problem with psqlite2 return types

Danny shevitz at lanl.gov
Thu Jul 19 00:47:26 CEST 2007


Howdy,

I'm having troubles with psqlite2 and the return types from a query. The problem
is that my data which is numeric, is being returned as a string. I'm aware of the
detect_types=sqlite.PARSE_DECLTYPES argument to the connect function. 

Here's my connection code:  
		self.connection = sqlite.connect(self.dbFile,
detect_types=sqlite.PARSE_DECLTYPES)#
		self.connection.text_factory=str
		self.cursor = self.connection.cursor()

Here's my sql (I'm returning risk1, which is numeric):
create table risk(
	quantity varchar(8),
	color varchar(8),
	risk1 real,
	risk2 real,
	primary key (quantity, color)
	);
	
( I have also tried [REAL, float, FLOAT], none work for me)

Here's my query (this will probably be not much use out of context...):
		primaryKeys = self.primaryKeyFields[table]
		primaryKeyList= ' and '.join(['%s = ?'% pKey for pKey in primaryKeys])
		query = 'select %s from %s where %s' % (field, table, primaryKeyList)
		paramList = [state[primaryKey] for primaryKey in primaryKeys]
		self.cursor.execute(query, paramList)

Any ideas?

TIA,
Danny




More information about the Python-list mailing list