[PyIndexer] Representing MySQL results as native data types
Status: Pre-Alpha
Brought to you by:
cduncan
From: Marcus C. <ma...@wr...> - 2001-12-12 17:09:56
|
On Mon, 10 Dec 2001 at 15:53:47 +0000, Chris Withers wrote: > Marcus Collins wrote: > > > The MySQL C API returns rows as an array of strings. See the typedefs > > and prototypes in mysql.h... > > Booo hiss and shame on MySQL :-( > > Has anyone requested this 'feature' be changed? I think it's probably implemented like this because returning it as a string is the most universal -- some of MySQL's data types (such as DECIMAL, for example) have no native counterparts in C. Also, MySQL has locale support which may not be available in the C libraries on all the platforms on which the C API might be used (which could very well be different to the platform on which the server is running!). And most importantly, the return type of the C function needs to be known! However, it would indeed be good to see the C API support the data types C knows about natively -- and these do account for the majority of MySQL's native data types. It would be interesting to determine what it would take to add this. I've looked only at the typedefs and declarations, and not at the definitions in the source, but I think that it could be done by allocating a pointer to the binary representation in MYSQL_RES, and having an access function in the Python wrapper (not in C; it wouldn't be all that useful since the return type would be ambiguous at compile time) to examine the column type, treat the binary data appropriately, and return a native Python object of the appropriate type. Then again, it depends how these are returned by the server itself ;-) Cheers -- Marcus |