1 /* microprotocol_proto.c - psycopg protocols
3 * Copyright (C) 2003 Federico Di Gregorio <fog@debian.org>
5 * This file is part of psycopg.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include <structmember.h>
24 #include <stringobject.h>
28 #define PSYCOPG_MODULE
29 #include "psycopg/config.h"
30 #include "psycopg/python.h"
31 #include "psycopg/psycopg.h"
32 #include "psycopg/microprotocols_proto.h"
35 /** void protocol implementation **/
38 /* getquoted - return quoted representation for object */
40 #define psyco_isqlquote_getquoted_doc \
41 "getquoted() -- return SQL-quoted representation of this object"
44 psyco_isqlquote_getquoted(isqlquoteObject *self, PyObject *args)
46 if (!PyArg_ParseTuple(args, "")) return NULL;
52 /* getbinary - return quoted representation for object */
54 #define psyco_isqlquote_getbinary_doc \
55 "getbinary() -- return SQL-quoted binary representation of this object"
58 psyco_isqlquote_getbinary(isqlquoteObject *self, PyObject *args)
60 if (!PyArg_ParseTuple(args, "")) return NULL;
66 /* getbuffer - return quoted representation for object */
68 #define psyco_isqlquote_getbuffer_doc \
69 "getbuffer() -- return this object"
72 psyco_isqlquote_getbuffer(isqlquoteObject *self, PyObject *args)
74 if (!PyArg_ParseTuple(args, "")) return NULL;
82 /** the ISQLQuote object **/
85 /* object method list */
87 static struct PyMethodDef isqlquoteObject_methods[] = {
88 {"getquoted", (PyCFunction)psyco_isqlquote_getquoted,
89 METH_VARARGS, psyco_isqlquote_getquoted_doc},
90 {"getbinary", (PyCFunction)psyco_isqlquote_getbinary,
91 METH_VARARGS, psyco_isqlquote_getbinary_doc},
92 {"getbuffer", (PyCFunction)psyco_isqlquote_getbuffer,
93 METH_VARARGS, psyco_isqlquote_getbuffer_doc},
94 /* {"prepare", (PyCFunction)psyco_isqlquote_prepare,
95 METH_VARARGS, psyco_isqlquote_prepare_doc}, */
99 /* object member list */
101 static struct PyMemberDef isqlquoteObject_members[] = {
102 /* DBAPI-2.0 extensions (exception objects) */
103 {"_wrapped", T_OBJECT, offsetof(isqlquoteObject, wrapped), RO},
107 /* initialization and finalization methods */
110 isqlquote_setup(isqlquoteObject *self, PyObject *wrapped)
112 self->wrapped = wrapped;
119 isqlquote_dealloc(PyObject* obj)
121 isqlquoteObject *self = (isqlquoteObject *)obj;
123 Py_XDECREF(self->wrapped);
125 obj->ob_type->tp_free(obj);
129 isqlquote_init(PyObject *obj, PyObject *args, PyObject *kwds)
131 PyObject *wrapped = NULL;
133 if (!PyArg_ParseTuple(args, "O", &wrapped))
136 return isqlquote_setup((isqlquoteObject *)obj, wrapped);
140 isqlquote_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
142 return type->tp_alloc(type, 0);
146 isqlquote_del(PyObject* self)
154 #define isqlquoteType_doc \
155 "Abstract ISQLQuote protocol\n\n" \
156 "An object conform to this protocol should expose a ``getquoted()`` method\n" \
157 "returning the SQL representation of the object.\n\n"
159 PyTypeObject isqlquoteType = {
160 PyObject_HEAD_INIT(NULL)
162 "psycopg2._psycopg.ISQLQuote",
163 sizeof(isqlquoteObject),
165 isqlquote_dealloc, /*tp_dealloc*/
172 0, /*tp_as_sequence*/
182 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
183 isqlquoteType_doc, /*tp_doc*/
188 0, /*tp_richcompare*/
189 0, /*tp_weaklistoffset*/
194 /* Attribute descriptor and subclassing stuff */
196 isqlquoteObject_methods, /*tp_methods*/
197 isqlquoteObject_members, /*tp_members*/
206 isqlquote_init, /*tp_init*/
207 0, /*tp_alloc will be set to PyType_GenericAlloc in module init*/
208 isqlquote_new, /*tp_new*/
209 (freefunc)isqlquote_del, /*tp_free Low-level free-memory routine */
210 0, /*tp_is_gc For PyObject_IS_GC */
212 0, /*tp_mro method resolution order */