Adding missing __conform__ methods before release.

This commit is contained in:
Federico Di Gregorio 2005-03-02 14:51:24 +00:00
parent e8e6c0ada3
commit e816aa07b6
4 changed files with 21 additions and 14 deletions

View File

@ -1,6 +1,7 @@
2005-03-02 Federico Di Gregorio <fog@debian.org>
* Release 1.99.12.
* psycopg/adapter_binary.c (binary_conform): started to add
__conform__ to all adapters.
* psycopg/adapter_qstring.c (qstring_quote): we now use
PyString_AsStringAndSize() instead of strlen() that would stop at

View File

@ -46,9 +46,9 @@ data2 = {'id':2, 'name':'whereareyou.jpg',
'img':buffer(open('whereareyou.jpg').read())}
curs.execute("""INSERT INTO test_binary
VALUES (%(id)d, %(name)s, %(img)s)""", data1)
VALUES (%(id)s, %(name)s, %(img)s)""", data1)
curs.execute("""INSERT INTO test_binary
VALUES (%(id)d, %(name)s, %(img)s)""", data2)
VALUES (%(id)s, %(name)s, %(img)s)""", data2)
# now we try to extract the images as simple text strings

View File

@ -15,7 +15,7 @@ intrusive for your classes (don't want inheritance from an 'Item' or
from datetime import datetime
import psycopg
from psycopg.extensions import adapters, adapt
from psycopg.extensions import adapt, register_adapter
try: sorted()
except NameError:
@ -28,7 +28,7 @@ except NameError:
# its job on that instance
class ObjectMapper(object):
def __init__(self, orig):
def __init__(self, orig, curs=None):
self.orig = orig
self.tmp = {}
self.items, self.fields = self._gatherState()
@ -81,7 +81,8 @@ class Order(object):
self.order_id = self.id
Order.id = Order.id + 1
adapters.update({Album: ObjectMapper, Order: ObjectMapper})
register_adapter(Album, ObjectMapper)
register_adapter(Order, ObjectMapper)
# Describe what is needed to save on each object
# This is actually just configuration, you can use xml with a parser if you

View File

@ -31,6 +31,7 @@
#include "psycopg/python.h"
#include "psycopg/psycopg.h"
#include "psycopg/adapter_binary.h"
#include "psycopg/microprotocols_proto.h"
/** the quoting code */
@ -165,14 +166,19 @@ binary_getquoted(binaryObject *self, PyObject *args)
}
PyObject *
binary_prepare(binaryObject *self, PyObject *args)
binary_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 Binary object **/
@ -190,8 +196,7 @@ static struct PyMemberDef binaryObject_members[] = {
static PyMethodDef binaryObject_methods[] = {
{"getquoted", (PyCFunction)binary_getquoted, METH_VARARGS,
"getquoted() -> wrapped object value as SQL-quoted binary string"},
/* {"prepare", (PyCFunction)binary_prepare, METH_VARARGS,
"prepare(conn) -> currently does nothing"},*/
{"__conform__", (PyCFunction)binary_conform, METH_VARARGS, NULL},
{NULL} /* Sentinel */
};