[SCM] watchdog branch, master, updated. 5808702326ab5595d221d3468adffb287f2c1e97

0 views
Skip to first unread message

aaronsw

unread,
Aug 13, 2009, 4:17:48 PM8/13/09
to watchdo...@googlegroups.com
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "watchdog".

The branch, master has been updated
via 5808702326ab5595d221d3468adffb287f2c1e97 (commit)
from 0f52e799322b101c324d906df6e0670e0141322a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5808702326ab5595d221d3468adffb287f2c1e97
Author: Aaron Swartz <m...@aaronsw.com>
Date: Thu Aug 13 16:17:41 2009 -0400

don't load bulk iterators all at once

-----------------------------------------------------------------------

Summary of changes:
vendor/webpy/web/db.py | 39 +++++++++++++++++++++++++--------------
1 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/vendor/webpy/web/db.py b/vendor/webpy/web/db.py
index 31940d8..2d697cc 100644
--- a/vendor/webpy/web/db.py
+++ b/vendor/webpy/web/db.py
@@ -725,7 +725,7 @@ class DB:
self.ctx.commit()
return out

- def multiple_insert(self, tablename, values, seqname=None, _test=False):
+ def multiple_insert(self, tablename, values, seqname=None, percall=5000, _test=False):
"""
Inserts multiple rows into `tablename`. The `values` must be a list of dictioanries,
one for each row to be inserted, each with the same set of keys.
@@ -738,7 +738,19 @@ class DB:
>>> values = [{"name": "foo", "email": "f...@example.com"}, {"name": "bar", "email": "b...@example.com"}]
>>> db.multiple_insert('person', values=values, _test=True)
<sql: "INSERT INTO person (name, email) VALUES ('foo', 'f...@example.com'), ('bar', 'b...@example.com')">
- """
+ """
+ if _test:
+ return self._multiple_insert(tablename, values, seqname, _test)
+ out = []
+ rows = []
+ for row in values:
+ rows.append(row)
+ if len(rows) > percall:
+ out.extend(self._multiple_insert(tablename, rows, seqname, _test))
+ rows = []
+ out.extend(self._multiple_insert(tablename, rows, seqname, _test))
+
+ def _multiple_insert(self, tablename, values, seqname=None, _test=False):
if not values:
return []

@@ -748,21 +760,20 @@ class DB:
return None
else:
return out
-
- keys = values[0].keys()
- #@@ make sure all keys are valid
-
- # make sure all rows have same keys.
- for v in values:
- if v.keys() != keys:
- raise ValueError, 'Bad data'
-
- sql_query = SQLQuery('INSERT INTO %s (%s) VALUES ' % (tablename, ', '.join(keys)))
-
+
data = []
+ keys = None
+ count = 0
for row in values:
+ if keys is None:
+ keys = row.keys()
+ sql_query = SQLQuery('INSERT INTO %s (%s) VALUES ' % (tablename, ', '.join(keys)))
+ elif row.keys() != keys:
+ raise ValueError, 'Inconsistent keys'
+
d = SQLQuery.join([SQLParam(row[k]) for k in keys], ', ')
data.append('(' + d + ')')
+ count += 1
sql_query += SQLQuery.join(data, ', ')

if _test: return sql_query
@@ -782,7 +793,7 @@ class DB:

try:
out = db_cursor.fetchone()[0]
- out = range(out-len(values)+1, out+1)
+ out = range(out-count+1, out+1)
except Exception:
out = None


hooks/post-receive
--
watchdog

Reply all
Reply to author
Forward
0 new messages