[ticket/12439] Unify behavior and deduplicate sql_multi_insert

PHPBB3-12439
This commit is contained in:
Marc Alexander 2023-07-02 10:48:46 +02:00
parent 3e2d2d240a
commit 1a6de696b1
No known key found for this signature in database
GPG key ID: 50E0D2423696F995

View file

@ -724,38 +724,28 @@ abstract class driver implements driver_interface
return false;
}
if ($this->multi_insert)
$ary = array();
foreach ($sql_ary as $_sql_ary)
{
$ary = array();
foreach ($sql_ary as $id => $_sql_ary)
// If by accident the sql array is only one-dimensional we build a normal insert statement
if (!is_array($_sql_ary))
{
// If by accident the sql array is only one-dimensional we build a normal insert statement
if (!is_array($_sql_ary))
{
return $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $sql_ary));
}
return $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $sql_ary));
}
// Add values to set to $ary if multi insert is supported, otherwise run every insert query separately
if ($this->multi_insert)
{
$values = array();
foreach ($_sql_ary as $key => $var)
foreach ($_sql_ary as $var)
{
$values[] = $this->_sql_validate_value($var);
}
$ary[] = '(' . implode(', ', $values) . ')';
}
return $this->sql_query('INSERT INTO ' . $table . ' ' . ' (' . implode(', ', array_keys($sql_ary[0])) . ') VALUES ' . implode(', ', $ary));
}
else
{
foreach ($sql_ary as $ary)
else
{
if (!is_array($ary))
{
return false;
}
$result = $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $ary));
$result = $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $_sql_ary));
if (!$result)
{
return false;
@ -763,6 +753,11 @@ abstract class driver implements driver_interface
}
}
if ($this->multi_insert)
{
return $this->sql_query('INSERT INTO ' . $table . ' ' . ' (' . implode(', ', array_keys($sql_ary[0])) . ') VALUES ' . implode(', ', $ary));
}
return true;
}