/** * Expands :name and @name macros. Escapes/quotes mapped values. * * @param string $sql Statement with 0 or more macros. * @param Array $map Assoc. array that maps macro names to their values. * Use ':' macro prefix to escape and quote the value (if string). * Use '@' macro prefix to only escape it. * Prefix is required. * Each value is escaped and quoted (if string). * @return string * @throws Exception if any parameter cannot be converted to a string; * if query does not produce a valid result object/resource; * if a macro is missing a valid prefix. */ public function expandSql($sql, $map) { // Ex. prevent macro :name from being being expanded before :nameSuffix. uksort($map, array('Hashmark_Util', 'sortByStrlenReverse')); foreach ($map as $macro => $value) { if (':' == $macro[0]) { $map[$macro] = $this->_db->quote($value); } else { if ('@' == $macro[0]) { $map[$macro] = $this->escape($value); } else { throw new Exception("Macro '{$macro}' does not have a valid prefix character.", HASHMARK_EXCEPTION_VALIDATION); } } } return str_replace(array_keys($map), array_values($map), $sql); }
/** * @return void */ protected function tearDown() { if ($this->_db) { $this->_db->closeConnection(); } }