From: <nc...@us...> - 2011-08-13 08:24:56
|
Revision: 840 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=840&view=rev Author: ncjones Date: 2011-08-13 08:24:50 +0000 (Sat, 13 Aug 2011) Log Message: ----------- Fix persisting of null values. ticket:138 Modified Paths: -------------- pytrainer/trunk/pytrainer/lib/sqliteUtils.py Modified: pytrainer/trunk/pytrainer/lib/sqliteUtils.py =================================================================== --- pytrainer/trunk/pytrainer/lib/sqliteUtils.py 2011-08-09 22:46:46 UTC (rev 839) +++ pytrainer/trunk/pytrainer/lib/sqliteUtils.py 2011-08-13 08:24:50 UTC (rev 840) @@ -90,11 +90,19 @@ for i in val: if count>0: string+="," - string+="""\"%s\"""" %i + string+= self._to_sql_value(i) count = count+1 sql = "insert into %s (%s) values (%s)" %(table,cells,string) cur.execute(sql) self.db.commit() + + def _to_sql_value(self, value): + if value == None: + return "null" + elif type(value) in [str, unicode]: + return "\"" + value + "\"" + else: + return str(value) def freeExec(self,sql): cur = self.db.cursor() @@ -119,7 +127,7 @@ for val in values: if count>0: string+="," - string += """%s=%s """ %(cells[count],values[count] if type(values[count]) not in [str, unicode] else "'%s'" % values[count]) + string += """%s=%s """ %(cells[count], self._to_sql_value(values[count])) count = count+1 string +=" where %s" %condition This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |