mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
Dropped XID_UNPARSED: we use format_id = None for PG xact ids.
This commit is contained in:
parent
978cac3a1b
commit
774be1d616
|
@ -31,9 +31,6 @@
|
||||||
|
|
||||||
#include "psycopg/config.h"
|
#include "psycopg/config.h"
|
||||||
|
|
||||||
/* value for the format_id when the xid doesn't follow the XA standard. */
|
|
||||||
#define XID_UNPARSED (-2)
|
|
||||||
|
|
||||||
extern HIDDEN PyTypeObject XidType;
|
extern HIDDEN PyTypeObject XidType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -303,25 +303,13 @@ _xid_encode64(PyObject *s)
|
||||||
{
|
{
|
||||||
PyObject *base64 = NULL;
|
PyObject *base64 = NULL;
|
||||||
PyObject *encode = NULL;
|
PyObject *encode = NULL;
|
||||||
PyObject *out = NULL;
|
|
||||||
PyObject *rv = NULL;
|
PyObject *rv = NULL;
|
||||||
|
|
||||||
if (!(base64 = PyImport_ImportModule("base64"))) { goto exit; }
|
if (!(base64 = PyImport_ImportModule("base64"))) { goto exit; }
|
||||||
if (!(encode = PyObject_GetAttrString(base64, "b64encode"))) { goto exit; }
|
if (!(encode = PyObject_GetAttrString(base64, "b64encode"))) { goto exit; }
|
||||||
if (!(out = PyObject_CallFunctionObjArgs(encode, s, NULL))) { goto exit; }
|
if (!(rv = PyObject_CallFunctionObjArgs(encode, s, NULL))) { goto exit; }
|
||||||
|
|
||||||
/* we are going to use PyString_AS_STRING on this so let's ensure it. */
|
|
||||||
if (!PyString_Check(out)) {
|
|
||||||
PyErr_SetString(PyExc_TypeError,
|
|
||||||
"base64.b64encode didn't return a string");
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
rv = out;
|
|
||||||
out = NULL;
|
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
Py_XDECREF(out);
|
|
||||||
Py_XDECREF(encode);
|
Py_XDECREF(encode);
|
||||||
Py_XDECREF(base64);
|
Py_XDECREF(base64);
|
||||||
|
|
||||||
|
@ -364,16 +352,15 @@ char *
|
||||||
xid_get_tid(XidObject *self)
|
xid_get_tid(XidObject *self)
|
||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
long format_id;
|
|
||||||
Py_ssize_t bufsize = 0;
|
Py_ssize_t bufsize = 0;
|
||||||
PyObject *egtrid = NULL;
|
PyObject *egtrid = NULL;
|
||||||
PyObject *ebqual = NULL;
|
PyObject *ebqual = NULL;
|
||||||
|
PyObject *format = NULL;
|
||||||
|
PyObject *args = NULL;
|
||||||
PyObject *tid = NULL;
|
PyObject *tid = NULL;
|
||||||
|
|
||||||
format_id = PyInt_AsLong(self->format_id);
|
if (Py_None == self->format_id) {
|
||||||
if (-1 == format_id && PyErr_Occurred()) { goto exit; }
|
/* Unparsed xid: return the gtrid. */
|
||||||
|
|
||||||
if (XID_UNPARSED == format_id) {
|
|
||||||
bufsize = 1 + PyString_Size(self->gtrid);
|
bufsize = 1 + PyString_Size(self->gtrid);
|
||||||
if (!(buf = (char *)PyMem_Malloc(bufsize))) {
|
if (!(buf = (char *)PyMem_Malloc(bufsize))) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
|
@ -382,23 +369,32 @@ xid_get_tid(XidObject *self)
|
||||||
strncpy(buf, PyString_AsString(self->gtrid), bufsize);
|
strncpy(buf, PyString_AsString(self->gtrid), bufsize);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
/* XA xid: mash together the components. */
|
||||||
if (!(egtrid = _xid_encode64(self->gtrid))) { goto exit; }
|
if (!(egtrid = _xid_encode64(self->gtrid))) { goto exit; }
|
||||||
if (!(ebqual = _xid_encode64(self->bqual))) { goto exit; }
|
if (!(ebqual = _xid_encode64(self->bqual))) { goto exit; }
|
||||||
if (!(tid = PyString_FromFormat("%ld_%s_%s",
|
|
||||||
format_id,
|
/* tid = "%d_%s_%s" % (format_id, egtrid, ebqual) */
|
||||||
PyString_AS_STRING(egtrid),
|
if (!(format = PyString_FromString("%d_%s_%s"))) { goto exit; }
|
||||||
PyString_AS_STRING(ebqual)))) {
|
|
||||||
goto exit;
|
if (!(args = PyTuple_New(3))) { goto exit; }
|
||||||
}
|
Py_INCREF(self->format_id);
|
||||||
|
PyTuple_SET_ITEM(args, 0, self->format_id);
|
||||||
|
PyTuple_SET_ITEM(args, 1, egtrid); egtrid = NULL;
|
||||||
|
PyTuple_SET_ITEM(args, 2, ebqual); ebqual = NULL;
|
||||||
|
|
||||||
|
if (!(tid = PyString_Format(format, args))) { goto exit; }
|
||||||
|
|
||||||
bufsize = 1 + PyString_Size(tid);
|
bufsize = 1 + PyString_Size(tid);
|
||||||
if (!(buf = (char *)PyMem_Malloc(bufsize))) {
|
if (!(buf = (char *)PyMem_Malloc(bufsize))) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
strncpy(buf, PyString_AS_STRING(tid), bufsize);
|
strncpy(buf, PyString_AsString(tid), bufsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
Py_XDECREF(args);
|
||||||
|
Py_XDECREF(format);
|
||||||
Py_XDECREF(egtrid);
|
Py_XDECREF(egtrid);
|
||||||
Py_XDECREF(ebqual);
|
Py_XDECREF(ebqual);
|
||||||
Py_XDECREF(tid);
|
Py_XDECREF(tid);
|
||||||
|
@ -505,29 +501,27 @@ static XidObject *
|
||||||
_xid_unparsed_from_string(PyObject *str) {
|
_xid_unparsed_from_string(PyObject *str) {
|
||||||
XidObject *xid = NULL;
|
XidObject *xid = NULL;
|
||||||
XidObject *rv = NULL;
|
XidObject *rv = NULL;
|
||||||
PyObject *format_id = NULL;
|
|
||||||
PyObject *tmp;
|
PyObject *tmp;
|
||||||
|
|
||||||
/* fake args to work around the checks performed by the xid init */
|
/* fake args to work around the checks performed by the xid init */
|
||||||
if (!(xid = (XidObject *)PyObject_CallFunction((PyObject *)&XidType,
|
if (!(xid = (XidObject *)PyObject_CallFunction((PyObject *)&XidType,
|
||||||
"iss", 0, "tmp", "tmp"))) {
|
"iss", 0, "", ""))) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set xid.gtrid */
|
/* set xid.gtrid = str */
|
||||||
tmp = xid->gtrid;
|
tmp = xid->gtrid;
|
||||||
Py_INCREF(str);
|
Py_INCREF(str);
|
||||||
xid->gtrid = str;
|
xid->gtrid = str;
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
|
|
||||||
/* set xid.format_id */
|
/* set xid.format_id = None */
|
||||||
if (!(format_id = PyInt_FromLong(XID_UNPARSED))) { goto exit; }
|
|
||||||
tmp = xid->format_id;
|
tmp = xid->format_id;
|
||||||
xid->format_id = format_id;
|
Py_INCREF(Py_None);
|
||||||
format_id = NULL;
|
xid->format_id = Py_None;
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
|
|
||||||
/* set xid.bqual */
|
/* set xid.bqual = None */
|
||||||
tmp = xid->bqual;
|
tmp = xid->bqual;
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
xid->bqual = Py_None;
|
xid->bqual = Py_None;
|
||||||
|
@ -538,7 +532,6 @@ _xid_unparsed_from_string(PyObject *str) {
|
||||||
xid = NULL;
|
xid = NULL;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
Py_XDECREF(format_id);
|
|
||||||
Py_XDECREF(xid);
|
Py_XDECREF(xid);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
|
|
|
@ -347,7 +347,7 @@ class ConnectionTwoPhaseTests(unittest.TestCase):
|
||||||
if xid.database == tests.dbname ]
|
if xid.database == tests.dbname ]
|
||||||
self.assertEqual(1, len(xids))
|
self.assertEqual(1, len(xids))
|
||||||
xid = xids[0]
|
xid = xids[0]
|
||||||
self.assertEqual(xid.format_id, -2)
|
self.assertEqual(xid.format_id, None)
|
||||||
self.assertEqual(xid.gtrid, tid)
|
self.assertEqual(xid.gtrid, tid)
|
||||||
self.assertEqual(xid.bqual, None)
|
self.assertEqual(xid.bqual, None)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user