which makes MySQL field types to Python functions which perform the
conversion. All numeric types except DECIMAL are mapped into either
PyInt or PyLong, and the floating point types are mapped into PyFloat by
default. Types which are not represented in the dictionary are returned
as strings.
Modified MySQLdb to adjust type_conv so that the various date/time types
are returned as DateTime objects.
Bug: If you were to delete or assign type_conv, bad things would happen.
I haven't actually tried this, but it wouldn't be good. May add an extra
reference count to prevent this, haven't really decided.
exception handling. And a light sprinkling of bug fixes throughout.
I'm thinking this part is done, unless I find the need to add another
feature or two for the Python DBI. All the mysql_* calls are duplicated
either as functions, connection objects, or result objects, with the
exception of deprecated functions and a lot of field_* functions.
Access to the MYSQL_FIELD members is done mostly through
ResultObject.describe(), which returns almost all information for all
the fields. ResultObject.field_flags() returns the flag values.
methods to the Result object. Also need to rip out the Field object;
ended up not needing it. It's just cruft now.
Python 1.5.2b2 (#1, Feb 18 1999, 18:20:08) [GCC egcs-2.90.29 980515 (egcs-1.0.3 re on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import _mysql
>>> c=_mysql.connect(passwd='foobar',db='vmail')
>>> c.query("insert into Users (Name, Mailbox, Forward) values ('Ed Landa', 'elanda', 'elanda@beavis.comstar.net')")
>>> c.affected_rows()
1L
>>> c.query("select * from Users")
>>> r=c.store_result()
>>> r.describe()
(('Handle', 253, 0, 16, 16, 0, 1), ('UNIXpasswd', 253, 0, 16, 16, 0, 1), ('Name', 253, 8, 64, 64, 0, 1), ('Mailbox', 253, 8, 64, 64, 0, 0), ('DomainName', 253, 0, 64, 64, 0, 0), ('Forward', 252, 25, 65535, 65535, 0, 1), ('Secret', 253, 0, 64, 64, 0, 1), ('Active', 2, 0, 6, 6, 0, 1), ('MailQuota', 2, 0, 6, 6, 0, 1), ('Priv', 2, 0, 6, 6, 0, 1), ('Updated', 7, 14, 14, 14, 0, 0), ('AcctUpdate', 2, 0, 6, 6, 0, 1), ('RefNo', 3, 0, 11, 11, 0, 1), ('MailboxHash', 253, 0, 32, 32, 0, 1))
>>> r.fetch_row()
(None, None, 'Andy', 'adustman', '', None, None, None, None, None, '19990312021455', None, None, None)
>>> r.fetch_row()
(None, None, 'Ed Landa', 'elanda', '', 'elanda@beavis.comstar.net', None, None, None, None, '19990312022659', None, None, None)
>>> r.fetch_row()
>>>
Notes: NULL values represented by Python None object. fetch_row() returns
None at the end of the query set, which doesn't print. Conversion of data
types will be done in a Python wrapper module. Need to figure out a way
to read a fixed number of rows without having to twiddle with the global
interpreter lock all the time. Not a big problem if store_result() has
been used, but is trickier if use_result() was used.
sorta functional. The problem with the existing interface (minor) is that
it's for 3.21 mysql. Not a huge problem, but it doesn't seem to have a stable
maintainer at the moment either.
Tommorrow I work on result objects so I can get queries done and stuff.
Python 1.5.2b2 (#1, Feb 18 1999, 18:20:08) [GCC egcs-2.90.29 980515 (egcs-1.0.3 re on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import _mysql
>>> dir(_mysql)
['__doc__', '__file__', '__name__', 'connect', 'error', 'escape', 'get_client_info']
>>> _mysql.get_client_info()
'3.22.19a'
>>> c=_mysql.connect(passwd='foobar')
>>> dir(c)
['affected_rows', 'closed', 'dump_debug_info', 'errno', 'error', 'get_host_info', 'get_proto_info', 'get_server_info', 'info', 'open']
>>> c
<open connection to 'localhost' at 80ddf50>
>>> c.get_server_info()
'3.22.19a'
>>>