-
Notifications
You must be signed in to change notification settings - Fork 138
Description
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:
...
// 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);
}
...
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-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.