From dcb0287a79df6c745b47e39b516765a329af5353 Mon Sep 17 00:00:00 2001 From: Jeremy Carbaugh Date: Tue, 9 Mar 2010 13:00:37 -0500 Subject: [PATCH] handle conversion of None to null --- saucebrush/emitters.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/saucebrush/emitters.py b/saucebrush/emitters.py index 9294bc4..cf9dd84 100644 --- a/saucebrush/emitters.py +++ b/saucebrush/emitters.py @@ -137,10 +137,13 @@ class SqlDumpEmitter(Emitter): table_name, '`,`'.join(fieldnames)) def quote(self, item): - if not isinstance(item, ('unicode','str')): + if item is None: + return "null" + elif isinstance(item, (unicode, str)): + item = item.replace("\\","\\\\").replace("'","\\'").replace(chr(0),'0') + return "'%s'" % item + else: return "%s" % item - item = item.replace("\\","\\\\").replace("'","\\'").replace(chr(0),'0') - return "'%s'" % item def emit_record(self, record): quoted_data = [self.quote(record[field]) for field in self._fieldnames]