@@ -326,9 +326,13 @@ def py2executeSQL(self, cursor, qStr, params=None, paramList=False):
326
326
elif paramList :
327
327
raise Exception ("Not supported!" )
328
328
else :
329
- params = tuple ([
330
- not isinstance (item , int ) and u"'%s'" % item or item
331
- for item in params ])
329
+ def py_to_sql (param ):
330
+ if param is None :
331
+ return 'NULL'
332
+ if isinstance (param , int ):
333
+ return param
334
+ return "'%s'" % param
335
+ params = tuple (map (py_to_sql , params ))
332
336
querystr = qStr .replace ('"' , "'" )
333
337
cursor .execute (querystr % params )
334
338
@@ -348,11 +352,16 @@ def pycompat_executeSQL(self, cursor, qStr, params=None, paramList=False):
348
352
except :
349
353
pass
350
354
351
- def locproc (item ):
355
+ def py_to_sql (param ):
356
+ if param is None :
357
+ return 'NULL'
358
+ if isinstance (param , int ):
359
+ return param
352
360
try :
353
- return "'%s'" % item .decode ()
361
+ return "'%s'" % param .decode ()
354
362
except :
355
- return item
363
+ return param
364
+
356
365
# _logger.debug("SQLGenerator %s - %s" % (qStr,params))
357
366
if not params :
358
367
querystr = qStr .replace ('"' , "'" )
@@ -365,7 +374,7 @@ def locproc(item):
365
374
elif paramList :
366
375
raise Exception ("Not supported!" )
367
376
else :
368
- params = tuple ([ locproc ( item ) for item in params ] )
377
+ params = tuple (map ( py_to_sql , params ) )
369
378
querystr = qStr .replace ('"' , "'" )
370
379
querystr = querystr % params
371
380
# if isinstance(qStr, bytes): qStr = qStr.decode()
@@ -461,8 +470,8 @@ def buildLiteralTripleSQLCommand(
461
470
self .normalizeTerm (obj ),
462
471
self .normalizeTerm (context .identifier ),
463
472
triplePattern ,
464
- isinstance (obj , Literal ) and obj .language or 'NULL' ,
465
- isinstance (obj , Literal ) and obj .datatype or 'NULL' ]
473
+ isinstance (obj , Literal ) and obj .language or None ,
474
+ isinstance (obj , Literal ) and obj .datatype or None ]
466
475
467
476
def buildTripleSQLCommand (
468
477
self , subject , predicate , obj , context , storeId , quoted ):
@@ -484,8 +493,8 @@ def buildTripleSQLCommand(
484
493
self .normalizeTerm (obj ),
485
494
self .normalizeTerm (context .identifier ),
486
495
triplePattern ,
487
- isinstance (obj , Literal ) and obj .language or 'NULL' ,
488
- isinstance (obj , Literal ) and obj .datatype or 'NULL' ]
496
+ isinstance (obj , Literal ) and obj .language or None ,
497
+ isinstance (obj , Literal ) and obj .datatype or None ]
489
498
else :
490
499
command = "INSERT INTO %s " % stmt_table + \
491
500
"(subject,predicate,object,context,termComb) " + \
0 commit comments