diff options
author | laurent.duretz <laurent.duretz@piwigo.org> | 2007-02-08 18:51:22 +0000 |
---|---|---|
committer | laurent.duretz <laurent.duretz@piwigo.org> | 2007-02-08 18:51:22 +0000 |
commit | a62ab78e2a7060ea1c68c5fa837d0939789786b7 (patch) | |
tree | 697905f0a18b45656c64fa461e3fdd4fcd29649a | |
parent | b6fc0fa5eb94301d5611b5385371aeda821da0fe (diff) |
Issue : 137
git-svn-id: http://piwigo.org/svn/trunk@1790 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r-- | admin/include/functions.php | 57 | ||||
-rw-r--r-- | include/config_default.inc.php | 8 |
2 files changed, 29 insertions, 36 deletions
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); } } diff --git a/include/config_default.inc.php b/include/config_default.inc.php index b93f3e51d..110accd46 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -677,12 +677,4 @@ $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; - ?> |