From 515d66cc9fbfb34c50b4a7a27a915fd46e70b846 Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio <fog@initd.org> Date: Thu, 3 Mar 2005 06:31:03 +0000 Subject: [PATCH] Added __conform__ to all adapters. --- ChangeLog | 5 ++--- psycopg/adapter_asis.c | 20 ++++++++++++-------- psycopg/adapter_datetime.c | 19 ++++++++++++------- psycopg/adapter_mxdatetime.c | 19 ++++++++++++------- psycopg/adapter_pboolean.c | 19 ++++++++++++------- psycopg/adapter_qstring.c | 17 +++++++++++++++++ 6 files changed, 67 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 59400d96..8a2e336f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,7 @@ 2005-03-02 Federico Di Gregorio <fog@debian.org> - * psycopg/adapter_binary.c (binary_conform): started to add - __conform__ to all adapters. - + * psycopg/adapter_*.c: added __conform__ to all adapters. + * psycopg/adapter_qstring.c (qstring_quote): we now use PyString_AsStringAndSize() instead of strlen() that would stop at the first embedded \0 (but note that libpq quoting function will diff --git a/psycopg/adapter_asis.c b/psycopg/adapter_asis.c index 5e5fb861..93a793c3 100644 --- a/psycopg/adapter_asis.c +++ b/psycopg/adapter_asis.c @@ -29,7 +29,7 @@ #include "psycopg/python.h" #include "psycopg/psycopg.h" #include "psycopg/adapter_asis.h" - +#include "psycopg/microprotocols_proto.h" /** the AsIs object **/ @@ -52,14 +52,19 @@ asis_getquoted(asisObject *self, PyObject *args) } PyObject * -asis_prepare(asisObject *self, PyObject *args) +asis_conform(binaryObject *self, PyObject *args) { - PyObject *fake; + PyObject *res, *proto; - if (!PyArg_ParseTuple(args, "O", &fake)) return NULL; + if (!PyArg_ParseTuple(args, "O", &proto)) return NULL; - Py_INCREF(Py_None); - return Py_None; + if (proto == (PyObject*)&isqlquoteType) + res = (PyObject*)self; + else + res = Py_None; + + Py_INCREF(res); + return res; } /** the AsIs object */ @@ -76,8 +81,7 @@ static struct PyMemberDef asisObject_members[] = { static PyMethodDef asisObject_methods[] = { {"getquoted", (PyCFunction)asis_getquoted, METH_VARARGS, "getquoted() -> wrapped object value as SQL-quoted string"}, - /* {"prepare", (PyCFunction)asis_prepare, METH_VARARGS, - "prepare(conn) -> currently does nothing"}, */ + {"__conform__", (PyCFunction)asis_conform, METH_VARARGS, NULL}, {NULL} /* Sentinel */ }; diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c index 2f3b70ac..acbf43b1 100644 --- a/psycopg/adapter_datetime.c +++ b/psycopg/adapter_datetime.c @@ -32,6 +32,7 @@ #include "psycopg/python.h" #include "psycopg/psycopg.h" #include "psycopg/adapter_datetime.h" +#include "psycopg/microprotocols_proto.h" /* the pointer to the datetime module API is initialized by the module init @@ -83,14 +84,19 @@ pydatetime_getquoted(pydatetimeObject *self, PyObject *args) } PyObject * -pydatetime_prepare(pydatetimeObject *self, PyObject *args) +datetime_conform(binaryObject *self, PyObject *args) { - PyObject *fake; + PyObject *res, *proto; - if (!PyArg_ParseTuple(args, "O", &fake)) return NULL; + if (!PyArg_ParseTuple(args, "O", &proto)) return NULL; - Py_INCREF(Py_None); - return Py_None; + if (proto == (PyObject*)&isqlquoteType) + res = (PyObject*)self; + else + res = Py_None; + + Py_INCREF(res); + return res; } /** the DateTime wrapper object **/ @@ -108,8 +114,7 @@ static struct PyMemberDef pydatetimeObject_members[] = { static PyMethodDef pydatetimeObject_methods[] = { {"getquoted", (PyCFunction)pydatetime_getquoted, METH_VARARGS, "getquoted() -> wrapped object value as SQL date/time"}, - /* {"prepare", (PyCFunction)pydatetime_prepare, METH_VARARGS, - "prepare(conn) -> currently does nothing"}, */ + {"__conform__", (PyCFunction)pydatetime_conform, METH_VARARGS, NULL}, {NULL} /* Sentinel */ }; diff --git a/psycopg/adapter_mxdatetime.c b/psycopg/adapter_mxdatetime.c index 1c83e0ca..3a1b5966 100644 --- a/psycopg/adapter_mxdatetime.c +++ b/psycopg/adapter_mxdatetime.c @@ -30,6 +30,7 @@ #include "psycopg/python.h" #include "psycopg/psycopg.h" #include "psycopg/adapter_mxdatetime.h" +#include "psycopg/microprotocols_proto.h" /* the pointer to the mxDateTime API is initialized by the module init code, we just need to grab it */ @@ -59,14 +60,19 @@ mxdatetime_getquoted(mxdatetimeObject *self, PyObject *args) } PyObject * -mxdatetime_prepare(mxdatetimeObject *self, PyObject *args) +mxdatetime_conform(binaryObject *self, PyObject *args) { - PyObject *fake; + PyObject *res, *proto; - if (!PyArg_ParseTuple(args, "O", &fake)) return NULL; + if (!PyArg_ParseTuple(args, "O", &proto)) return NULL; - Py_INCREF(Py_None); - return Py_None; + if (proto == (PyObject*)&isqlquoteType) + res = (PyObject*)self; + else + res = Py_None; + + Py_INCREF(res); + return res; } /** the MxDateTime object **/ @@ -84,8 +90,7 @@ static struct PyMemberDef mxdatetimeObject_members[] = { static PyMethodDef mxdatetimeObject_methods[] = { {"getquoted", (PyCFunction)mxdatetime_getquoted, METH_VARARGS, "getquoted() -> wrapped object value as SQL date/time"}, - /* {"prepare", (PyCFunction)mxdatetime_prepare, METH_VARARGS, - "prepare(conn) -> currently does nothing"}, */ + {"__conform__", (PyCFunction)mxdatetime_conform, METH_VARARGS, NULL}, {NULL} /* Sentinel */ }; diff --git a/psycopg/adapter_pboolean.c b/psycopg/adapter_pboolean.c index a58aecdb..cb77fc81 100644 --- a/psycopg/adapter_pboolean.c +++ b/psycopg/adapter_pboolean.c @@ -29,6 +29,7 @@ #include "psycopg/python.h" #include "psycopg/psycopg.h" #include "psycopg/adapter_pboolean.h" +#include "psycopg/microprotocols_proto.h" /** the Boolean object **/ @@ -52,14 +53,19 @@ pboolean_getquoted(pbooleanObject *self, PyObject *args) } PyObject * -pboolean_prepare(pbooleanObject *self, PyObject *args) +pboolean_conform(binaryObject *self, PyObject *args) { - PyObject *fake; + PyObject *res, *proto; - if (!PyArg_ParseTuple(args, "O", &fake)) return NULL; + if (!PyArg_ParseTuple(args, "O", &proto)) return NULL; - Py_INCREF(Py_None); - return Py_None; + if (proto == (PyObject*)&isqlquoteType) + res = (PyObject*)self; + else + res = Py_None; + + Py_INCREF(res); + return res; } /** the Boolean object */ @@ -76,8 +82,7 @@ static struct PyMemberDef pbooleanObject_members[] = { static PyMethodDef pbooleanObject_methods[] = { {"getquoted", (PyCFunction)pboolean_getquoted, METH_VARARGS, "getquoted() -> wrapped object value as SQL-quoted string"}, - /* {"prepare", (PyCFunction)pboolean_prepare, METH_VARARGS, - "prepare(conn) -> currently does nothing"}, */ + {"__conform__", (PyCFunction)pboolean_conform, METH_VARARGS, NULL}, {NULL} /* Sentinel */ }; diff --git a/psycopg/adapter_qstring.c b/psycopg/adapter_qstring.c index 755cdf1e..93d3dade 100644 --- a/psycopg/adapter_qstring.c +++ b/psycopg/adapter_qstring.c @@ -32,6 +32,7 @@ #include "psycopg/psycopg.h" #include "psycopg/connection.h" #include "psycopg/adapter_qstring.h" +#include "psycopg/microprotocols_proto.h" /** the quoting code */ @@ -183,6 +184,21 @@ qstring_prepare(qstringObject *self, PyObject *args) return Py_None; } +PyObject * +qstring_conform(binaryObject *self, PyObject *args) +{ + PyObject *res, *proto; + + if (!PyArg_ParseTuple(args, "O", &proto)) return NULL; + + if (proto == (PyObject*)&isqlquoteType) + res = (PyObject*)self; + else + res = Py_None; + + Py_INCREF(res); + return res; +} /** the QuotedString object **/ @@ -202,6 +218,7 @@ static PyMethodDef qstringObject_methods[] = { "getquoted() -> wrapped object value as SQL-quoted string"}, {"prepare", (PyCFunction)qstring_prepare, METH_VARARGS, "prepare(conn) -> set encoding to conn->encoding"}, + {"__conform__", (PyCFunction)qstring_conform, METH_VARARGS, NULL}, {NULL} /* Sentinel */ };