From 3cbb89cefbd88f4ab973ef701b685dd8552604c1 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 25 Mar 2016 22:57:59 +0100 Subject: [PATCH] It turns out that SQLite 3.7.11+ implements multi-inserts! Version 3.8 is the minimum sqlite version fro php 5.5 --- src/Database/Dialect/SqliteDialectTrait.php | 53 --------------------- 1 file changed, 53 deletions(-) diff --git a/src/Database/Dialect/SqliteDialectTrait.php b/src/Database/Dialect/SqliteDialectTrait.php index 2376d618e65..9d785d6d2a7 100644 --- a/src/Database/Dialect/SqliteDialectTrait.php +++ b/src/Database/Dialect/SqliteDialectTrait.php @@ -149,59 +149,6 @@ protected function _transformFunctionExpression(FunctionExpression $expression) } } - /** - * Transforms an insert query that is meant to insert multiple rows at a time, - * otherwise it leaves the query untouched. - * - * The way SQLite works with multi insert is by having multiple select statements - * joined with UNION. - * - * @param \Cake\Database\Query $query The query to translate - * @return \Cake\Database\Query - */ - protected function _insertQueryTranslator($query) - { - $v = $query->clause('values'); - if (count($v->values()) === 1 || $v->query()) { - return $query; - } - - $newQuery = $query->connection()->newQuery(); - $cols = $v->columns(); - $placeholder = 0; - $replaceQuery = false; - - foreach ($v->values() as $k => $val) { - $fillLength = count($cols) - count($val); - if ($fillLength > 0) { - $val = array_merge($val, array_fill(0, $fillLength, null)); - } - - foreach ($val as $col => $attr) { - if (!($attr instanceof ExpressionInterface)) { - $val[$col] = sprintf(':c%d', $placeholder); - $placeholder++; - } - } - - $select = array_combine($cols, $val); - if ($k === 0) { - $replaceQuery = true; - $newQuery->select($select); - continue; - } - - $q = $newQuery->connection()->newQuery(); - $newQuery->unionAll($q->select($select)); - } - - if ($replaceQuery) { - $v->query($newQuery); - } - - return $query; - } - /** * Get the schema dialect. *