For pgsql and mysql sql statement,
we use TRUE or FALSE for boolean type.
FOr sqlite sql statement:
we use 1 or 0 for boolean type.
public deflate ( $value, SQLBuilder\ArgumentArray $args = NULL ) | ||
$args | SQLBuilder\ArgumentArray |
public function toSql(BaseDriver $driver, ArgumentArray $args) { // XXX: $pat can be a Bind object $isBind = $this->pat instanceof Bind; $pat = $isBind ? $this->pat->getValue() : $this->pat; switch ($this->criteria) { case Criteria::CONTAINS: $pat = '%' . $pat . '%'; break; case Criteria::STARTS_WITH: $pat = $pat . '%'; break; case Criteria::ENDS_WITH: $pat = '%' . $pat; break; case Criteria::EXACT: $pat = $pat; break; default: $pat = '%' . $pat . '%'; break; } if ($isBind) { $this->pat->setValue($pat); } else { $this->pat = $pat; } return $this->exprStr . ' LIKE ' . $driver->deflate($this->pat, $args); }
public function deflate($value, ArgumentArray $args = NULL) { if ($value instanceof DateTime) { // MySQL does not support date time string with timezone return $this->quote($value->format('Y-m-d H:i:s')); } return parent::deflate($value, $args); }
public function toSql(BaseDriver $driver, ArgumentArray $args) { $sql = ''; if (is_array($this->expr)) { foreach ($this->expr as $val) { $sql .= ',' . $driver->deflate($val, $args); } $sql = ltrim($sql, ','); } elseif ($this->expr instanceof ToSqlInterface) { $sql = $driver->deflate($this->expr, $args); } elseif ($this->expr instanceof Raw) { $sql = $this->expr->__toString(); } elseif (is_string($this->expr)) { $sql = $this->expr; } else { throw new InvalidArgumentException('Invalid expr type'); } return '(' . $sql . ')'; }
/** * For variable placeholder like PDO, we need 1 or 0 for boolean type, * * For pgsql and mysql sql statement, * we use TRUE or FALSE for boolean type. * * FOr sqlite sql statement: * we use 1 or 0 for boolean type. */ public function deflate($value, ArgumentArray $args = NULL) { // Special cases for SQLite if ($value === true) { return 1; } elseif ($value === false) { return 0; } else { return parent::deflate($value, $args); } return $value; }
public function toSql(BaseDriver $driver, ArgumentArray $args) { if ($this->clauseType == self::SET_DEFAULT) { return 'ALTER COLUMN ' . $driver->quoteIdentifier($this->name) . ' SET DEFAULT ' . $driver->deflate($this->defaultValue); } else { if ($this->clauseType == self::DROP_DEFAULT) { return 'ALTER COLUMN ' . $driver->quoteIdentifier($this->name) . ' DROP DEFAULT'; } else { throw new InvalidArgumentException('You should call either setDefault nor dropDefault'); } } }
public static function deflate($value, $isa, BaseDriver $driver = NULL) { switch ($isa) { case 'int': return (int) $value; case 'str': return (string) $value; case 'double': return (double) $value; case 'float': return floatval($value); case "json": return json_encode($value); case "DateTime": if (is_a($value, 'DateTime', true)) { return $value->format(DateTime::ATOM); } if (!$value) { return NULL; } return $value; // might return "" // might return "" case 'boolean': case 'bool': // Convert string into bool if (is_string($value)) { if ($value === '' || $value === '0' || strncasecmp($value, 'false', 5) == 0) { $value = false; } elseif ($value === '1' || strncasecmp($value, 'true', 4) == 0) { $value = true; } } if ($driver) { return $driver->deflate($value); } return (bool) $value ? 1 : 0; } /* respect the data type to inflate value */ return $value; }
public static function deflate($value, $isa, BaseDriver $driver = null) { switch ($isa) { case 'int': return (int) $value; case 'str': return (string) $value; case 'double': return (double) $value; case 'float': return floatval($value); case 'json': return json_encode($value); case 'bool': // Convert string into bool if (is_string($value)) { if ($value === '' || $value === '0' || strncasecmp($value, 'false', 5) == 0) { $value = false; } elseif ($value === '1' || strncasecmp($value, 'true', 4) == 0) { $value = true; } } if ($driver) { return $driver->deflate($value); } return (bool) $value ? 1 : 0; } if ($value instanceof DateTime) { if ($driver instanceof PDOMySQLDriver) { return $value->format('Y-m-d H:i:s'); } return $value->format(DateTime::ATOM); } /* respect the data type to inflate value */ return $value; }
public function toSql(BaseDriver $driver, ArgumentArray $args) { return $this->exprStr . ' REGEXP ' . $driver->deflate($this->pat, $args); }
public function toSql(BaseDriver $driver, ArgumentArray $args) { return $this->exprStr . ' BETWEEN ' . $driver->deflate($this->min, $args) . ' AND ' . $driver->deflate($this->max, $args); }
public function buildSetClause(BaseDriver $driver, ArgumentArray $args) { $setClauses = array(); foreach ($this->sets as $col => $val) { $setClauses[] = $driver->quoteColumn($col) . " = " . $driver->deflate($val); } return ' SET ' . join(', ', $setClauses); }
public function buildSetClause(BaseDriver $driver) { if ($this->isa === 'set' && !empty($this->set)) { $set = array(); foreach ($this->set as $val) { $set[] = $driver->deflate($val); } return '(' . join(', ', $set) . ')'; } return ''; }
public function toSql(BaseDriver $driver, ArgumentArray $args) { return $this->op . ' ' . $driver->deflate($this->operand, $args); }
public function toSql(BaseDriver $driver, ArgumentArray $args) { return 'AUTO_INCREMENT = ' . $driver->deflate($this->value); }
public function toSql(BaseDriver $driver, ArgumentArray $args) { return 'ENGINE = ' . $driver->deflate($this->value); }
public function toSql(BaseDriver $driver, ArgumentArray $args) { return $this->exprStr . ' IS NOT ' . $driver->deflate($this->boolean, $args); }