Optimizations to type casting (in preparation to array support.)

This commit is contained in:
Federico Di Gregorio 2005-03-12 06:39:47 +00:00
parent c639b92bd9
commit 9316c6af53
16 changed files with 118 additions and 137 deletions

View File

@ -1,13 +1,30 @@
2005-03-12 Federico Di Gregorio <fog@debian.org>
* psycopg/cursor_type.c (_psyco_curs_buildrow_fill): modified to
call typecast_cast().
* psycopg/typecast.c (typecast_call/typecast_cast): modified
typecast_call to use the new typecast_cast that avoids one string
conversion on every cast.
2005-03-04 Federico Di Gregorio <fog@initd.org> 2005-03-04 Federico Di Gregorio <fog@initd.org>
* Release 1.99.13.1. * Release 1.99.12.1.
* psycopg/adapter_asis.c (asis_str): changed call to PyObject_Repr * psycopg/adapter_asis.c (asis_str): changed call to PyObject_Repr
to PyObject_Str to avoid problems with long integers. to PyObject_Str to avoid problems with long integers.
2005-03-03 Federico Di Gregorio <fog@debian.org>
* psycopg/typecast.h: added array casting functions.
* scripts/maketypes.sh: does not generate pgversion.h anymore.
* Updated all examples for the release.
2005-03-02 Federico Di Gregorio <fog@debian.org> 2005-03-02 Federico Di Gregorio <fog@debian.org>
* Release 1.99.13. * Release 1.99.12.
* psycopg/adapter_*.c: added __conform__ to all adapters. * psycopg/adapter_*.c: added __conform__ to all adapters.

View File

@ -26,7 +26,6 @@ if len(sys.argv) > 1:
DSN = sys.argv[1] DSN = sys.argv[1]
print "Opening connection using dsn:", DSN print "Opening connection using dsn:", DSN
conn = psycopg.connect(DSN) conn = psycopg.connect(DSN)
print "Encoding for this connection is", conn.encoding print "Encoding for this connection is", conn.encoding
@ -51,7 +50,7 @@ class Cursor(psycopg.extensions.cursor):
raise NoDataError("no more data") raise NoDataError("no more data")
return d return d
curs = conn.cursor(factory=Cursor) curs = conn.cursor(cursor_factory=Cursor)
curs.execute("SELECT 1 AS foo") curs.execute("SELECT 1 AS foo")
print "Result of fetchone():", curs.fetchone() print "Result of fetchone():", curs.fetchone()

View File

@ -49,10 +49,10 @@ curs.execute("""INSERT INTO test_oid
moid = curs.lastrowid moid = curs.lastrowid
print "Oid for %(name)s %(surname)s" % data[1], "is", moid print "Oid for %(name)s %(surname)s" % data[1], "is", moid
curs.execute("SELECT * FROM test_oid WHERE oid = %d", (foid,)) curs.execute("SELECT * FROM test_oid WHERE oid = %s", (foid,))
print "Oid", foid, "selected %s %s" % curs.fetchone() print "Oid", foid, "selected %s %s" % curs.fetchone()
curs.execute("SELECT * FROM test_oid WHERE oid = %d", (moid,)) curs.execute("SELECT * FROM test_oid WHERE oid = %s", (moid,))
print "Oid", moid, "selected %s %s" % curs.fetchone() print "Oid", moid, "selected %s %s" % curs.fetchone()
curs.execute("DROP TABLE test_oid") curs.execute("DROP TABLE test_oid")

View File

@ -1,4 +1,4 @@
# mogrify.py - test all possible type mogrifications # mogrify.py - test all possible simple type mogrifications
# -*- encoding: latin1 -*- # -*- encoding: latin1 -*-
# #
# Copyright (C) 2004 Federico Di Gregorio <fog@debian.org> # Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
@ -33,14 +33,14 @@ curs = conn.cursor()
curs.execute("SELECT %(foo)s AS foo", {'foo':'bar'}) curs.execute("SELECT %(foo)s AS foo", {'foo':'bar'})
curs.execute("SELECT %(foo)s AS foo", {'foo':None}) curs.execute("SELECT %(foo)s AS foo", {'foo':None})
curs.execute("SELECT %(foo)s AS foo", {'foo':True}) curs.execute("SELECT %(foo)s AS foo", {'foo':True})
curs.execute("SELECT %(foo)f AS foo", {'foo':42}) curs.execute("SELECT %(foo)s AS foo", {'foo':42})
curs.execute("SELECT %(foo)s AS foo", {'foo':u'yattà!'}) curs.execute("SELECT %(foo)s AS foo", {'foo':u'yattà!'})
curs.execute("SELECT %(foo)s AS foo", {'foo':u'bar'}) curs.execute("SELECT %(foo)s AS foo", {'foo':u'bar'})
print curs.mogrify("SELECT %(foo)s AS foo", {'foo':'bar'}) print curs.mogrify("SELECT %(foo)s AS foo", {'foo':'bar'})
print curs.mogrify("SELECT %(foo)s AS foo", {'foo':None}) print curs.mogrify("SELECT %(foo)s AS foo", {'foo':None})
print curs.mogrify("SELECT %(foo)s AS foo", {'foo':True}) print curs.mogrify("SELECT %(foo)s AS foo", {'foo':True})
print curs.mogrify("SELECT %(foo)f AS foo", {'foo':42}) print curs.mogrify("SELECT %(foo)s AS foo", {'foo':42})
print curs.mogrify("SELECT %(foo)s AS foo", {'foo':u'yattà!'}) print curs.mogrify("SELECT %(foo)s AS foo", {'foo':u'yattà!'})
print curs.mogrify("SELECT %(foo)s AS foo", {'foo':u'bar'}) print curs.mogrify("SELECT %(foo)s AS foo", {'foo':u'bar'})

View File

@ -81,7 +81,7 @@ def insert_func(conn_or_pool, rows):
conn = conn_or_pool.getconn() conn = conn_or_pool.getconn()
c = conn.cursor() c = conn.cursor()
try: try:
c.execute("INSERT INTO test_threads VALUES (%s, %d, %f)", c.execute("INSERT INTO test_threads VALUES (%s, %s, %s)",
(str(i), i, float(i))) (str(i), i, float(i)))
except psycopg.ProgrammingError, err: except psycopg.ProgrammingError, err:
print name, ": an error occurred; skipping this insert" print name, ": an error occurred; skipping this insert"

View File

@ -30,6 +30,7 @@
#include "psycopg/cursor.h" #include "psycopg/cursor.h"
#include "psycopg/connection.h" #include "psycopg/connection.h"
#include "psycopg/pqpath.h" #include "psycopg/pqpath.h"
#include "psycopg/typecast.h"
#include "psycopg/microprotocols.h" #include "psycopg/microprotocols.h"
#include "psycopg/microprotocols_proto.h" #include "psycopg/microprotocols_proto.h"
#include "pgversion.h" #include "pgversion.h"
@ -545,30 +546,25 @@ static PyObject *
_psyco_curs_buildrow_fill(cursorObject *self, PyObject *res, _psyco_curs_buildrow_fill(cursorObject *self, PyObject *res,
int row, int n, int istuple) int row, int n, int istuple)
{ {
int i; int i, len;
PyObject *str, *val; unsigned char *str;
PyObject *val;
for (i=0; i < n; i++) { for (i=0; i < n; i++) {
if (PQgetisnull(self->pgres, row, i)) { if (PQgetisnull(self->pgres, row, i)) {
Py_INCREF(Py_None); str = NULL;
str = Py_None; len = 0;
} }
else { else {
char *s = PQgetvalue(self->pgres, row, i); str = PQgetvalue(self->pgres, row, i);
int l = PQgetlength(self->pgres, row, i); len = PQgetlength(self->pgres, row, i);
str = PyString_FromStringAndSize(s, l);
Dprintf("_psyco_curs_buildrow: row %ld, element %d, len %i",
self->row, i, l);
} }
Dprintf("_psyco_curs_buildrow: str->refcnt = %d", str->ob_refcnt); Dprintf("_psyco_curs_buildrow: row %ld, element %d, len %i",
val = PyObject_CallFunction(PyTuple_GET_ITEM(self->casts, i), "OO", self->row, i, len);
str, self);
/* here we DECREF str because the typecaster should already have val = typecast_cast(PyTuple_GET_ITEM(self->casts, i), str, len,
INCREFfed it, if necessary and we don't need it anymore */ (PyObject*)self);
Py_DECREF(str);
Dprintf("_psyco_curs_buildrow: str->refcnt = %d", str->ob_refcnt);
if (val) { if (val) {
Dprintf("_psyco_curs_buildrow: val->refcnt = %d", val->ob_refcnt); Dprintf("_psyco_curs_buildrow: val->refcnt = %d", val->ob_refcnt);
@ -590,7 +586,6 @@ _psyco_curs_buildrow_fill(cursorObject *self, PyObject *res,
} }
} }
return res; return res;
} }
static PyObject * static PyObject *

View File

@ -34,21 +34,6 @@
/** void protocol implementation **/ /** void protocol implementation **/
/* prepare - prepare object for quotation */
#define psyco_isqlquote_prepare_doc \
"prepare(conn) -> prepare object with connection 'conn'"
static PyObject *
psyco_isqlquote_prepare(isqlquoteObject *self, PyObject *args)
{
PyObject* conn = NULL;
if (!PyArg_ParseTuple(args, "O", &conn)) return NULL;
Py_INCREF(Py_None);
return Py_None;
}
/* getquoted - return quoted representation for object */ /* getquoted - return quoted representation for object */

View File

@ -305,31 +305,15 @@ typecast_destroy(typecastObject *self)
static PyObject * static PyObject *
typecast_call(PyObject *obj, PyObject *args, PyObject *kwargs) typecast_call(PyObject *obj, PyObject *args, PyObject *kwargs)
{ {
PyObject *string, *cursor, *res; PyObject *string, *cursor;
typecastObject *self = (typecastObject *)obj;
if (!PyArg_ParseTuple(args, "OO", &string, &cursor)) { if (!PyArg_ParseTuple(args, "OO", &string, &cursor)) {
return NULL; return NULL;
} }
if (self->ccast) { return typecast_cast(obj,
Dprintf("typecast_call: calling C cast function"); PyString_AsString(string), PyString_Size(string),
res = self->ccast(string, cursor); cursor);
}
else if (self->pcast) {
Dprintf("typecast_call: calling python callable");
Py_INCREF(string);
res = PyObject_CallFunction(self->pcast, "OO", string, cursor);
}
else {
Py_INCREF(Py_None);
res = Py_None;
}
Dprintf("typecast_call: string argument has refcnt = %d",
string->ob_refcnt);
return res;
} }
@ -436,4 +420,21 @@ typecast_from_c(typecastObject_initlist *type)
return (PyObject *)obj; return (PyObject *)obj;
} }
PyObject *
typecast_cast(PyObject *obj, unsigned char *str, int len, PyObject *curs)
{
typecastObject *self = (typecastObject *)obj;
if (self->ccast) {
Dprintf("typecast_call: calling C cast function");
return self->ccast(str, len, curs);
}
else if (self->pcast) {
Dprintf("typecast_call: calling python callable");
return PyObject_CallFunction(self->pcast, "s#O", str, len, curs);
}
else {
PyErr_SetString(Error, "internal error: no casting function found");
return NULL;
}
}

View File

@ -29,7 +29,7 @@ extern "C" {
#endif #endif
/* type of type-casting functions (both C and Python) */ /* type of type-casting functions (both C and Python) */
typedef PyObject *(*typecast_function)(PyObject *, PyObject *); typedef PyObject *(*typecast_function)(unsigned char *, int len, PyObject *);
/** typecast type **/ /** typecast type **/
@ -74,4 +74,8 @@ extern PyObject *typecast_from_c(typecastObject_initlist *type);
extern PyObject *typecast_from_python( extern PyObject *typecast_from_python(
PyObject *self, PyObject *args, PyObject *keywds); PyObject *self, PyObject *args, PyObject *keywds);
/* the function used to dispatch typecasting calls */
extern PyObject *typecast_cast(
PyObject *self, unsigned char *str, int len, PyObject *curs);
#endif /* !defined(PSYCOPG_TYPECAST_H) */ #endif /* !defined(PSYCOPG_TYPECAST_H) */

View File

@ -20,59 +20,57 @@
*/ */
#include <libpq-fe.h> #include <libpq-fe.h>
#include <stdlib.h>
/** INTEGER - cast normal integers (4 bytes) to python int **/ /** INTEGER - cast normal integers (4 bytes) to python int **/
static PyObject * static PyObject *
typecast_INTEGER_cast(PyObject *s, PyObject *curs) typecast_INTEGER_cast(unsigned char *s, int len, PyObject *curs)
{ {
if (s == Py_None) {Py_INCREF(s); return s;} if (s == NULL) {Py_INCREF(Py_None); return Py_None;}
return PyNumber_Int(s); return PyInt_FromString(s, NULL, 0);
} }
/** LONGINTEGER - cast long integers (8 bytes) to python long **/ /** LONGINTEGER - cast long integers (8 bytes) to python long **/
static PyObject * static PyObject *
typecast_LONGINTEGER_cast(PyObject *s, PyObject *curs) typecast_LONGINTEGER_cast(unsigned char *s, int len, PyObject *curs)
{ {
if (s == Py_None) {Py_INCREF(s); return s;} if (s == NULL) {Py_INCREF(Py_None); return Py_None;}
return PyNumber_Long(s); return PyLong_FromString(s, NULL, 0);
} }
/** FLOAT - cast floating point numbers to python float **/ /** FLOAT - cast floating point numbers to python float **/
static PyObject * static PyObject *
typecast_FLOAT_cast(PyObject *s, PyObject *curs) typecast_FLOAT_cast(unsigned char *s, int len, PyObject *curs)
{ {
if (s == Py_None) {Py_INCREF(s); return s;} if (s == NULL) {Py_INCREF(Py_None); return Py_None;}
return PyNumber_Float(s); return PyFloat_FromDouble(atof(s));
} }
/** STRING - cast strings of any type to python string **/ /** STRING - cast strings of any type to python string **/
static PyObject * static PyObject *
typecast_STRING_cast(PyObject *s, PyObject *curs) typecast_STRING_cast(unsigned char *s, int len, PyObject *curs)
{ {
Py_INCREF(s); if (s == NULL) {Py_INCREF(Py_None); return Py_None;}
return s; return PyString_FromStringAndSize(s, len);
} }
/** UNICODE - cast strings of any type to a python unicode object **/ /** UNICODE - cast strings of any type to a python unicode object **/
static PyObject * static PyObject *
typecast_UNICODE_cast(PyObject *s, PyObject *curs) typecast_UNICODE_cast(unsigned char *s, int len, PyObject *curs)
{ {
PyObject *enc; PyObject *enc;
if (s == Py_None) {Py_INCREF(s); return s;} if (s == NULL) {Py_INCREF(Py_None); return Py_None;}
enc = PyDict_GetItemString(psycoEncodings, enc = PyDict_GetItemString(psycoEncodings,
((cursorObject*)curs)->conn->encoding); ((cursorObject*)curs)->conn->encoding);
if (enc) { if (enc) {
return PyUnicode_Decode(PyString_AsString(s), return PyUnicode_Decode(s, strlen(s), PyString_AsString(enc), NULL);
PyString_Size(s),
PyString_AsString(enc),
NULL);
} }
else { else {
PyErr_Format(InterfaceError, PyErr_Format(InterfaceError,
@ -134,15 +132,15 @@ typecast_BINARY_cast_unescape(unsigned char *str, size_t *to_length)
#endif #endif
static PyObject * static PyObject *
typecast_BINARY_cast(PyObject *s, PyObject *curs) typecast_BINARY_cast(unsigned char *s, int l, PyObject *curs)
{ {
PyObject *res; PyObject *res;
unsigned char *str; unsigned char *str;
size_t len; size_t len;
if (s == Py_None) {Py_INCREF(s); return s;} if (s == NULL) {Py_INCREF(Py_None); return Py_None;}
str = PQunescapeBytea(PyString_AS_STRING(s), &len); str = PQunescapeBytea(s, &len);
Dprintf("typecast_BINARY_cast: unescaped %d bytes", len); Dprintf("typecast_BINARY_cast: unescaped %d bytes", len);
/* TODO: using a PyBuffer would make this a zero-copy operation but we'll /* TODO: using a PyBuffer would make this a zero-copy operation but we'll
@ -159,13 +157,13 @@ typecast_BINARY_cast(PyObject *s, PyObject *curs)
/** BOOLEAN - cast boolean value into right python object **/ /** BOOLEAN - cast boolean value into right python object **/
static PyObject * static PyObject *
typecast_BOOLEAN_cast(PyObject *s, PyObject *curs) typecast_BOOLEAN_cast(unsigned char *s, int len, PyObject *curs)
{ {
PyObject *res; PyObject *res;
if (s == Py_None) {Py_INCREF(s); return s;} if (s == NULL) {Py_INCREF(Py_None); return Py_None;}
if (PyString_AS_STRING(s)[0] == 't') if (s[0] == 't')
res = Py_True; res = Py_True;
else else
res = Py_False; res = Py_False;
@ -178,10 +176,10 @@ typecast_BOOLEAN_cast(PyObject *s, PyObject *curs)
#ifdef HAVE_DECIMAL #ifdef HAVE_DECIMAL
static PyObject * static PyObject *
typecast_DECIMAL_cast(PyObject *s, PyObject *curs) typecast_DECIMAL_cast(unsigned char *s, int len, PyObject *curs)
{ {
if (s == Py_None) {Py_INCREF(s); return s;} if (s == NULL) {Py_INCREF(Py_None); return Py_None;}
return PyObject_CallFunction(decimalType, "O", s); return PyObject_CallFunction(decimalType, "s", s);
} }
#else #else
#define typecast_DECIMAL_cast typecast_FLOAT_cast #define typecast_DECIMAL_cast typecast_FLOAT_cast

View File

@ -34,15 +34,12 @@ extern PyObject *pyDeltaTypeP;
/** DATE - cast a date into a date python object **/ /** DATE - cast a date into a date python object **/
static PyObject * static PyObject *
typecast_PYDATE_cast(PyObject *s, PyObject *curs) typecast_PYDATE_cast(unsigned char *str, int len, PyObject *curs)
{ {
PyObject* obj = NULL; PyObject* obj = NULL;
int n, y=0, m=0, d=0; int n, y=0, m=0, d=0;
char *str;
if (s == Py_None) {Py_INCREF(s); return s;} if (str == NULL) {Py_INCREF(Py_None); return Py_None;}
str = PyString_AsString(s);
/* check for infinity */ /* check for infinity */
if (!strcmp(str, "infinity") || !strcmp(str, "-infinity")) { if (!strcmp(str, "infinity") || !strcmp(str, "-infinity")) {
@ -70,18 +67,16 @@ typecast_PYDATE_cast(PyObject *s, PyObject *curs)
/** DATETIME - cast a timestamp into a datetime python object **/ /** DATETIME - cast a timestamp into a datetime python object **/
static PyObject * static PyObject *
typecast_PYDATETIME_cast(PyObject *s, PyObject *curs) typecast_PYDATETIME_cast(unsigned char *str, int len, PyObject *curs)
{ {
PyObject* obj = NULL; PyObject* obj = NULL;
int n, y=0, m=0, d=0; int n, y=0, m=0, d=0;
int hh=0, mm=0; int hh=0, mm=0;
int tzh=0, tzm=0; int tzh=0, tzm=0;
double ss=0.0; double ss=0.0;
char tzs=0, *str; char tzs=0;
if (s == Py_None) {Py_INCREF(s); return s;} if (str == NULL) {Py_INCREF(Py_None); return Py_None;}
str = PyString_AsString(s);
/* check for infinity */ /* check for infinity */
if (!strcmp(str, "infinity") || !strcmp(str, "-infinity")) { if (!strcmp(str, "infinity") || !strcmp(str, "-infinity")) {
@ -136,16 +131,13 @@ typecast_PYDATETIME_cast(PyObject *s, PyObject *curs)
/** TIME - parse time into a time object **/ /** TIME - parse time into a time object **/
static PyObject * static PyObject *
typecast_PYTIME_cast(PyObject *s, PyObject *curs) typecast_PYTIME_cast(unsigned char *str, int len, PyObject *curs)
{ {
PyObject* obj = NULL; PyObject* obj = NULL;
int n, hh=0, mm=0; int n, hh=0, mm=0;
double ss=0.0; double ss=0.0;
char *str;
if (s == Py_None) {Py_INCREF(s); return s;} if (str == NULL) {Py_INCREF(Py_None); return Py_None;}
str = PyString_AsString(s);
n = sscanf(str, "%d:%d:%lf", &hh, &mm, &ss); n = sscanf(str, "%d:%d:%lf", &hh, &mm, &ss);
@ -168,19 +160,15 @@ typecast_PYTIME_cast(PyObject *s, PyObject *curs)
/** INTERVAL - parse an interval into a timedelta object **/ /** INTERVAL - parse an interval into a timedelta object **/
static PyObject * static PyObject *
typecast_PYINTERVAL_cast(PyObject *s, PyObject *curs) typecast_PYINTERVAL_cast(unsigned char *str, int len, PyObject *curs)
{ {
long years = 0, months = 0, days = 0, denominator = 1; long years = 0, months = 0, days = 0, denominator = 1;
double hours = 0.0, minutes = 0.0, seconds = 0.0, hundredths = 0.0; double hours = 0.0, minutes = 0.0, seconds = 0.0, hundredths = 0.0;
double v = 0.0, sign = 1.0; double v = 0.0, sign = 1.0;
int part = 0, sec; int part = 0, sec;
double micro; double micro;
char *str;
if (s == Py_None) {Py_INCREF(s); return s;} if (str == NULL) {Py_INCREF(Py_None); return Py_None;}
str = PyString_AsString(s);
Dprintf("typecast_PYINTERVAL_cast: s = %s", str); Dprintf("typecast_PYINTERVAL_cast: s = %s", str);

View File

@ -28,16 +28,13 @@ extern mxDateTimeModule_APIObject *mxDateTimeP;
/** DATE - cast a date into mx.DateTime python object **/ /** DATE - cast a date into mx.DateTime python object **/
static PyObject * static PyObject *
typecast_MXDATE_cast(PyObject *s, PyObject *curs) typecast_MXDATE_cast(unsigned char *str, int len, PyObject *curs)
{ {
int n, y=0, m=0, d=0; int n, y=0, m=0, d=0;
int hh=0, mm=0; int hh=0, mm=0;
double ss=0.0; double ss=0.0;
char *str;
if (s == Py_None) {Py_INCREF(s); return s;} if (str == NULL) {Py_INCREF(Py_None); return Py_None;}
str = PyString_AsString(s);
/* check for infinity */ /* check for infinity */
if (!strcmp(str, "infinity") || !strcmp(str, "-infinity")) { if (!strcmp(str, "infinity") || !strcmp(str, "-infinity")) {
@ -63,15 +60,12 @@ typecast_MXDATE_cast(PyObject *s, PyObject *curs)
/** TIME - parse time into an mx.DateTime object **/ /** TIME - parse time into an mx.DateTime object **/
static PyObject * static PyObject *
typecast_MXTIME_cast(PyObject *s, PyObject *curs) typecast_MXTIME_cast(unsigned char *str, int len, PyObject *curs)
{ {
int n, hh=0, mm=0; int n, hh=0, mm=0;
double ss=0.0; double ss=0.0;
char *str;
if (s == Py_None) {Py_INCREF(s); return s;} if (str == NULL) {Py_INCREF(Py_None); return Py_None;}
str = PyString_AsString(s);
Dprintf("typecast_MXTIME_cast: s = %s", str); Dprintf("typecast_MXTIME_cast: s = %s", str);
@ -90,17 +84,15 @@ typecast_MXTIME_cast(PyObject *s, PyObject *curs)
/** INTERVAL - parse an interval into an mx.DateTimeDelta **/ /** INTERVAL - parse an interval into an mx.DateTimeDelta **/
static PyObject * static PyObject *
typecast_MXINTERVAL_cast(PyObject *s, PyObject *curs) typecast_MXINTERVAL_cast(unsigned char *str, int len, PyObject *curs)
{ {
long years = 0, months = 0, days = 0, denominator = 1; long years = 0, months = 0, days = 0, denominator = 1;
double hours = 0.0, minutes = 0.0, seconds = 0.0, hundredths = 0.0; double hours = 0.0, minutes = 0.0, seconds = 0.0, hundredths = 0.0;
double v = 0.0, sign = 1.0; double v = 0.0, sign = 1.0;
int part = 0; int part = 0;
char *str;
if (s == Py_None) {Py_INCREF(s); return s;} if (str == NULL) {Py_INCREF(Py_None); return Py_None;}
str = PyString_AsString(s);
Dprintf("typecast_MXINTERVAL_cast: s = %s", str); Dprintf("typecast_MXINTERVAL_cast: s = %s", str);
while (*str) { while (*str) {

View File

@ -37,8 +37,8 @@ echo -n generating typecast_builtins.c ...
awk '/#define .+OID/ {print $2 " " $3}' "$PGTYPE" | \ awk '/#define .+OID/ {print $2 " " $3}' "$PGTYPE" | \
python $SCRIPTSDIR/buildtypes.py >$SRCDIR/typecast_builtins.c python $SCRIPTSDIR/buildtypes.py >$SRCDIR/typecast_builtins.c
echo " done" echo " done"
echo -n generating pgversion.h ... #echo -n generating pgversion.h ...
echo "#define PG_VERSION_MAJOR $PGMAJOR" >$SRCDIR/pgversion.h #echo "#define PG_VERSION_MAJOR $PGMAJOR" >$SRCDIR/pgversion.h
echo "#define PG_VERSION_MINOR $PGMINOR" >>$SRCDIR/pgversion.h #echo "#define PG_VERSION_MINOR $PGMINOR" >>$SRCDIR/pgversion.h
echo " done" #echo " done"

View File

@ -1,5 +1,5 @@
[build_ext] [build_ext]
define=PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3 define=PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3,PSYCOPG_DEBUG
# PSYCOPG_DEBUG can be added to enable verbose debug information # PSYCOPG_DEBUG can be added to enable verbose debug information
# PSYCOPG_OWN_QUOTING can be added above but it is deprecated # PSYCOPG_OWN_QUOTING can be added above but it is deprecated

View File

@ -47,7 +47,7 @@ from distutils.core import setup, Extension
from distutils.sysconfig import get_python_inc from distutils.sysconfig import get_python_inc
import distutils.ccompiler import distutils.ccompiler
PSYCOPG_VERSION = '1.99.12.1' PSYCOPG_VERSION = '1.99.13/devel'
version_flags = [] version_flags = []
have_pydatetime = False have_pydatetime = False

View File

@ -40,6 +40,8 @@ class TypesBasicTests(TestCase):
def testNumber(self): def testNumber(self):
s = self.execute("SELECT %s AS foo", (1971,)) s = self.execute("SELECT %s AS foo", (1971,))
self.failUnless(s == 1971, "wrong integer quoting: " + str(s)) self.failUnless(s == 1971, "wrong integer quoting: " + str(s))
s = self.execute("SELECT %s AS foo", (1971L,))
self.failUnless(s == 1971L, "wrong integer quoting: " + str(s))
s = self.execute("SELECT %s AS foo", (19.10,)) s = self.execute("SELECT %s AS foo", (19.10,))
self.failUnless(s == 19.10, "wrong float quoting: " + str(s)) self.failUnless(s == 19.10, "wrong float quoting: " + str(s))