mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 17:06:33 +03:00
Little fixes.
This commit is contained in:
parent
8d8bfe969b
commit
cf7701a151
10
ChangeLog
10
ChangeLog
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 **/
|
||||
|
|
Loading…
Reference in New Issue
Block a user