diff options
| author | Federico Di Gregorio <fog@initd.org> | 2005-04-10 05:38:34 +0000 |
|---|---|---|
| committer | Federico Di Gregorio <fog@initd.org> | 2005-04-10 05:38:34 +0000 |
| commit | 48d8bd39a1be26c436adc9413011dec899f955ae (patch) | |
| tree | b8506b25ee98b4bc1a6ee72b339df068cff97fef /psycopg/microprotocols.c | |
| parent | 1430849c813cbeea246917f8a4a790b26b28b4fc (diff) | |
| download | psycopg2-48d8bd39a1be26c436adc9413011dec899f955ae.tar.gz | |
Array support completed (closes: #1).
Diffstat (limited to 'psycopg/microprotocols.c')
| -rw-r--r-- | psycopg/microprotocols.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/psycopg/microprotocols.c b/psycopg/microprotocols.c index 9675d91..6f75f25 100644 --- a/psycopg/microprotocols.c +++ b/psycopg/microprotocols.c @@ -27,6 +27,7 @@ #include "psycopg/python.h" #include "psycopg/psycopg.h" #include "psycopg/cursor.h" +#include "psycopg/connection.h" #include "psycopg/microprotocols.h" #include "psycopg/microprotocols_proto.h" @@ -109,6 +110,42 @@ microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt) return NULL; } +/* microprotocol_getquoted - utility function that adapt and call getquoted */ + +PyObject * +microprotocol_getquoted(PyObject *obj, connectionObject *conn) +{ + PyObject *res = NULL; + PyObject *tmp = microprotocols_adapt( + obj, (PyObject*)&isqlquoteType, NULL); + + if (tmp != NULL) { + Dprintf("microprotocol_getquoted: adapted to %s", + tmp->ob_type->tp_name); + + /* if requested prepare the object passing it the connection */ + if (PyObject_HasAttrString(tmp, "prepare") && conn) { + res = PyObject_CallMethod(tmp, "prepare", "O", (PyObject*)conn); + if (res == NULL) { + Py_DECREF(tmp); + return NULL; + } + else { + Py_DECREF(res); + } + } + + /* call the getquoted method on tmp (that should exist because we + adapted to the right protocol) */ + res = PyObject_CallMethod(tmp, "getquoted", NULL); + Py_DECREF(tmp); + } + + /* we return res with one extra reference, the caller shall free it */ + return res; +} + + /** module-level functions **/ PyObject * |
