Projects/worblehat-old
Projects
/
worblehat-old
Archived
12
0
Fork 0

New utility function execute_query, wrapping cursor.execute.

This is a hack to avoid a problem with using %(foo)d in a query with a
NULL value.
This commit is contained in:
Øystein Ingmar Skartsæterhagen 2011-10-08 19:20:21 +00:00
parent b34f8da82b
commit 87e0cdda9d
1 changed files with 6 additions and 0 deletions

View File

@ -1,6 +1,12 @@
import os import os
import tempfile import tempfile
def execute_query(cursor, query, bindings):
for (key, val) in bindings.items():
if val == None:
query = query.replace('%(' + key + ')d', 'NULL')
cursor.execute(query, bindings)
def make_result_dict(cursor, row): def make_result_dict(cursor, row):
d = {} d = {}
for i in xrange(len(row)): for i in xrange(len(row)):