Author: david
Date: Fri Feb 25 16:44:03 2011
New Revision: 9000
Log:
Chunk update to work around invisible limit on exec()
Modified:
trunk/lib/task/propelBuildNestedSetTask.class.php
Modified: trunk/lib/task/propelBuildNestedSetTask.class.php
==============================================================================
--- trunk/lib/task/propelBuildNestedSetTask.class.php Fri Feb 25 00:02:58
2011 (r8999)
+++ trunk/lib/task/propelBuildNestedSetTask.class.php Fri Feb 25 16:44:03
2011 (r9000)
@@ -103,13 +103,20 @@
self::addChildren($tree[0], $children, 1);
// Crawl tree and build sql statement to update nested set columns
- $sql = self::getNsUpdateSql($tree[0], $classname);
+ $rows = self::getNsUpdateRows($tree[0], $classname);
// Update database
$conn->beginTransaction();
try
{
- $conn->exec($sql);
+ // There seems to be some limit on how many rows we can update with one
+ // exec() statement, so chunk the update rows
+ $incr = 4000;
+ for ($i=0; $i <= count($rows); $i+=$incr)
+ {
+ $sql = implode("\n", array_slice($rows, $i, $incr));
+ $conn->exec($sql);
+ }
}
catch (PDOException $e)
{
@@ -147,21 +154,22 @@
return $width;
}
- protected function getNsUpdateSql($node, $classname)
+ protected function getNsUpdateRows($node, $classname)
{
- $sql = 'UPDATE '.constant($classname.'::TABLE_NAME');
- $sql .= ' SET lft = '.$node['lft'];
- $sql .= ', rgt = '.$node['rgt'];
- $sql .= ' WHERE id = '.$node['id'].";\n";
+ $str = 'UPDATE '.constant($classname.'::TABLE_NAME');
+ $str .= ' SET lft = '.$node['lft'];
+ $str .= ', rgt = '.$node['rgt'];
+ $str .= ' WHERE id = '.$node['id'].";";
+ $rows = array($str);
if (0 < count($node['children']))
{
foreach ($node['children'] as $child)
{
- $sql .= self::getNsUpdateSql($child, $classname);
+ $rows = array_merge($rows, self::getNsUpdateRows($child, $classname));
}
}
- return $sql;
+ return $rows;
}
}
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.