diff options
| author | Gaëtan de Menten <gdementen@gmail.com> | 2010-02-28 20:39:49 +0000 |
|---|---|---|
| committer | Gaëtan de Menten <gdementen@gmail.com> | 2010-02-28 20:39:49 +0000 |
| commit | 08f2c2c19a2f66eaf3c243bd1db7ace82f0e1286 (patch) | |
| tree | 966b75b2d875cc6722751d1d4df48e3696c2ebec /lib/sqlalchemy/cextension | |
| parent | 9fd094edbb4d7f160fcb36ae96f39514ac1d1f88 (diff) | |
| download | sqlalchemy-08f2c2c19a2f66eaf3c243bd1db7ace82f0e1286.tar.gz | |
support scale argument for the C implementation of the decimal processor
Diffstat (limited to 'lib/sqlalchemy/cextension')
| -rw-r--r-- | lib/sqlalchemy/cextension/processors.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/sqlalchemy/cextension/processors.c b/lib/sqlalchemy/cextension/processors.c index d2d398090..6e3302719 100644 --- a/lib/sqlalchemy/cextension/processors.c +++ b/lib/sqlalchemy/cextension/processors.c @@ -143,6 +143,7 @@ typedef struct { typedef struct { PyObject_HEAD PyObject *type; + PyObject *format; } DecimalResultProcessor; @@ -158,7 +159,7 @@ UnicodeResultProcessor_init(UnicodeResultProcessor *self, PyObject *args, PyObject *encoding, *errors = NULL; static char *kwlist[] = {"encoding", "errors", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "S|S:init", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "S|S:__init__", kwlist, &encoding, &errors)) return -1; @@ -252,30 +253,38 @@ static int DecimalResultProcessor_init(DecimalResultProcessor *self, PyObject *args, PyObject *kwds) { - PyObject *type; + PyObject *type, *format; - if (!PyArg_ParseTuple(args, "O", &type)) + if (!PyArg_ParseTuple(args, "OS", &type, &format)) return -1; Py_INCREF(type); self->type = type; + Py_INCREF(format); + self->format = format; + return 0; } static PyObject * DecimalResultProcessor_process(DecimalResultProcessor *self, PyObject *value) { - PyObject *str, *result; + PyObject *str, *result, *args; if (value == Py_None) Py_RETURN_NONE; if (PyFloat_CheckExact(value)) { /* Decimal does not accept float values directly */ - str = PyObject_Str(value); + args = PyTuple_Pack(1, value); + if (args == NULL) + return NULL; + + str = PyString_Format(self->format, args); if (str == NULL) return NULL; + result = PyObject_CallFunctionObjArgs(self->type, str, NULL); Py_DECREF(str); return result; |
