Changeset 1790


Ignore:
Timestamp:
Feb 8, 2007, 7:51:22 PM (17 years ago)
Author:
laurent_duretz
Message:

Issue : 137

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r1789 r1790  
    522522function mass_inserts($table_name, $dbfields, $datas)
    523523{
    524   global $conf;
    525 
    526524  if (count($datas) != 0)
    527525  {
    528     // inserts all found categories
    529     $query_begin = '
    530 INSERT INTO '.$table_name.'
    531   ('.implode(',', $dbfields).')
    532   VALUES';
    533 
    534526    $first = true;
    535     $query_value = '';
    536 
     527     
     528    $query = 'SHOW VARIABLES where variable_name = \'max_allowed_packet\';';
     529    list(, $packet_size) = mysql_fetch_row(pwg_query($query));
     530    $packet_size = $packet_size - 2000; // The last list of values MUST not exceed 2000 character
     531   
    537532    foreach ($datas as $insert)
    538533    {
     534      if (strlen($query) >= $packet_size)
     535      {
     536        $query .= '
     537;';
     538        pwg_query($query);
     539        $first = true;
     540      }
     541     
    539542      if ($first)
    540543      {
     544        $query = '
     545  INSERT INTO '.$table_name.'
     546    ('.implode(',', $dbfields).')
     547     VALUES';
    541548        $first = false;
    542549      }
    543550      else
    544551      {
    545         if (strlen($query_value) >= $conf['max_allowed_packet'])
    546         {
    547           pwg_query( $query_begin.$query_value );
    548           $query_value = '';
    549         }
    550         else
    551         {
    552           $query_value .= ',';
    553         }
     552        $query .= '
     553    , ';
    554554      }
    555 
    556       $query_value .= '
    557     (';
    558 
     555     
     556      $query .= '(';
    559557      foreach ($dbfields as $field_id => $dbfield)
    560558      {
    561559        if ($field_id > 0)
    562560        {
    563           $query_value .= ',';
     561          $query .= ',';
    564562        }
    565563
    566564        if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
    567565        {
    568           $query_value .= 'NULL';
     566          $query .= 'NULL';
    569567        }
    570568        else
    571569        {
    572           $query_value .= "'".$insert[$dbfield]."'";
     570          $query .= "'".$insert[$dbfield]."'";
    573571        }
    574572      }
    575       $query_value .= ')';
    576     }
    577     pwg_query($query_begin.$query_value);
     573      $query .= ')';
     574    }
     575   
     576    $query .= '
     577;';
     578    pwg_query($query);
    578579  }
    579580}
  • trunk/include/config_default.inc.php

    r1788 r1790  
    678678$conf['light_slideshow'] = true; 
    679679
    680 // +-----------------------------------------------------------------------+
    681 // |                                mysql                                  |
    682 // +-----------------------------------------------------------------------+
    683 
    684 // $conf['max_allowed_packet'] indicates the max size in octets of MySql
    685 // request. Used in mass_inserts() function.
    686 $conf['max_allowed_packet'] = 1000000;
    687 
    688680?>
Note: See TracChangeset for help on using the changeset viewer.