Ejemplo n.º 1
0
 /**
  * Quote a value for an SQL query.
  *
  * Objects passed to this function will be converted to strings.
  * Expression objects will use the value of the expression.
  * Query objects will be compiled and converted to a sub-query.
  * Command objects will be send of for compiling.
  * All other objects will be converted using the `__toString` method.
  *
  * @param   mixed   any value to quote
  * @return  string
  */
 public function quote($value)
 {
     if ($value === '?') {
         return $value;
     } elseif ($value === null) {
         return 'NULL';
     } elseif (is_bool($value)) {
         return $value ? "'1'" : "'0'";
     } elseif ($value instanceof Query) {
         // create a sub-query
         return '(' . $value->getQuery($this) . ')';
     } elseif ($value instanceof Expression) {
         // get the output from the expression
         return $value->getValue($this->connection);
     } elseif (is_array($value)) {
         $value = array_map(array($this, 'quote'), $value);
         return '(' . implode(', ', $value) . ')';
     } elseif (is_int($value)) {
         return $value;
     } elseif (is_double($value)) {
         return $value;
     } elseif (is_float($value)) {
         // Convert to non-locale aware d to prevent possible commas
         return sprintf('%F', $value);
     }
     return $this->connection->getPdo()->quote($value);
 }
Ejemplo n.º 2
0
 public function runCommands(array $commands)
 {
     foreach ($commands as $command) {
         $this->connection->execute(DB::PLAIN, $command);
     }
     $this->schema = null;
 }