[svn:p5ee] r8685 - p5ee/trunk/App-Repository/lib/App/Repository

[email protected]
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
Author: spadkins
Date: Tue Jan 23 14:41:42 2007
New Revision: 8685

Modified:
   p5ee/trunk/App-Repository/lib/App/Repository/MySQL.pm

Log:
updated MySQL.pm insert_rows to batches of options->maxrows

Modified: p5ee/trunk/App-Repository/lib/App/Repository/MySQL.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository/MySQL.pm	(original)
+++ p5ee/trunk/App-Repository/lib/App/Repository/MySQL.pm	Tue Jan 23 14:41:42 2007
@@ -219,22 +219,32 @@
     }
     my $rows_ref = ref($rows);
     if ($rows_ref eq "ARRAY") {
-        $sql = $self->_mk_insert_rows_sql($table, $cols, $rows);
-        if ($debug_sql) {
-            print "DEBUG_SQL: _insert_rows()\n";
-            print $sql;
-        }
-        $retval = $dbh->do($sql);
-        if ($debug_sql) {
-            print "DEBUG_SQL: retval [$retval] $DBI::errstr\n";
-            print "\n";
-        }
+        my $maxrows = $options->{maxrows} || 100;
+        my $rownum = 0;
+        my (@current_rows, $rownum2);
+        while ($rownum <= $#$rows) {
+            $rownum2 = $rownum + $maxrows - 1;
+            $rownum2 = $#$rows if ($rownum2 > $#$rows);
+            @current_rows = @{$rows}[($rownum .. $rownum2)];
 
-        $nrows = $retval;
-        $self->{numrows} = $nrows;
-        if ($retval != $#$rows + 1) {
+            $sql = $self->_mk_insert_rows_sql($table, $cols, \@current_rows);
+            if ($debug_sql) {
+                print "DEBUG_SQL: _insert_rows()\n";
+                print $sql;
+            }
+            $retval = $dbh->do($sql);
+            if ($debug_sql) {
+                print "DEBUG_SQL: retval [$retval] $DBI::errstr\n";
+                print "\n";
+            }
+
+            $nrows += $retval;
+            $rownum += $maxrows;
+        }
+        if ($nrows != $#$rows + 1) {
             $ok = 0;
         }
+        $self->{numrows} = $nrows;
     }
     else {
         my ($fh);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.