diff options
author | Federico Di Gregorio <fog@initd.org> | 2006-06-15 12:39:56 +0000 |
---|---|---|
committer | Federico Di Gregorio <fog@initd.org> | 2006-06-15 12:39:56 +0000 |
commit | cf7701a151d5be665de4847344fa7b3e90a44f5a (patch) | |
tree | b43a9e268e898668f06ea5c3f8005c5fd503029a | |
parent | 8d8bfe969b3c196d77e74f9623059d6459f284f4 (diff) | |
download | psycopg2-cf7701a151d5be665de4847344fa7b3e90a44f5a.tar.gz |
Little fixes.
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | ZPsycopgDA/db.py | 32 | ||||
-rw-r--r-- | psycopg/typecast_basic.c | 14 |
3 files changed, 27 insertions, 29 deletions
@@ -1,3 +1,13 @@ +2006-06-15 Federico Di Gregorio <fog@initd.org> + + * psycopg/typecast_basic.c: fixed problem with bogus + conversion when importing gtk (that was crazy, I didn't + understand why it happened but the new code just fixes it.) + + * ZPsycopgDA/db.py: better type analisys, using an hash + instead of a series of if (variation on patch from Charlie + Clark.) + 2006-06-11 Federico Di Gregorio <fog@initd.org> * Release 2.0.2. diff --git a/ZPsycopgDA/db.py b/ZPsycopgDA/db.py index 5b81080..9a0b4b0 100644 --- a/ZPsycopgDA/db.py +++ b/ZPsycopgDA/db.py @@ -42,6 +42,7 @@ class DB(TM, dbi_db.DB): self.encoding = enc self.failures = 0 self.calls = 0 + self.make_mappings() def getconn(self, create=True): conn = pool.getconn(self.dsn) @@ -89,32 +90,23 @@ class DB(TM, dbi_db.DB): def sortKey(self): return 1 + def make_mappings(self): + """Generate the mappings used later by self.convert_description().""" + self.type_mappings = {} + for t, s in [(INTEGER,'i'), (LONGINTEGER, 'i'), (NUMBER, 'n'), + (BOOLEAN,'n'), (ROWID, 'i'), + (DATETIME, 'd'), (DATE, 'd'), (TIME, 'd')]: + for v in t.values: + self.type_mappings[v] = (t, s) + def convert_description(self, desc, use_psycopg_types=False): """Convert DBAPI-2.0 description field to Zope format.""" items = [] for name, typ, width, ds, p, scale, null_ok in desc: - if typ == NUMBER: - if typ == INTEGER or typ == LONGINTEGER: - typs = 'i' - else: - typs = 'n' - typp = NUMBER - elif typ == BOOLEAN: - typs = 'n' - typp = BOOLEAN - elif typ == ROWID: - typs = 'i' - typp = ROWID - # FIXME: shouldn't DATETIME include other types? - elif typ == DATETIME or typ == DATE or typ == TIME: - typs = 'd' - typp = DATETIME - else: - typs = 's' - typp = STRING + m = self.type_mappings.get(typ, (STRING, 's')) items.append({ 'name': name, - 'type': use_psycopg_types and typp or typs, + 'type': use_psycopg_types and m[0] or m[1], 'width': width, 'precision': p, 'scale': scale, diff --git a/psycopg/typecast_basic.c b/psycopg/typecast_basic.c index d3ebb0f..00f9480 100644 --- a/psycopg/typecast_basic.c +++ b/psycopg/typecast_basic.c @@ -54,15 +54,11 @@ typecast_LONGINTEGER_cast(char *s, int len, PyObject *curs) static PyObject * typecast_FLOAT_cast(char *s, int len, PyObject *curs) { - /* FIXME: is 64 large enough for any float? */ - char buffer[64]; - - if (s == NULL) {Py_INCREF(Py_None); return Py_None;} - if (s[len] != '\0') { - strncpy(buffer, s, len); buffer[len] = '\0'; - s = buffer; - } - return PyFloat_FromDouble(atof(s)); + char *pend; + PyObject *str = PyString_FromStringAndSize(s, len); + PyObject *flo = PyFloat_FromString(str, &pend); + Py_DECREF(str); + return flo; } /** STRING - cast strings of any type to python string **/ |