本文整理汇总了PHP中Nette\Database\Connection::quote方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::quote方法的具体用法?PHP Connection::quote怎么用?PHP Connection::quote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Database\Connection
的用法示例。
在下文中一共展示了Connection::quote方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formatValue
private function formatValue($value)
{
if (is_string($value)) {
if (strlen($value) > 20) {
$this->remaining[] = $value;
return '?';
} else {
return $this->connection->quote($value);
}
} elseif (is_int($value)) {
return (string) $value;
} elseif (is_float($value)) {
return rtrim(rtrim(number_format($value, 10, '.', ''), '0'), '.');
} elseif (is_bool($value)) {
return $this->driver->formatBool($value);
} elseif ($value === NULL) {
return 'NULL';
} elseif ($value instanceof Table\ActiveRow) {
return $value->getPrimary();
} elseif (is_array($value) || $value instanceof \Traversable) {
$vx = $kx = array();
if ($value instanceof \Traversable) {
$value = iterator_to_array($value);
}
if (isset($value[0])) {
// non-associative; value, value, value
foreach ($value as $v) {
$vx[] = $this->formatValue($v);
}
return implode(', ', $vx);
} elseif ($this->arrayMode === 'values') {
// (key, key, ...) VALUES (value, value, ...)
$this->arrayMode = 'multi';
foreach ($value as $k => $v) {
$kx[] = $this->driver->delimite($k);
$vx[] = $this->formatValue($v);
}
return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
} elseif ($this->arrayMode === 'assoc') {
// key=value, key=value, ...
foreach ($value as $k => $v) {
$vx[] = $this->driver->delimite($k) . '=' . $this->formatValue($v);
}
return implode(', ', $vx);
} elseif ($this->arrayMode === 'multi') {
// multiple insert (value, value, ...), ...
foreach ($value as $v) {
$vx[] = $this->formatValue($v);
}
return '(' . implode(', ', $vx) . ')';
}
} elseif ($value instanceof \DateTime) {
return $this->driver->formatDateTime($value);
} elseif ($value instanceof SqlLiteral) {
return $value->__toString();
} else {
$this->remaining[] = $value;
return '?';
}
}
示例2: getColumns
/**
* Returns metadata for all columns in a table.
*/
public function getColumns($table)
{
$meta = $this->connection->query("\r\n\t\t\tSELECT sql FROM sqlite_master WHERE type = 'table' AND name = {$this->connection->quote($table)}\r\n\t\t\tUNION ALL\r\n\t\t\tSELECT sql FROM sqlite_temp_master WHERE type = 'table' AND name = {$this->connection->quote($table)}\r\n\t\t")->fetch();
$columns = array();
foreach ($this->connection->query("PRAGMA table_info({$this->delimite($table)})") as $row) {
$column = $row['name'];
$pattern = "/(\"{$column}\"|\\[{$column}\\]|{$column})\\s+[^,]+\\s+PRIMARY\\s+KEY\\s+AUTOINCREMENT/Ui";
$type = explode('(', $row['type']);
$columns[] = array('name' => $column, 'table' => $table, 'fullname' => "{$table}.{$column}", 'nativetype' => strtoupper($type[0]), 'size' => isset($type[1]) ? (int) $type[1] : NULL, 'nullable' => $row['notnull'] == '0', 'default' => $row['dflt_value'], 'autoincrement' => (bool) preg_match($pattern, $meta['sql']), 'primary' => $row['pk'] == '1', 'vendor' => (array) $row);
}
return $columns;
}
示例3: getForeignKeys
/**
* Returns metadata for all foreign keys in a table.
*/
public function getForeignKeys($table)
{
$keys = [];
$query = 'SELECT \'CONSTRAINT_NAME\', C.COLUMN_NAME, C2.TABLE_NAME AS `REFERENCED_TABLE_NAME`, C2.COLUMN_NAME AS `REFERENCED_COLUMN_NAME` ' . 'FROM information_schema.COLUMNS C ' . 'JOIN information_schema.TABLES T ON T.TABLE_SCHEMA = C.TABLE_SCHEMA ' . 'JOIN information_schema.COLUMNS C2 ON C2.TABLE_SCHEMA = C.TABLE_SCHEMA ' . 'WHERE 1 ' . 'AND C.TABLE_SCHEMA = DATABASE() ' . 'AND C.TABLE_NAME = ' . $this->connection->quote($table) . ' ' . 'AND C.COLUMN_KEY != \'\' ' . 'AND C2.TABLE_NAME = T.TABLE_NAME ' . 'AND ( ' . '( ' . 'C.COLUMN_COMMENT REGEXP \'^\\s*@refs [a-zA-Z_]+\\.[a-zA-Z_]+\' ' . 'AND C.COLUMN_COMMENT LIKE CONCAT(\'@refs \', C2.TABLE_NAME, \'\\.\', C2.COLUMN_NAME, \'%\') ' . ') ' . 'OR ( ' . 'C.COLUMN_NAME LIKE CONCAT(T.TABLE_NAME, \'\\_%\') ' . 'AND REPLACE(C.COLUMN_NAME, CONCAT(T.TABLE_NAME, \'_\'), \'\') = C2.COLUMN_NAME' . ') ' . ')';
foreach ($this->connection->query($query) as $id => $row) {
$keys[$id]['name'] = 'FK_' . $table . '_' . $row['REFERENCED_TABLE_NAME'] . '_' . $row['REFERENCED_COLUMN_NAME'];
// foreign key name
$keys[$id]['local'] = $row['COLUMN_NAME'];
// local columns
$keys[$id]['table'] = $row['REFERENCED_TABLE_NAME'];
// referenced table
$keys[$id]['foreign'] = $row['REFERENCED_COLUMN_NAME'];
// referenced columns
}
return array_values($keys);
}
示例4: getForeignKeys
/**
* Returns metadata for all foreign keys in a table.
*/
public function getForeignKeys($table)
{
// Does't work with multicolumn foreign keys
$keys = array();
foreach ($this->connection->query("\n\t\t\tSELECT\n\t\t\t\tfk.name AS name,\n\t\t\t\tcl.name AS local,\n\t\t\t\ttf.name AS [table],\n\t\t\t\tcf.name AS [column]\n\t\t\tFROM\n\t\t\t\tsys.foreign_keys fk\n\t\t\t\tJOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id\n\t\t\t\tJOIN sys.tables tl ON fkc.parent_object_id = tl.object_id\n\t\t\t\tJOIN sys.columns cl ON fkc.parent_object_id = cl.object_id AND fkc.parent_column_id = cl.column_id\n\t\t\t\tJOIN sys.tables tf ON fkc.referenced_object_id = tf.object_id\n\t\t\t\tJOIN sys.columns cf ON fkc.referenced_object_id = cf.object_id AND fkc.referenced_column_id = cf.column_id\n\t\t\tWHERE\n\t\t\t\ttl.name = {$this->connection->quote($table)}\n\t\t") as $row) {
$keys[$row->name] = (array) $row;
}
return array_values($keys);
}
示例5: getForeignKeys
/**
* Returns metadata for all foreign keys in a table.
*/
public function getForeignKeys($table)
{
/* Not for multi-column foreign keys */
$keys = array();
foreach ($this->connection->query("\n\t\t\tSELECT\n\t\t\t\ttc.constraint_name AS name,\n\t\t\t\tkcu.column_name AS local,\n\t\t\t\tccu.table_name AS table,\n\t\t\t\tccu.column_name AS foreign\n\t\t\tFROM\n\t\t\t\tinformation_schema.table_constraints AS tc\n\t\t\t\tJOIN information_schema.key_column_usage AS kcu USING(constraint_catalog, constraint_schema, constraint_name)\n\t\t\t\tJOIN information_schema.constraint_column_usage AS ccu USING(constraint_catalog, constraint_schema, constraint_name)\n\t\t\tWHERE\n\t\t\t\tconstraint_type = 'FOREIGN KEY'\n\t\t\t\tAND\n\t\t\t\ttc.table_name = {$this->connection->quote($table)}\n\t\t\tORDER BY\n\t\t\t\tkcu.ordinal_position\n\t\t") as $row) {
$keys[] = (array) $row;
}
return $keys;
}
示例6: getForeignKeys
/**
* Returns metadata for all foreign keys in a table.
*/
public function getForeignKeys($table)
{
$keys = [];
$query = 'SELECT CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME FROM information_schema.KEY_COLUMN_USAGE ' . 'WHERE TABLE_SCHEMA = DATABASE() AND REFERENCED_TABLE_NAME IS NOT NULL AND TABLE_NAME = ' . $this->connection->quote($table);
foreach ($this->connection->query($query) as $id => $row) {
$keys[$id]['name'] = $row['CONSTRAINT_NAME'];
// foreign key name
$keys[$id]['local'] = $row['COLUMN_NAME'];
// local columns
$keys[$id]['table'] = $row['REFERENCED_TABLE_NAME'];
// referenced table
$keys[$id]['foreign'] = $row['REFERENCED_COLUMN_NAME'];
// referenced columns
}
return array_values($keys);
}
示例7: getIndexes
/**
* Returns metadata for all indexes in a table.
*/
public function getIndexes($table)
{
$columns = array();
foreach ($this->connection->query("\n\t\t\tSELECT ordinal_position, column_name\n\t\t\tFROM information_schema.columns\n\t\t\tWHERE table_name = {$this->connection->quote($table)} AND table_schema = current_schema()\n\t\t\tORDER BY ordinal_position\n\t\t") as $row) {
$columns[$row['ordinal_position']] = $row['column_name'];
}
$indexes = array();
foreach ($this->connection->query("\n\t\t\tSELECT pg_class2.relname, indisunique, indisprimary, indkey\n\t\t\tFROM pg_class\n\t\t\tLEFT JOIN pg_index on pg_class.oid = pg_index.indrelid\n\t\t\tINNER JOIN pg_class as pg_class2 on pg_class2.oid = pg_index.indexrelid\n\t\t\tWHERE pg_class.relname = {$this->connection->quote($table)}\n\t\t") as $row) {
$indexes[$row['relname']]['name'] = $row['relname'];
$indexes[$row['relname']]['unique'] = $row['indisunique'] === 't';
$indexes[$row['relname']]['primary'] = $row['indisprimary'] === 't';
foreach (explode(' ', $row['indkey']) as $index) {
$indexes[$row['relname']]['columns'][] = $columns[$index];
}
}
return array_values($indexes);
}
示例8: getForeignKeys
/**
* Returns metadata for all foreign keys in a table.
*/
public function getForeignKeys($table)
{
/* Does't work with multicolumn foreign keys */
return $this->connection->query("
SELECT
co.conname::varchar AS name,
al.attname::varchar AS local,
cf.relname::varchar AS table,
af.attname::varchar AS foreign
FROM
pg_catalog.pg_constraint AS co
JOIN pg_catalog.pg_class AS cl ON co.conrelid = cl.oid
JOIN pg_catalog.pg_class AS cf ON co.confrelid = cf.oid
JOIN pg_catalog.pg_namespace AS nf ON nf.oid = cf.relnamespace
JOIN pg_catalog.pg_attribute AS al ON al.attrelid = cl.oid AND al.attnum = co.conkey[1]
JOIN pg_catalog.pg_attribute AS af ON af.attrelid = cf.oid AND af.attnum = co.confkey[1]
WHERE
co.contype = 'f'
AND cl.oid = {$this->connection->quote($this->delimiteFQN($table))}::regclass
AND nf.nspname = ANY (pg_catalog.current_schemas(FALSE))
")->fetchAll();
}
示例9: dumpSql
/**
* Returns syntax highlighted SQL command.
* @param string
* @return string
*/
public static function dumpSql($sql, array $params = NULL, Connection $connection = NULL)
{
static $keywords1 = 'SELECT|(?:ON\\s+DUPLICATE\\s+KEY)?UPDATE|INSERT(?:\\s+INTO)?|REPLACE(?:\\s+INTO)?|DELETE|CALL|UNION|FROM|WHERE|HAVING|GROUP\\s+BY|ORDER\\s+BY|LIMIT|OFFSET|SET|VALUES|LEFT\\s+JOIN|INNER\\s+JOIN|TRUNCATE';
static $keywords2 = 'ALL|DISTINCT|DISTINCTROW|IGNORE|AS|USING|ON|AND|OR|IN|IS|NOT|NULL|[RI]?LIKE|REGEXP|TRUE|FALSE';
// insert new lines
$sql = " {$sql} ";
$sql = preg_replace("#(?<=[\\s,(])({$keywords1})(?=[\\s,)])#i", "\n\$1", $sql);
// reduce spaces
$sql = preg_replace('#[ \\t]{2,}#', ' ', $sql);
$sql = wordwrap($sql, 100);
$sql = preg_replace('#([ \\t]*\\r?\\n){2,}#', "\n", $sql);
// syntax highlight
$sql = htmlSpecialChars($sql, ENT_IGNORE, 'UTF-8');
$sql = preg_replace_callback("#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])({$keywords1})(?=[\\s,)])|(?<=[\\s,(=])({$keywords2})(?=[\\s,)=])#is", function ($matches) {
if (!empty($matches[1])) {
// comment
return '<em style="color:gray">' . $matches[1] . '</em>';
} elseif (!empty($matches[2])) {
// error
return '<strong style="color:red">' . $matches[2] . '</strong>';
} elseif (!empty($matches[3])) {
// most important keywords
return '<strong style="color:blue">' . $matches[3] . '</strong>';
} elseif (!empty($matches[4])) {
// other keywords
return '<strong style="color:green">' . $matches[4] . '</strong>';
}
}, $sql);
// parameters
$sql = preg_replace_callback('#\\?#', function () use($params, $connection) {
static $i = 0;
if (!isset($params[$i])) {
return '?';
}
$param = $params[$i++];
if (is_string($param) && (preg_match('#[^\\x09\\x0A\\x0D\\x20-\\x7E\\xA0-\\x{10FFFF}]#u', $param) || preg_last_error())) {
return '<i title="Length ' . strlen($param) . ' bytes"><binary></i>';
} elseif (is_string($param)) {
$length = Nette\Utils\Strings::length($param);
$truncated = Nette\Utils\Strings::truncate($param, Helpers::$maxLength);
$text = htmlspecialchars($connection ? $connection->quote($truncated) : '\'' . $truncated . '\'', ENT_NOQUOTES, 'UTF-8');
return '<span title="Length ' . $length . ' characters">' . $text . '</span>';
} elseif (is_resource($param)) {
$type = get_resource_type($param);
if ($type === 'stream') {
$info = stream_get_meta_data($param);
}
return '<i' . (isset($info['uri']) ? ' title="' . htmlspecialchars($info['uri'], ENT_NOQUOTES, 'UTF-8') . '"' : NULL) . '><' . htmlSpecialChars($type, ENT_NOQUOTES, 'UTF-8') . ' resource></i> ';
} else {
return htmlspecialchars($param, ENT_NOQUOTES, 'UTF-8');
}
}, $sql);
return '<pre class="dump">' . trim($sql) . "</pre>\n";
}
示例10: escapeInt
public function escapeInt($value)
{
return $this->conn->quote($value, PDO::PARAM_INT);
}
示例11: formatValue
private function formatValue($value, $mode = NULL)
{
if (!$mode || $mode === 'auto') {
if (is_string($value)) {
if (strlen($value) > 20) {
$this->remaining[] = $value;
return '?';
} else {
return $this->connection->quote($value);
}
} elseif (is_int($value)) {
return (string) $value;
} elseif (is_float($value)) {
return rtrim(rtrim(number_format($value, 10, '.', ''), '0'), '.');
} elseif (is_bool($value)) {
return $this->driver->formatBool($value);
} elseif ($value === NULL) {
return 'NULL';
} elseif ($value instanceof Table\IRow) {
return $value->getPrimary();
} elseif ($value instanceof SqlLiteral) {
$prep = clone $this;
list($res, $params) = $prep->process(array_merge([$value->__toString()], $value->getParameters()));
$this->remaining = array_merge($this->remaining, $params);
return $res;
} elseif ($value instanceof \DateTimeInterface) {
return $this->driver->formatDateTime($value);
} elseif ($value instanceof \DateInterval) {
return $this->driver->formatDateInterval($value);
} elseif (is_object($value) && method_exists($value, '__toString')) {
return $this->formatValue((string) $value);
} elseif (is_resource($value)) {
$this->remaining[] = $value;
return '?';
}
} elseif ($mode === 'name') {
if (!is_string($value)) {
$type = gettype($value);
throw new Nette\InvalidArgumentException("Placeholder ?{$mode} expects string, {$type} given.");
}
return $this->delimite($value);
}
if ($value instanceof \Traversable && !$value instanceof Table\IRow) {
$value = iterator_to_array($value);
}
if (is_array($value)) {
$vx = $kx = [];
if ($mode === 'auto') {
$mode = $this->arrayMode;
}
if ($mode === 'values') {
// (key, key, ...) VALUES (value, value, ...)
if (array_key_exists(0, $value)) {
// multi-insert
foreach ($value[0] as $k => $v) {
$kx[] = $this->delimite($k);
}
foreach ($value as $val) {
$vx2 = [];
foreach ($val as $v) {
$vx2[] = $this->formatValue($v);
}
$vx[] = implode(', ', $vx2);
}
$select = $this->driver->isSupported(ISupplementalDriver::SUPPORT_MULTI_INSERT_AS_SELECT);
return '(' . implode(', ', $kx) . ($select ? ') SELECT ' : ') VALUES (') . implode($select ? ' UNION ALL SELECT ' : '), (', $vx) . ($select ? '' : ')');
}
foreach ($value as $k => $v) {
$kx[] = $this->delimite($k);
$vx[] = $this->formatValue($v);
}
return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
} elseif (!$mode || $mode === 'set') {
foreach ($value as $k => $v) {
if (is_int($k)) {
// value, value, ... OR (1, 2), (3, 4)
$vx[] = is_array($v) ? '(' . $this->formatValue($v) . ')' : $this->formatValue($v);
} elseif (substr($k, -1) === '=') {
// key+=value, key-=value, ...
$k2 = $this->delimite(substr($k, 0, -2));
$vx[] = $k2 . '=' . $k2 . ' ' . substr($k, -2, 1) . ' ' . $this->formatValue($v);
} else {
// key=value, key=value, ...
$vx[] = $this->delimite($k) . '=' . $this->formatValue($v);
}
}
return implode(', ', $vx);
} elseif ($mode === 'and' || $mode === 'or') {
// (key [operator] value) AND ...
foreach ($value as $k => $v) {
if (is_int($k)) {
$vx[] = $this->formatValue($v);
continue;
}
list($k, $operator) = explode(' ', $k . ' ');
$k = $this->delimite($k);
if (is_array($v)) {
if ($v) {
$vx[] = $k . ' ' . ($operator ? $operator . ' ' : '') . 'IN (' . $this->formatValue(array_values($v)) . ')';
} elseif ($operator === 'NOT') {
//.........这里部分代码省略.........
示例12: getForeignKeys
/**
* Returns metadata for all foreign keys in a table.
*/
public function getForeignKeys($table)
{
/* Does't work with multicolumn foreign keys */
return $this->connection->query("\n\t\t\tSELECT\n\t\t\t\tco.conname::varchar AS name,\n\t\t\t\tal.attname::varchar AS local,\n\t\t\t\tnf.nspname || '.' || cf.relname::varchar AS table,\n\t\t\t\taf.attname::varchar AS foreign\n\t\t\tFROM\n\t\t\t\tpg_catalog.pg_constraint AS co\n\t\t\t\tJOIN pg_catalog.pg_class AS cl ON co.conrelid = cl.oid\n\t\t\t\tJOIN pg_catalog.pg_class AS cf ON co.confrelid = cf.oid\n\t\t\t\tJOIN pg_catalog.pg_namespace AS nf ON nf.oid = cf.relnamespace\n\t\t\t\tJOIN pg_catalog.pg_attribute AS al ON al.attrelid = cl.oid AND al.attnum = co.conkey[1]\n\t\t\t\tJOIN pg_catalog.pg_attribute AS af ON af.attrelid = cf.oid AND af.attnum = co.confkey[1]\n\t\t\tWHERE\n\t\t\t\tco.contype = 'f'\n\t\t\t\tAND cl.oid = {$this->connection->quote($this->delimiteFQN($table))}::regclass\n\t\t\t\tAND nf.nspname = ANY (pg_catalog.current_schemas(FALSE))\n\t\t")->fetchAll();
}
示例13: formatLike
/**
* Encodes string for use in a LIKE statement.
*/
public function formatLike($value, $pos)
{
$value = addcslashes(substr($this->connection->quote($value), 1, -1), '%_\\');
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'") . " ESCAPE '\\'";
}
示例14: getForeignKeys
/**
* Returns metadata for all foreign keys in a table.
*/
public function getForeignKeys($table)
{
/* Does't work with multicolumn foreign keys */
return $this->connection->query("\r\n\t\t\tSELECT\r\n\t\t\t\tco.conname::varchar AS name,\r\n\t\t\t\tal.attname::varchar AS local,\r\n\t\t\t\tcf.relname::varchar AS table,\r\n\t\t\t\taf.attname::varchar AS foreign\r\n\t\t\tFROM\r\n\t\t\t\tpg_catalog.pg_constraint AS co\r\n\t\t\t\tJOIN pg_catalog.pg_namespace AS n ON co.connamespace = n.oid\r\n\t\t\t\tJOIN pg_catalog.pg_class AS cl ON co.conrelid = cl.oid\r\n\t\t\t\tJOIN pg_catalog.pg_class AS cf ON co.confrelid = cf.oid\r\n\t\t\t\tJOIN pg_catalog.pg_attribute AS al ON al.attrelid = cl.oid AND al.attnum = co.conkey[1]\r\n\t\t\t\tJOIN pg_catalog.pg_attribute AS af ON af.attrelid = cf.oid AND af.attnum = co.confkey[1]\r\n\t\t\tWHERE\r\n\t\t\t\tARRAY[n.nspname] <@ pg_catalog.current_schemas(FALSE)\r\n\t\t\t\tAND co.contype = 'f'\r\n\t\t\t\tAND cl.relname = {$this->connection->quote($table)}\r\n\t\t")->fetchAll();
}
示例15: formatValue
private function formatValue($value)
{
if (is_string($value)) {
if (strlen($value) > 20) {
$this->remaining[] = $value;
return '?';
} else {
return $this->connection->quote($value);
}
} elseif (is_int($value)) {
return (string) $value;
} elseif (is_float($value)) {
return rtrim(rtrim(number_format($value, 10, '.', ''), '0'), '.');
} elseif (is_bool($value)) {
return $this->driver->formatBool($value);
} elseif ($value === NULL) {
return 'NULL';
} elseif ($value instanceof Table\IRow) {
return $value->getPrimary();
} elseif (is_array($value) || $value instanceof \Traversable) {
$vx = $kx = array();
if ($value instanceof \Traversable) {
$value = iterator_to_array($value);
}
if (isset($value[0])) {
// non-associative; value, value, value
foreach ($value as $v) {
if (is_array($v) && isset($v[0])) {
// no-associative; (value), (value), (value)
$vx[] = '(' . $this->formatValue($v) . ')';
} else {
$vx[] = $this->formatValue($v);
}
}
if ($this->arrayMode === 'union') {
return implode(' ', $vx);
}
return implode(', ', $vx);
} elseif ($this->arrayMode === 'values') {
// (key, key, ...) VALUES (value, value, ...)
$this->arrayMode = 'multi';
foreach ($value as $k => $v) {
$kx[] = $this->driver->delimite($k);
$vx[] = $this->formatValue($v);
}
return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
} elseif ($this->arrayMode === 'select') {
// (key, key, ...) SELECT value, value, ...
$this->arrayMode = 'union';
foreach ($value as $k => $v) {
$kx[] = $this->driver->delimite($k);
$vx[] = $this->formatValue($v);
}
return '(' . implode(', ', $kx) . ') SELECT ' . implode(', ', $vx);
} elseif ($this->arrayMode === 'assoc') {
// key=value, key=value, ...
foreach ($value as $k => $v) {
if (substr($k, -1) === '=') {
$k2 = $this->driver->delimite(substr($k, 0, -2));
$vx[] = $k2 . '=' . $k2 . ' ' . substr($k, -2, 1) . ' ' . $this->formatValue($v);
} else {
$vx[] = $this->driver->delimite($k) . '=' . $this->formatValue($v);
}
}
return implode(', ', $vx);
} elseif ($this->arrayMode === 'multi') {
// multiple insert (value, value, ...), ...
foreach ($value as $v) {
$vx[] = $this->formatValue($v);
}
return '(' . implode(', ', $vx) . ')';
} elseif ($this->arrayMode === 'union') {
// UNION ALL SELECT value, value, ...
foreach ($value as $v) {
$vx[] = $this->formatValue($v);
}
return 'UNION ALL SELECT ' . implode(', ', $vx);
} elseif ($this->arrayMode === 'and') {
// (key [operator] value) AND ...
foreach ($value as $k => $v) {
$k = $this->driver->delimite($k);
if (is_array($v)) {
$vx[] = $v ? $k . ' IN (' . $this->formatValue(array_values($v)) . ')' : '1=0';
} else {
$v = $this->formatValue($v);
$vx[] = $k . ($v === 'NULL' ? ' IS ' : ' = ') . $v;
}
}
return $value ? '(' . implode(') AND (', $vx) . ')' : '1=1';
} elseif ($this->arrayMode === 'order') {
// key, key DESC, ...
foreach ($value as $k => $v) {
$vx[] = $this->driver->delimite($k) . ($v > 0 ? '' : ' DESC');
}
return implode(', ', $vx);
}
} elseif ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
return $this->driver->formatDateTime($value);
} elseif ($value instanceof SqlLiteral) {
$this->remaining = array_merge($this->remaining, $value->getParameters());
//.........这里部分代码省略.........