mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 19:31:54 +08:00
Updated _mysql to do some type conversion. Adds a dictionary type_conv
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.
This commit is contained in:
@ -1,11 +1,19 @@
|
||||
import _mysql
|
||||
from _mysql import *
|
||||
from DateTime import Date, Time, Timestamp
|
||||
from DateTime import Date, Time, Timestamp, ISO
|
||||
from types import StringType, ListType, TupleType
|
||||
|
||||
threadsafety = 1
|
||||
apllevel = "1.1"
|
||||
|
||||
def mysql_timestamp_converter(s):
|
||||
parts = map(int, filter(None, (s[:4],s[4:6],s[6:8],s[8:10],s[10:12],s[12:14])))
|
||||
return apply(Timestamp, tuple(parts))
|
||||
|
||||
type_conv[FIELD_TYPE.TIMESTAMP] = mysql_timestamp_converter
|
||||
type_conv[FIELD_TYPE.DATETIME] = ISO.ParseDateTime
|
||||
type_conv[FIELD_TYPE.TIME] = ISO.ParseTime
|
||||
type_conv[FIELD_TYPE.DATE] = ISO.ParseDate
|
||||
|
||||
class Cursor:
|
||||
|
||||
|
Reference in New Issue
Block a user