From 87e0cdda9d20235352fc73e7041212831388e998 Mon Sep 17 00:00:00 2001 From: oysteini Date: Sat, 8 Oct 2011 19:20:21 +0000 Subject: [PATCH] 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. --- cli/util.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cli/util.py b/cli/util.py index 81cd483..8705d36 100644 --- a/cli/util.py +++ b/cli/util.py @@ -1,6 +1,12 @@ import os 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): d = {} for i in xrange(len(row)):