mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
implement sequence behaviour, as required for transaction IDs.
By James Henstridge on 2008-07-24. Merged from lp:~jamesh/psycopg/two-phase-commit/revision/357
This commit is contained in:
parent
0021e56d80
commit
22aea9114b
|
@ -12,6 +12,11 @@
|
||||||
|
|
||||||
* Merged James Henstridge work on two-phase commit support.
|
* Merged James Henstridge work on two-phase commit support.
|
||||||
|
|
||||||
|
2008-07-24 James Henstridge <james@jamesh.id.au>
|
||||||
|
|
||||||
|
* psycopg/xid_type.c (xid_len, xid_getitem): implement sequence
|
||||||
|
behaviour, as required for transaction IDs.
|
||||||
|
|
||||||
2008-07-23 James Henstridge <james@jamesh.id.au>
|
2008-07-23 James Henstridge <james@jamesh.id.au>
|
||||||
|
|
||||||
* psycopg/connection_type.c (psyco_conn_xid): add a
|
* psycopg/connection_type.c (psyco_conn_xid): add a
|
||||||
|
|
|
@ -41,6 +41,8 @@
|
||||||
#define PY_FORMAT_SIZE_T ""
|
#define PY_FORMAT_SIZE_T ""
|
||||||
#define PyInt_FromSsize_t(x) PyInt_FromLong((x))
|
#define PyInt_FromSsize_t(x) PyInt_FromLong((x))
|
||||||
|
|
||||||
|
#define lenfunc inquiry
|
||||||
|
#define ssizeargfunc intargfunc
|
||||||
#define readbufferproc getreadbufferproc
|
#define readbufferproc getreadbufferproc
|
||||||
#define writebufferproc getwritebufferproc
|
#define writebufferproc getwritebufferproc
|
||||||
#define segcountproc getsegcountproc
|
#define segcountproc getsegcountproc
|
||||||
|
|
|
@ -184,6 +184,47 @@ xid_repr(XidObject *self)
|
||||||
self->pg_xact_id ? self->pg_xact_id : "(null)");
|
self->pg_xact_id ? self->pg_xact_id : "(null)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Py_ssize_t
|
||||||
|
xid_len(XidObject *self)
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
xid_getitem(XidObject *self, Py_ssize_t item)
|
||||||
|
{
|
||||||
|
if (item < 0)
|
||||||
|
item += 3;
|
||||||
|
|
||||||
|
switch (item) {
|
||||||
|
case 0:
|
||||||
|
Py_INCREF(self->format_id);
|
||||||
|
return self->format_id;
|
||||||
|
case 1:
|
||||||
|
Py_INCREF(self->gtrid);
|
||||||
|
return self->gtrid;
|
||||||
|
case 2:
|
||||||
|
Py_INCREF(self->bqual);
|
||||||
|
return self->bqual;
|
||||||
|
default:
|
||||||
|
PyErr_SetString(PyExc_IndexError, "index out of range");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static PySequenceMethods xid_sequence = {
|
||||||
|
(lenfunc)xid_len, /* sq_length */
|
||||||
|
0, /* sq_concat */
|
||||||
|
0, /* sq_repeat */
|
||||||
|
(ssizeargfunc)xid_getitem, /* sq_item */
|
||||||
|
0, /* sq_slice */
|
||||||
|
0, /* sq_ass_item */
|
||||||
|
0, /* sq_ass_slice */
|
||||||
|
0, /* sq_contains */
|
||||||
|
0, /* sq_inplace_concat */
|
||||||
|
0, /* sq_inplace_repeat */
|
||||||
|
};
|
||||||
|
|
||||||
static const char xid_doc[] =
|
static const char xid_doc[] =
|
||||||
"A transaction identifier used for two phase commit.";
|
"A transaction identifier used for two phase commit.";
|
||||||
|
|
||||||
|
@ -203,7 +244,7 @@ PyTypeObject XidType = {
|
||||||
|
|
||||||
(reprfunc)xid_repr, /*tp_repr*/
|
(reprfunc)xid_repr, /*tp_repr*/
|
||||||
0, /*tp_as_number*/
|
0, /*tp_as_number*/
|
||||||
0, /*tp_as_sequence*/
|
&xid_sequence, /*tp_as_sequence*/
|
||||||
0, /*tp_as_mapping*/
|
0, /*tp_as_mapping*/
|
||||||
0, /*tp_hash */
|
0, /*tp_hash */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user