Utilizing a MySQL back-finish and essentially want to look for the area kind of tables in the type_code within the cursor.description tuples...
Things I get is a lot of different amounts... by evaluating my tables using the type_code values I'm able to by hand come up with some correspondences... however i have numerous more types compared to type objects recorded during my Python book (Beazley), namely STRING, BINARY, NUMBER, DATETIME, ROWID.
I presume you will find therefore different type_codes receiving to such things as DECIMAL, UNSIGNED INT, etc... but I am just surprised to not have the ability to find any info out here or around the Internet generally.
What I wish to do, incidentally, would be to automate the procedure whereby input (inside a GUI power grid attached to a MySQL table for instance) determines which kind of data the table is expecting for your column, and parses and inspections it to discover whether this can be a legal value.
If you work with
MySQLdb, then your
MySQLdb.constants.FIELD_TYPE module consists of constants for every area type.
>>> print dir(MySQLdb.constants.FIELD_TYPE) ['BIT', 'BLOB', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'DOUBLE', 'ENUM', 'FLOAT', 'GEOMETRY', 'INT24', 'INTERVAL', 'LONG', 'LONGLONG', 'LONG_BLOB', 'MEDIUM_BLOB', 'NEWDATE', 'NEWDECIMAL', 'NULL', 'SET', 'SHORT', 'STRING', 'TIME', 'TIMESTAMP', 'TINY', 'TINY_BLOB', 'VARCHAR', 'VAR_STRING', 'YEAR', '__builtins__', '__doc__', '__file__', '__name__', '__package__']
For instance, the a typecode of
5 signifies it's a MySQL double
>>> MySQLdb.constants.FIELD_TYPE.DOUBLE 5
This module is noted within the documentation.
The fundamental type codes as referred to inside your book are based on the DB-API specification.
The kind_code must compare comparable to among Type Objects defined below.
The secret here's that there might be multiple different type codes that compare comparable to exactly the same type object.
>>> MySQLdb.constants.FIELD_TYPE.TIMESTAMP 7 >>> MySQLdb.constants.FIELD_TYPE.DATETIME 12 >>> MySQLdb.constants.FIELD_TYPE.TIMESTAMP==MySQLdb.DATETIME True >>> MySQLdb.constants.FIELD_TYPE.DATETIME==MySQLdb.DATETIME True >>> MySQLdb.DATETIME DBAPISet([12, 7])
(How this miracle is implemented is layed out within the note about DBAPITypeObject within the DB-API spec. A far more conventional interface may have carried this out with subclasses...)
This enables MySQLdb to provide more potent details about the column than simply maybe it's a date-and-time type, although still permitting an easy test for any string versus several.
Obviously should you start evaluating against MySQLdb.constants.Area_TYPE types directly you're depending on MySQLdb functionality that will not port with other databases.