mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-26 10:53:44 +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>
|
2006-06-11 Federico Di Gregorio <fog@initd.org>
|
||||||
|
|
||||||
* Release 2.0.2.
|
* Release 2.0.2.
|
||||||
|
|
|
@ -42,6 +42,7 @@ class DB(TM, dbi_db.DB):
|
||||||
self.encoding = enc
|
self.encoding = enc
|
||||||
self.failures = 0
|
self.failures = 0
|
||||||
self.calls = 0
|
self.calls = 0
|
||||||
|
self.make_mappings()
|
||||||
|
|
||||||
def getconn(self, create=True):
|
def getconn(self, create=True):
|
||||||
conn = pool.getconn(self.dsn)
|
conn = pool.getconn(self.dsn)
|
||||||
|
@ -89,32 +90,23 @@ class DB(TM, dbi_db.DB):
|
||||||
def sortKey(self):
|
def sortKey(self):
|
||||||
return 1
|
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):
|
def convert_description(self, desc, use_psycopg_types=False):
|
||||||
"""Convert DBAPI-2.0 description field to Zope format."""
|
"""Convert DBAPI-2.0 description field to Zope format."""
|
||||||
items = []
|
items = []
|
||||||
for name, typ, width, ds, p, scale, null_ok in desc:
|
for name, typ, width, ds, p, scale, null_ok in desc:
|
||||||
if typ == NUMBER:
|
m = self.type_mappings.get(typ, (STRING, 's'))
|
||||||
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
|
|
||||||
items.append({
|
items.append({
|
||||||
'name': name,
|
'name': name,
|
||||||
'type': use_psycopg_types and typp or typs,
|
'type': use_psycopg_types and m[0] or m[1],
|
||||||
'width': width,
|
'width': width,
|
||||||
'precision': p,
|
'precision': p,
|
||||||
'scale': scale,
|
'scale': scale,
|
||||||
|
|
|
@ -54,15 +54,11 @@ typecast_LONGINTEGER_cast(char *s, int len, PyObject *curs)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
typecast_FLOAT_cast(char *s, int len, PyObject *curs)
|
typecast_FLOAT_cast(char *s, int len, PyObject *curs)
|
||||||
{
|
{
|
||||||
/* FIXME: is 64 large enough for any float? */
|
char *pend;
|
||||||
char buffer[64];
|
PyObject *str = PyString_FromStringAndSize(s, len);
|
||||||
|
PyObject *flo = PyFloat_FromString(str, &pend);
|
||||||
if (s == NULL) {Py_INCREF(Py_None); return Py_None;}
|
Py_DECREF(str);
|
||||||
if (s[len] != '\0') {
|
return flo;
|
||||||
strncpy(buffer, s, len); buffer[len] = '\0';
|
|
||||||
s = buffer;
|
|
||||||
}
|
|
||||||
return PyFloat_FromDouble(atof(s));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** STRING - cast strings of any type to python string **/
|
/** STRING - cast strings of any type to python string **/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user