mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 21:00:33 +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 *
|
static PyObject *
|
||||||
binary_prepare(binaryObject *self, PyObject *args)
|
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;
|
return NULL;
|
||||||
|
|
||||||
Py_XDECREF(self->conn);
|
Py_XDECREF(self->conn);
|
||||||
if (conn) {
|
self->conn = conn;
|
||||||
self->conn = (PyObject*)conn;
|
Py_INCREF(self->conn);
|
||||||
Py_INCREF(self->conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
|
|
|
@ -98,9 +98,9 @@ list_getquoted(listObject *self, PyObject *args)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
list_prepare(listObject *self, PyObject *args)
|
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;
|
return NULL;
|
||||||
|
|
||||||
/* note that we don't copy the encoding from the connection, but take a
|
/* 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. */
|
work even without a connection to the backend. */
|
||||||
Py_CLEAR(self->connection);
|
Py_CLEAR(self->connection);
|
||||||
Py_INCREF(conn);
|
Py_INCREF(conn);
|
||||||
self->connection = (PyObject*)conn;
|
self->connection = conn;
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
|
|
|
@ -124,24 +124,22 @@ qstring_str(qstringObject *self)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
qstring_prepare(qstringObject *self, PyObject *args)
|
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;
|
return NULL;
|
||||||
|
|
||||||
/* we bother copying the encoding only if the wrapped string is unicode,
|
/* we bother copying the encoding only if the wrapped string is unicode,
|
||||||
we don't need the encoding if that's not the case */
|
we don't need the encoding if that's not the case */
|
||||||
if (PyUnicode_Check(self->wrapped)) {
|
if (PyUnicode_Check(self->wrapped)) {
|
||||||
if (self->encoding) free(self->encoding);
|
if (self->encoding) free(self->encoding);
|
||||||
self->encoding = strdup(conn->codec);
|
self->encoding = strdup(((connectionObject *)conn)->codec);
|
||||||
Dprintf("qstring_prepare: set encoding to %s", conn->codec);
|
Dprintf("qstring_prepare: set encoding to %s", self->encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_CLEAR(self->conn);
|
Py_CLEAR(self->conn);
|
||||||
if (conn) {
|
Py_INCREF(conn);
|
||||||
Py_INCREF(conn);
|
self->conn = conn;
|
||||||
self->conn = (PyObject*)conn;
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user