Python 2.3 Breaks PySQLite a Little

achrist at achrist at
Wed Aug 6 20:48:36 CEST 2003

Have hit a problem with PySQLite and python 2.3.  The new bool
type doesn't want to get written properly to a database. I was
expecting this to break when I started using True and False in 
python 2.2, but it didn't.  Now there's a little trouble.  
I changed the _quote function in pysqlite to look like:

	def _quote(value):

	    if value is None:
        	return 'NULL'
	    elif isinstance(value, bool):   ### Added
        	return 0 + value	    ### Added	
	    elif type(value) in (IntType, LongType, FloatType):
        	return value
	    elif isinstance(value, StringType):
        	return "'%s'" % value.replace("'", "''")
	    elif hasattr(value, '__quote__'):
        	return value.__quote__()
	    elif hasattr(value, '_quote'):
        	return value._quote()
	    elif have_datetime and type(value) in \
        	    (DateTime.DateTimeType, 						DateTime.DateTimeDeltaType):
	    return "'%s'" % value
        return repr(value)

Is that all it needs?


More information about the Python-list mailing list