From a62ab78e2a7060ea1c68c5fa837d0939789786b7 Mon Sep 17 00:00:00 2001 From: "laurent.duretz" Date: Thu, 8 Feb 2007 18:51:22 +0000 Subject: Issue : 137 git-svn-id: http://piwigo.org/svn/trunk@1790 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/include/functions.php | 57 +++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'admin') diff --git a/admin/include/functions.php b/admin/include/functions.php index c3494d266..7bc9cf5e6 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -521,60 +521,61 @@ 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_begin = ' -INSERT INTO '.$table_name.' - ('.implode(',', $dbfields).') - VALUES'; - $first = true; - $query_value = ''; - + + $query = 'SHOW VARIABLES where variable_name = \'max_allowed_packet\';'; + list(, $packet_size) = mysql_fetch_row(pwg_query($query)); + $packet_size = $packet_size - 2000; // The last list of values MUST not exceed 2000 character + foreach ($datas as $insert) { + if (strlen($query) >= $packet_size) + { + $query .= ' +;'; + pwg_query($query); + $first = true; + } + if ($first) { + $query = ' + INSERT INTO '.$table_name.' + ('.implode(',', $dbfields).') + VALUES'; $first = false; } else { - if (strlen($query_value) >= $conf['max_allowed_packet']) - { - pwg_query( $query_begin.$query_value ); - $query_value = ''; - } - else - { - $query_value .= ','; - } + $query .= ' + , '; } - - $query_value .= ' - ('; - + + $query .= '('; foreach ($dbfields as $field_id => $dbfield) { if ($field_id > 0) { - $query_value .= ','; + $query .= ','; } if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') { - $query_value .= 'NULL'; + $query .= 'NULL'; } else { - $query_value .= "'".$insert[$dbfield]."'"; + $query .= "'".$insert[$dbfield]."'"; } } - $query_value .= ')'; + $query .= ')'; } - pwg_query($query_begin.$query_value); + + $query .= ' +;'; + pwg_query($query); } } -- cgit v1.2.3