MCPcopy Index your code
hub / github.com/webpy/webpy / sqlify

Function sqlify

web/db.py:356–381  ·  view source on GitHub ↗

converts `obj` to its proper SQL version >>> sqlify(None) 'NULL' >>> sqlify(True) "'t'" >>> sqlify(3) '3'

(obj)

Source from the content-addressed store, hash-verified

354
355
356def sqlify(obj):
357 """
358 converts `obj` to its proper SQL version
359
360 >>> sqlify(None)
361 'NULL'
362 >>> sqlify(True)
363 "'t'"
364 >>> sqlify(3)
365 '3'
366 """
367 # because `1 == True and hash(1) == hash(True)`
368 # we have to do this the hard way...
369
370 if obj is None:
371 return "NULL"
372 elif obj is True:
373 return "'t'"
374 elif obj is False:
375 return "'f'"
376 elif isinstance(obj, int):
377 return str(obj)
378 elif isinstance(obj, datetime.datetime):
379 return repr(obj.isoformat())
380 else:
381 return repr(obj)
382
383
384def sqllist(lst):

Callers 1

_strMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected