git-svn-id: http://piwigo.org/svn/trunk@1786 68402e56-0260-453c-a942-63ccdbb3a9ee

This commit is contained in:
laurent.duretz 2007-02-07 19:49:35 +00:00
commit 15b3774482
2 changed files with 45 additions and 12 deletions

View file

@ -521,48 +521,73 @@ function get_fs_directories($path, $recursive = true)
*/
function mass_inserts($table_name, $dbfields, $datas)
{
global $conf;
if (count($datas) != 0)
{
// inserts all found categories
$query = '
$query_begin = '
INSERT INTO '.$table_name.'
('.implode(',', $dbfields).')
VALUES';
$first = 1;
$first = true;
$query_value = array();
$query_value_index = 0;
foreach ($datas as $insert)
{
$query.= '
$query_value[$query_value_index] .= '
';
if ($first)
{
$first = 0;
$first = false;
if (strlen($query_value[$query_value_index]) > 6)
{
$query_value[$query_value_index] .= ',';
}
}
else
{
$query.= ',';
if (strlen($query_value[$query_value_index]) >= $conf['max_allowed_packet'])
{
$query_value_index ++;
$query_value[$query_value_index] .= '
';
$first = true;
}
else
{
$query_value[$query_value_index] .= ',';
}
}
$query.= '(';
$query_value[$query_value_index] .= '(';
foreach ($dbfields as $field_id => $dbfield)
{
if ($field_id > 0)
{
$query.= ',';
$query_value[$query_value_index] .= ',';
}
if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
{
$query.= 'NULL';
$query_value[$query_value_index] .= 'NULL';
}
else
{
$query.= "'".$insert[$dbfield]."'";
$query_value[$query_value_index] .= "'".$insert[$dbfield]."'";
}
}
$query.=')';
$query_value[$query_value_index] .= ')';
}
$query.= '
$query_end .= '
;';
pwg_query($query);
foreach ($query_value as $value)
{
$final_query = $query_begin.$value.$query_end;
pwg_query($final_query);
}
}
}

View file

@ -664,4 +664,12 @@ $conf['filter_pages'] = array
// Every plugin from 1.7 would be design to manage light_slideshow case.
$conf['light_slideshow'] = true;
// +-----------------------------------------------------------------------+
// | mysql |
// +-----------------------------------------------------------------------+
// $conf['max_allowed_packet'] indicates the max size in octets of MySql
// request. Used in mass_inserts() function.
$conf['max_allowed_packet'] = 1000000;
?>