diff options
author | Kenneth Graunke <kenneth@whitecape.org> | 2012-11-25 13:37:33 -0800 |
---|---|---|
committer | Kenneth Graunke <kenneth@whitecape.org> | 2012-11-25 13:37:41 -0800 |
commit | 85501f5aadccd7f1d247ef58df16b2560cc1dcab (patch) | |
tree | 3edabb357175d981819a7238f35b69396c34a0a9 | |
parent | bce1a8666b949d2290cf09b5ee31c8934b32e57f (diff) |
proof of concept: way faster inserts
but the code is horrendously ugly, and it doesn't look like apsw has a
way to multiple-row inserts yet. plus, I'm not using bindings, which
makes it vulnerable to injection attacks, and....oy sqlite :/
-rw-r--r-- | framework/database.py | 13 | ||||
-rwxr-xr-x | programs/run.py | 3 |
2 files changed, 10 insertions, 6 deletions
diff --git a/framework/database.py b/framework/database.py index 5e9e5d1..6f899ba 100644 --- a/framework/database.py +++ b/framework/database.py @@ -60,7 +60,12 @@ class ResultDatabase: cursor.execute('INSERT INTO runs VALUES(?,?,?,?)', (date, name, driver, sysinfo)) return date - def addPlaceholderResult(self, run, testName): - cursor = self.connection.cursor() - cursor.execute('INSERT INTO results(run_id, test_name) VALUES(?,?)', - (run, testName)) + def addPlaceholderResults(self, run, tests): + #rows = [(run, test) for test in tests] + c = self.connection.cursor() + #c.executemany('INSERT INTO results(run_id, test_name) VALUES(?,?)', rows) + testlist = list(tests) + batches = [testlist[x:x+500] for x in range(0, len(testlist), 500)] + for batch in batches: + query = 'INSERT INTO results(run_id, test_name) VALUES (' + '),('.join([str(run) + ',' + "'" + test.replace("'", '') + "'" for test in batch]) + ')' + c.execute(query) diff --git a/programs/run.py b/programs/run.py index c1f4a34..69a1ae1 100755 --- a/programs/run.py +++ b/programs/run.py @@ -82,8 +82,7 @@ def main(argv, config): runID = db.createRun(args.name, 'driver', 'system') # Populate results with "not run yet" - for test in tests.keys(): - db.addPlaceholderResult(runID, test) + db.addPlaceholderResults(runID, tests.keys()) # Resume |