mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
Proper type check in prepare() methods for list, binary, qstring
This commit is contained in:
parent
76cc838a93
commit
0e832b97ea
|
@ -149,16 +149,14 @@ binary_str(binaryObject *self)
|
|||
static PyObject *
|
||||
binary_prepare(binaryObject *self, PyObject *args)
|
||||
{
|
||||
connectionObject *conn;
|
||||
PyObject *conn;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &conn))
|
||||
if (!PyArg_ParseTuple(args, "O!", &connectionType, &conn))
|
||||
return NULL;
|
||||
|
||||
Py_XDECREF(self->conn);
|
||||
if (conn) {
|
||||
self->conn = (PyObject*)conn;
|
||||
Py_INCREF(self->conn);
|
||||
}
|
||||
self->conn = conn;
|
||||
Py_INCREF(self->conn);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
|
|
|
@ -98,9 +98,9 @@ list_getquoted(listObject *self, PyObject *args)
|
|||
static PyObject *
|
||||
list_prepare(listObject *self, PyObject *args)
|
||||
{
|
||||
connectionObject *conn;
|
||||
PyObject *conn;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &conn))
|
||||
if (!PyArg_ParseTuple(args, "O!", &connectionType, &conn))
|
||||
return NULL;
|
||||
|
||||
/* note that we don't copy the encoding from the connection, but take a
|
||||
|
@ -109,7 +109,7 @@ list_prepare(listObject *self, PyObject *args)
|
|||
work even without a connection to the backend. */
|
||||
Py_CLEAR(self->connection);
|
||||
Py_INCREF(conn);
|
||||
self->connection = (PyObject*)conn;
|
||||
self->connection = conn;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
|
|
|
@ -124,24 +124,22 @@ qstring_str(qstringObject *self)
|
|||
static PyObject *
|
||||
qstring_prepare(qstringObject *self, PyObject *args)
|
||||
{
|
||||
connectionObject *conn;
|
||||
PyObject *conn;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &conn))
|
||||
if (!PyArg_ParseTuple(args, "O!", &connectionType, &conn))
|
||||
return NULL;
|
||||
|
||||
/* we bother copying the encoding only if the wrapped string is unicode,
|
||||
we don't need the encoding if that's not the case */
|
||||
if (PyUnicode_Check(self->wrapped)) {
|
||||
if (self->encoding) free(self->encoding);
|
||||
self->encoding = strdup(conn->codec);
|
||||
Dprintf("qstring_prepare: set encoding to %s", conn->codec);
|
||||
self->encoding = strdup(((connectionObject *)conn)->codec);
|
||||
Dprintf("qstring_prepare: set encoding to %s", self->encoding);
|
||||
}
|
||||
|
||||
Py_CLEAR(self->conn);
|
||||
if (conn) {
|
||||
Py_INCREF(conn);
|
||||
self->conn = (PyObject*)conn;
|
||||
}
|
||||
Py_INCREF(conn);
|
||||
self->conn = conn;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
|
|
Loading…
Reference in New Issue
Block a user