QueryBuilder.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. <?php
  2. /**
  3. * @link https://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license https://www.yiiframework.com/license/
  6. */
  7. namespace yii\db\pgsql;
  8. use yii\base\InvalidArgumentException;
  9. use yii\db\Constraint;
  10. use yii\db\Expression;
  11. use yii\db\ExpressionInterface;
  12. use yii\db\Query;
  13. use yii\db\PdoValue;
  14. use yii\helpers\StringHelper;
  15. /**
  16. * QueryBuilder is the query builder for PostgreSQL databases.
  17. *
  18. * @author Gevik Babakhani <gevikb@gmail.com>
  19. * @since 2.0
  20. */
  21. class QueryBuilder extends \yii\db\QueryBuilder
  22. {
  23. /**
  24. * Defines a UNIQUE index for [[createIndex()]].
  25. * @since 2.0.6
  26. */
  27. const INDEX_UNIQUE = 'unique';
  28. /**
  29. * Defines a B-tree index for [[createIndex()]].
  30. * @since 2.0.6
  31. */
  32. const INDEX_B_TREE = 'btree';
  33. /**
  34. * Defines a hash index for [[createIndex()]].
  35. * @since 2.0.6
  36. */
  37. const INDEX_HASH = 'hash';
  38. /**
  39. * Defines a GiST index for [[createIndex()]].
  40. * @since 2.0.6
  41. */
  42. const INDEX_GIST = 'gist';
  43. /**
  44. * Defines a GIN index for [[createIndex()]].
  45. * @since 2.0.6
  46. */
  47. const INDEX_GIN = 'gin';
  48. /**
  49. * @var array mapping from abstract column types (keys) to physical column types (values).
  50. */
  51. public $typeMap = [
  52. Schema::TYPE_PK => 'serial NOT NULL PRIMARY KEY',
  53. Schema::TYPE_UPK => 'serial NOT NULL PRIMARY KEY',
  54. Schema::TYPE_BIGPK => 'bigserial NOT NULL PRIMARY KEY',
  55. Schema::TYPE_UBIGPK => 'bigserial NOT NULL PRIMARY KEY',
  56. Schema::TYPE_CHAR => 'char(1)',
  57. Schema::TYPE_STRING => 'varchar(255)',
  58. Schema::TYPE_TEXT => 'text',
  59. Schema::TYPE_TINYINT => 'smallint',
  60. Schema::TYPE_SMALLINT => 'smallint',
  61. Schema::TYPE_INTEGER => 'integer',
  62. Schema::TYPE_BIGINT => 'bigint',
  63. Schema::TYPE_FLOAT => 'double precision',
  64. Schema::TYPE_DOUBLE => 'double precision',
  65. Schema::TYPE_DECIMAL => 'numeric(10,0)',
  66. Schema::TYPE_DATETIME => 'timestamp(0)',
  67. Schema::TYPE_TIMESTAMP => 'timestamp(0)',
  68. Schema::TYPE_TIME => 'time(0)',
  69. Schema::TYPE_DATE => 'date',
  70. Schema::TYPE_BINARY => 'bytea',
  71. Schema::TYPE_BOOLEAN => 'boolean',
  72. Schema::TYPE_MONEY => 'numeric(19,4)',
  73. Schema::TYPE_JSON => 'jsonb',
  74. ];
  75. /**
  76. * {@inheritdoc}
  77. */
  78. protected function defaultConditionClasses()
  79. {
  80. return array_merge(parent::defaultConditionClasses(), [
  81. 'ILIKE' => 'yii\db\conditions\LikeCondition',
  82. 'NOT ILIKE' => 'yii\db\conditions\LikeCondition',
  83. 'OR ILIKE' => 'yii\db\conditions\LikeCondition',
  84. 'OR NOT ILIKE' => 'yii\db\conditions\LikeCondition',
  85. ]);
  86. }
  87. /**
  88. * {@inheritdoc}
  89. */
  90. protected function defaultExpressionBuilders()
  91. {
  92. return array_merge(parent::defaultExpressionBuilders(), [
  93. 'yii\db\ArrayExpression' => 'yii\db\pgsql\ArrayExpressionBuilder',
  94. 'yii\db\JsonExpression' => 'yii\db\pgsql\JsonExpressionBuilder',
  95. ]);
  96. }
  97. /**
  98. * Builds a SQL statement for creating a new index.
  99. * @param string $name the name of the index. The name will be properly quoted by the method.
  100. * @param string $table the table that the new index will be created for. The table name will be properly quoted by the method.
  101. * @param string|array $columns the column(s) that should be included in the index. If there are multiple columns,
  102. * separate them with commas or use an array to represent them. Each column name will be properly quoted
  103. * by the method, unless a parenthesis is found in the name.
  104. * @param bool|string $unique whether to make this a UNIQUE index constraint. You can pass `true` or [[INDEX_UNIQUE]] to create
  105. * a unique index, `false` to make a non-unique index using the default index type, or one of the following constants to specify
  106. * the index method to use: [[INDEX_B_TREE]], [[INDEX_HASH]], [[INDEX_GIST]], [[INDEX_GIN]].
  107. * @return string the SQL statement for creating a new index.
  108. * @see https://www.postgresql.org/docs/8.2/sql-createindex.html
  109. */
  110. public function createIndex($name, $table, $columns, $unique = false)
  111. {
  112. if ($unique === self::INDEX_UNIQUE || $unique === true) {
  113. $index = false;
  114. $unique = true;
  115. } else {
  116. $index = $unique;
  117. $unique = false;
  118. }
  119. return ($unique ? 'CREATE UNIQUE INDEX ' : 'CREATE INDEX ') .
  120. $this->db->quoteTableName($name) . ' ON ' .
  121. $this->db->quoteTableName($table) .
  122. ($index !== false ? " USING $index" : '') .
  123. ' (' . $this->buildColumns($columns) . ')';
  124. }
  125. /**
  126. * Builds a SQL statement for dropping an index.
  127. * @param string $name the name of the index to be dropped. The name will be properly quoted by the method.
  128. * @param string $table the table whose index is to be dropped. The name will be properly quoted by the method.
  129. * @return string the SQL statement for dropping an index.
  130. */
  131. public function dropIndex($name, $table)
  132. {
  133. if (strpos($table, '.') !== false && strpos($name, '.') === false) {
  134. if (strpos($table, '{{') !== false) {
  135. $table = preg_replace('/\\{\\{(.*?)\\}\\}/', '\1', $table);
  136. list($schema, $table) = explode('.', $table);
  137. if (strpos($schema, '%') === false) {
  138. $name = $schema . '.' . $name;
  139. } else {
  140. $name = '{{' . $schema . '.' . $name . '}}';
  141. }
  142. } else {
  143. list($schema) = explode('.', $table);
  144. $name = $schema . '.' . $name;
  145. }
  146. }
  147. return 'DROP INDEX ' . $this->db->quoteTableName($name);
  148. }
  149. /**
  150. * Builds a SQL statement for renaming a DB table.
  151. * @param string $oldName the table to be renamed. The name will be properly quoted by the method.
  152. * @param string $newName the new table name. The name will be properly quoted by the method.
  153. * @return string the SQL statement for renaming a DB table.
  154. */
  155. public function renameTable($oldName, $newName)
  156. {
  157. return 'ALTER TABLE ' . $this->db->quoteTableName($oldName) . ' RENAME TO ' . $this->db->quoteTableName($newName);
  158. }
  159. /**
  160. * Creates a SQL statement for resetting the sequence value of a table's primary key.
  161. * The sequence will be reset such that the primary key of the next new row inserted
  162. * will have the specified value or 1.
  163. * @param string $tableName the name of the table whose primary key sequence will be reset
  164. * @param mixed $value the value for the primary key of the next new row inserted. If this is not set,
  165. * the next new row's primary key will have a value 1.
  166. * @return string the SQL statement for resetting sequence
  167. * @throws InvalidArgumentException if the table does not exist or there is no sequence associated with the table.
  168. */
  169. public function resetSequence($tableName, $value = null)
  170. {
  171. $table = $this->db->getTableSchema($tableName);
  172. if ($table !== null && $table->sequenceName !== null) {
  173. // c.f. https://www.postgresql.org/docs/8.1/functions-sequence.html
  174. $sequence = $this->db->quoteTableName($table->sequenceName);
  175. $tableName = $this->db->quoteTableName($tableName);
  176. if ($value === null) {
  177. $key = $this->db->quoteColumnName(reset($table->primaryKey));
  178. $value = "(SELECT COALESCE(MAX({$key}),0) FROM {$tableName})+1";
  179. } else {
  180. $value = (int) $value;
  181. }
  182. return "SELECT SETVAL('$sequence',$value,false)";
  183. } elseif ($table === null) {
  184. throw new InvalidArgumentException("Table not found: $tableName");
  185. }
  186. throw new InvalidArgumentException("There is not sequence associated with table '$tableName'.");
  187. }
  188. /**
  189. * Builds a SQL statement for enabling or disabling integrity check.
  190. * @param bool $check whether to turn on or off the integrity check.
  191. * @param string $schema the schema of the tables.
  192. * @param string $table the table name.
  193. * @return string the SQL statement for checking integrity
  194. */
  195. public function checkIntegrity($check = true, $schema = '', $table = '')
  196. {
  197. $enable = $check ? 'ENABLE' : 'DISABLE';
  198. $schema = $schema ?: $this->db->getSchema()->defaultSchema;
  199. $tableNames = $table ? [$table] : $this->db->getSchema()->getTableNames($schema);
  200. $viewNames = $this->db->getSchema()->getViewNames($schema);
  201. $tableNames = array_diff($tableNames, $viewNames);
  202. $command = '';
  203. foreach ($tableNames as $tableName) {
  204. $tableName = $this->db->quoteTableName("{$schema}.{$tableName}");
  205. $command .= "ALTER TABLE $tableName $enable TRIGGER ALL; ";
  206. }
  207. // enable to have ability to alter several tables
  208. $this->db->getMasterPdo()->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
  209. return $command;
  210. }
  211. /**
  212. * Builds a SQL statement for truncating a DB table.
  213. * Explicitly restarts identity for PGSQL to be consistent with other databases which all do this by default.
  214. * @param string $table the table to be truncated. The name will be properly quoted by the method.
  215. * @return string the SQL statement for truncating a DB table.
  216. */
  217. public function truncateTable($table)
  218. {
  219. return 'TRUNCATE TABLE ' . $this->db->quoteTableName($table) . ' RESTART IDENTITY';
  220. }
  221. /**
  222. * Builds a SQL statement for changing the definition of a column.
  223. * @param string $table the table whose column is to be changed. The table name will be properly quoted by the method.
  224. * @param string $column the name of the column to be changed. The name will be properly quoted by the method.
  225. * @param string $type the new column type. The [[getColumnType()]] method will be invoked to convert abstract
  226. * column type (if any) into the physical one. Anything that is not recognized as abstract type will be kept
  227. * in the generated SQL. For example, 'string' will be turned into 'varchar(255)', while 'string not null'
  228. * will become 'varchar(255) not null'. You can also use PostgreSQL-specific syntax such as `SET NOT NULL`.
  229. * @return string the SQL statement for changing the definition of a column.
  230. */
  231. public function alterColumn($table, $column, $type)
  232. {
  233. $columnName = $this->db->quoteColumnName($column);
  234. $tableName = $this->db->quoteTableName($table);
  235. // https://github.com/yiisoft/yii2/issues/4492
  236. // https://www.postgresql.org/docs/9.1/sql-altertable.html
  237. if (preg_match('/^(DROP|SET|RESET)\s+/i', $type)) {
  238. return "ALTER TABLE {$tableName} ALTER COLUMN {$columnName} {$type}";
  239. }
  240. $type = 'TYPE ' . $this->getColumnType($type);
  241. $multiAlterStatement = [];
  242. $constraintPrefix = preg_replace('/[^a-z0-9_]/i', '', $table . '_' . $column);
  243. if (preg_match('/\s+DEFAULT\s+(["\']?\w*["\']?)/i', $type, $matches)) {
  244. $type = preg_replace('/\s+DEFAULT\s+(["\']?\w*["\']?)/i', '', $type);
  245. $multiAlterStatement[] = "ALTER COLUMN {$columnName} SET DEFAULT {$matches[1]}";
  246. } else {
  247. // safe to drop default even if there was none in the first place
  248. $multiAlterStatement[] = "ALTER COLUMN {$columnName} DROP DEFAULT";
  249. }
  250. $type = preg_replace('/\s+NOT\s+NULL/i', '', $type, -1, $count);
  251. if ($count) {
  252. $multiAlterStatement[] = "ALTER COLUMN {$columnName} SET NOT NULL";
  253. } else {
  254. // remove additional null if any
  255. $type = preg_replace('/\s+NULL/i', '', $type);
  256. // safe to drop not null even if there was none in the first place
  257. $multiAlterStatement[] = "ALTER COLUMN {$columnName} DROP NOT NULL";
  258. }
  259. if (preg_match('/\s+CHECK\s+\((.+)\)/i', $type, $matches)) {
  260. $type = preg_replace('/\s+CHECK\s+\((.+)\)/i', '', $type);
  261. $multiAlterStatement[] = "ADD CONSTRAINT {$constraintPrefix}_check CHECK ({$matches[1]})";
  262. }
  263. $type = preg_replace('/\s+UNIQUE/i', '', $type, -1, $count);
  264. if ($count) {
  265. $multiAlterStatement[] = "ADD UNIQUE ({$columnName})";
  266. }
  267. // add what's left at the beginning
  268. array_unshift($multiAlterStatement, "ALTER COLUMN {$columnName} {$type}");
  269. return 'ALTER TABLE ' . $tableName . ' ' . implode(', ', $multiAlterStatement);
  270. }
  271. /**
  272. * {@inheritdoc}
  273. */
  274. public function insert($table, $columns, &$params)
  275. {
  276. return parent::insert($table, $this->normalizeTableRowData($table, $columns), $params);
  277. }
  278. /**
  279. * {@inheritdoc}
  280. * @see https://www.postgresql.org/docs/9.5/static/sql-insert.html#SQL-ON-CONFLICT
  281. * @see https://stackoverflow.com/questions/1109061/insert-on-duplicate-update-in-postgresql/8702291#8702291
  282. */
  283. public function upsert($table, $insertColumns, $updateColumns, &$params)
  284. {
  285. $insertColumns = $this->normalizeTableRowData($table, $insertColumns);
  286. if (!is_bool($updateColumns)) {
  287. $updateColumns = $this->normalizeTableRowData($table, $updateColumns);
  288. }
  289. if (version_compare($this->db->getServerVersion(), '9.5', '<')) {
  290. return $this->oldUpsert($table, $insertColumns, $updateColumns, $params);
  291. }
  292. return $this->newUpsert($table, $insertColumns, $updateColumns, $params);
  293. }
  294. /**
  295. * [[upsert()]] implementation for PostgreSQL 9.5 or higher.
  296. * @param string $table
  297. * @param array|Query $insertColumns
  298. * @param array|bool $updateColumns
  299. * @param array $params
  300. * @return string
  301. */
  302. private function newUpsert($table, $insertColumns, $updateColumns, &$params)
  303. {
  304. $insertSql = $this->insert($table, $insertColumns, $params);
  305. list($uniqueNames, , $updateNames) = $this->prepareUpsertColumns($table, $insertColumns, $updateColumns);
  306. if (empty($uniqueNames)) {
  307. return $insertSql;
  308. }
  309. if ($updateNames === []) {
  310. // there are no columns to update
  311. $updateColumns = false;
  312. }
  313. if ($updateColumns === false) {
  314. return "$insertSql ON CONFLICT DO NOTHING";
  315. }
  316. if ($updateColumns === true) {
  317. $updateColumns = [];
  318. foreach ($updateNames as $name) {
  319. $updateColumns[$name] = new Expression('EXCLUDED.' . $this->db->quoteColumnName($name));
  320. }
  321. }
  322. list($updates, $params) = $this->prepareUpdateSets($table, $updateColumns, $params);
  323. return $insertSql . ' ON CONFLICT (' . implode(', ', $uniqueNames) . ') DO UPDATE SET ' . implode(', ', $updates);
  324. }
  325. /**
  326. * [[upsert()]] implementation for PostgreSQL older than 9.5.
  327. * @param string $table
  328. * @param array|Query $insertColumns
  329. * @param array|bool $updateColumns
  330. * @param array $params
  331. * @return string
  332. */
  333. private function oldUpsert($table, $insertColumns, $updateColumns, &$params)
  334. {
  335. /** @var Constraint[] $constraints */
  336. list($uniqueNames, $insertNames, $updateNames) = $this->prepareUpsertColumns($table, $insertColumns, $updateColumns, $constraints);
  337. if (empty($uniqueNames)) {
  338. return $this->insert($table, $insertColumns, $params);
  339. }
  340. if ($updateNames === []) {
  341. // there are no columns to update
  342. $updateColumns = false;
  343. }
  344. /** @var Schema $schema */
  345. $schema = $this->db->getSchema();
  346. if (!$insertColumns instanceof Query) {
  347. $tableSchema = $schema->getTableSchema($table);
  348. $columnSchemas = $tableSchema !== null ? $tableSchema->columns : [];
  349. foreach ($insertColumns as $name => $value) {
  350. // NULLs and numeric values must be type hinted in order to be used in SET assigments
  351. // NVM, let's cast them all
  352. if (isset($columnSchemas[$name])) {
  353. $phName = self::PARAM_PREFIX . count($params);
  354. $params[$phName] = $value;
  355. $insertColumns[$name] = new Expression("CAST($phName AS {$columnSchemas[$name]->dbType})");
  356. }
  357. }
  358. }
  359. list(, $placeholders, $values, $params) = $this->prepareInsertValues($table, $insertColumns, $params);
  360. $updateCondition = ['or'];
  361. $insertCondition = ['or'];
  362. $quotedTableName = $schema->quoteTableName($table);
  363. foreach ($constraints as $constraint) {
  364. $constraintUpdateCondition = ['and'];
  365. $constraintInsertCondition = ['and'];
  366. foreach ($constraint->columnNames as $name) {
  367. $quotedName = $schema->quoteColumnName($name);
  368. $constraintUpdateCondition[] = "$quotedTableName.$quotedName=\"EXCLUDED\".$quotedName";
  369. $constraintInsertCondition[] = "\"upsert\".$quotedName=\"EXCLUDED\".$quotedName";
  370. }
  371. $updateCondition[] = $constraintUpdateCondition;
  372. $insertCondition[] = $constraintInsertCondition;
  373. }
  374. $withSql = 'WITH "EXCLUDED" (' . implode(', ', $insertNames)
  375. . ') AS (' . (!empty($placeholders) ? 'VALUES (' . implode(', ', $placeholders) . ')' : ltrim($values, ' ')) . ')';
  376. if ($updateColumns === false) {
  377. $selectSubQuery = (new Query())
  378. ->select(new Expression('1'))
  379. ->from($table)
  380. ->where($updateCondition);
  381. $insertSelectSubQuery = (new Query())
  382. ->select($insertNames)
  383. ->from('EXCLUDED')
  384. ->where(['not exists', $selectSubQuery]);
  385. $insertSql = $this->insert($table, $insertSelectSubQuery, $params);
  386. return "$withSql $insertSql";
  387. }
  388. if ($updateColumns === true) {
  389. $updateColumns = [];
  390. foreach ($updateNames as $name) {
  391. $quotedName = $this->db->quoteColumnName($name);
  392. if (strrpos($quotedName, '.') === false) {
  393. $quotedName = '"EXCLUDED".' . $quotedName;
  394. }
  395. $updateColumns[$name] = new Expression($quotedName);
  396. }
  397. }
  398. list($updates, $params) = $this->prepareUpdateSets($table, $updateColumns, $params);
  399. $updateSql = 'UPDATE ' . $this->db->quoteTableName($table) . ' SET ' . implode(', ', $updates)
  400. . ' FROM "EXCLUDED" ' . $this->buildWhere($updateCondition, $params)
  401. . ' RETURNING ' . $this->db->quoteTableName($table) . '.*';
  402. $selectUpsertSubQuery = (new Query())
  403. ->select(new Expression('1'))
  404. ->from('upsert')
  405. ->where($insertCondition);
  406. $insertSelectSubQuery = (new Query())
  407. ->select($insertNames)
  408. ->from('EXCLUDED')
  409. ->where(['not exists', $selectUpsertSubQuery]);
  410. $insertSql = $this->insert($table, $insertSelectSubQuery, $params);
  411. return "$withSql, \"upsert\" AS ($updateSql) $insertSql";
  412. }
  413. /**
  414. * {@inheritdoc}
  415. */
  416. public function update($table, $columns, $condition, &$params)
  417. {
  418. return parent::update($table, $this->normalizeTableRowData($table, $columns), $condition, $params);
  419. }
  420. /**
  421. * Normalizes data to be saved into the table, performing extra preparations and type converting, if necessary.
  422. *
  423. * @param string $table the table that data will be saved into.
  424. * @param array|Query $columns the column data (name => value) to be saved into the table or instance
  425. * of [[yii\db\Query|Query]] to perform INSERT INTO ... SELECT SQL statement.
  426. * Passing of [[yii\db\Query|Query]] is available since version 2.0.11.
  427. * @return array|Query normalized columns
  428. * @since 2.0.9
  429. */
  430. private function normalizeTableRowData($table, $columns)
  431. {
  432. if ($columns instanceof Query) {
  433. return $columns;
  434. }
  435. if (($tableSchema = $this->db->getSchema()->getTableSchema($table)) !== null) {
  436. $columnSchemas = $tableSchema->columns;
  437. foreach ($columns as $name => $value) {
  438. if (isset($columnSchemas[$name]) && $columnSchemas[$name]->type === Schema::TYPE_BINARY && is_string($value)) {
  439. $columns[$name] = new PdoValue($value, \PDO::PARAM_LOB); // explicitly setup PDO param type for binary column
  440. }
  441. }
  442. }
  443. return $columns;
  444. }
  445. /**
  446. * {@inheritdoc}
  447. */
  448. public function batchInsert($table, $columns, $rows, &$params = [])
  449. {
  450. if (empty($rows)) {
  451. return '';
  452. }
  453. $schema = $this->db->getSchema();
  454. if (($tableSchema = $schema->getTableSchema($table)) !== null) {
  455. $columnSchemas = $tableSchema->columns;
  456. } else {
  457. $columnSchemas = [];
  458. }
  459. $values = [];
  460. foreach ($rows as $row) {
  461. $vs = [];
  462. foreach ($row as $i => $value) {
  463. if (isset($columns[$i], $columnSchemas[$columns[$i]])) {
  464. $value = $columnSchemas[$columns[$i]]->dbTypecast($value);
  465. }
  466. if (is_string($value)) {
  467. $value = $schema->quoteValue($value);
  468. } elseif (is_float($value)) {
  469. // ensure type cast always has . as decimal separator in all locales
  470. $value = StringHelper::floatToString($value);
  471. } elseif ($value === true) {
  472. $value = 'TRUE';
  473. } elseif ($value === false) {
  474. $value = 'FALSE';
  475. } elseif ($value === null) {
  476. $value = 'NULL';
  477. } elseif ($value instanceof ExpressionInterface) {
  478. $value = $this->buildExpression($value, $params);
  479. }
  480. $vs[] = $value;
  481. }
  482. $values[] = '(' . implode(', ', $vs) . ')';
  483. }
  484. if (empty($values)) {
  485. return '';
  486. }
  487. foreach ($columns as $i => $name) {
  488. $columns[$i] = $schema->quoteColumnName($name);
  489. }
  490. return 'INSERT INTO ' . $schema->quoteTableName($table)
  491. . ' (' . implode(', ', $columns) . ') VALUES ' . implode(', ', $values);
  492. }
  493. }