示例#1
0
 /**
  * Gets the SQL that would be executed with the execute() method.
  * @param callable $callback
  *  If not set, this function returns the generated SQL string.
  *  If it is set, this function calls $callback, passing it the SQL
  *  string, and then returns $this, for chainable interface.
  *
  * @return string | Db_Query
  *  Depends on whether $callback is set or not.
  */
 function getSQL($callback = null)
 {
     $repres = $this->build();
     foreach ($this->parameters as $key => $value) {
         if ($value instanceof Db_Expression) {
             $value2 = $value;
         } else {
             if (!isset($value)) {
                 $value2 = "NULL";
             } else {
                 $this->db->pdoConnect();
                 $value2 = $this->db->pdo->quote($value);
             }
         }
         // wrong: $repres = str_replace(":$key", "$value2", $repres);
         if (false !== ($pos = strpos($repres, ":{$key}"))) {
             $pos2 = $pos + strlen(":{$key}");
             $repres = substr($repres, 0, $pos) . (string) $value2 . substr($repres, $pos2);
         }
     }
     foreach ($this->replacements as $k => $v) {
         $repres = str_replace($k, $v, $repres);
     }
     if (isset($callback)) {
         $args = array($repres);
         Pie::call($callback, $args);
         return $this;
     }
     return $repres;
 }