You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func_get_args returns array of arguments, but we except every argument to be array, we need to flattern this array by one level. This is how I would fix it:
...
// Get all of the passed values
$values = array();
$args_values = func_get_args();
foreach($args_values as $i => $arg_values)
{
if ( ! is_array($arg_values))
{
throw new InvalidArgumentException('Argument ' . $i . ' must be array, got ' . gettype($arg_values));
}
}
foreach($args_values as $arg_values)
{
// Detect if it is row or array of rows
if ( ! is_array(reset($arg_values)))
{
$arg_values = array($arg_values);
}
$values = array_merge($values, $arg_values);
}
...
Note that variable $quote is not used, perhaps it migrated from previous code or it is just unfinished code. Actual problem is following. If we do bulk insert, it generates SQL-code INSERT INTO table(column1, column2) VALUES ((value1_1, value1_2), (value2_1, value2_2));. Notice double round braces. This SQL-code is not working in PostgreSQL and SphinxQL, it works only in MySQL. Proper SQL-code: INSERT INTO table(column1, column2) VALUES (value1_1, value1_2), (value2_1, value2_2);. I have no fix currently.
The text was updated successfully, but these errors were encountered:
rafis
changed the title
Bug in Database_Query_Insert
Bug in Database_Query_Insert: bad SQL for bulk insert
Nov 5, 2015
There is two related bugs in Database_Query_Insert.
First bug is here:
https://github.com/kohana/database/blob/3.3/master/classes/Kohana/Database/Query/Builder/Insert.php#L91
func_get_args
returns array of arguments, but we except every argument to be array, we need to flattern this array by one level. This is how I would fix it:Second (related bug) is here:
https://github.com/kohana/database/blob/3.3/master/classes/Kohana/Database/Query/Builder/Insert.php#L141-L160
Note that variable
$quote
is not used, perhaps it migrated from previous code or it is just unfinished code. Actual problem is following. If we do bulk insert, it generates SQL-codeINSERT INTO table(column1, column2) VALUES ((value1_1, value1_2), (value2_1, value2_2));
. Notice double round braces. This SQL-code is not working in PostgreSQL and SphinxQL, it works only in MySQL. Proper SQL-code:INSERT INTO table(column1, column2) VALUES (value1_1, value1_2), (value2_1, value2_2);
. I have no fix currently.The text was updated successfully, but these errors were encountered: