Static-type psycopg_escape_string connection parameter

This commit is contained in:
Daniele Varrazzo 2013-04-05 00:07:36 +01:00
parent 736a78f3f6
commit 6bc4b23af5
6 changed files with 13 additions and 12 deletions

View File

@ -79,7 +79,7 @@ qstring_quote(qstringObject *self)
/* encode the string into buffer */ /* encode the string into buffer */
Bytes_AsStringAndSize(str, &s, &len); Bytes_AsStringAndSize(str, &s, &len);
if (!(buffer = psycopg_escape_string((PyObject *)self->conn, s, len, NULL, &qlen))) { if (!(buffer = psycopg_escape_string(self->conn, s, len, NULL, &qlen))) {
goto exit; goto exit;
} }

View File

@ -74,7 +74,8 @@ struct connectionObject_notice {
const char *message; const char *message;
}; };
typedef struct { /* the typedef is forward-declared in psycopg.h */
struct connectionObject {
PyObject_HEAD PyObject_HEAD
pthread_mutex_t lock; /* the global connection lock */ pthread_mutex_t lock; /* the global connection lock */
@ -120,7 +121,7 @@ typedef struct {
int autocommit; int autocommit;
} connectionObject; };
/* map isolation level values into a numeric const */ /* map isolation level values into a numeric const */
typedef struct { typedef struct {

View File

@ -1374,12 +1374,12 @@ psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
goto exit; goto exit;
if (!(quoted_delimiter = psycopg_escape_string( if (!(quoted_delimiter = psycopg_escape_string(
(PyObject*)self->conn, sep, 0, NULL, NULL))) { self->conn, sep, 0, NULL, NULL))) {
goto exit; goto exit;
} }
if (!(quoted_null = psycopg_escape_string( if (!(quoted_null = psycopg_escape_string(
(PyObject*)self->conn, null, 0, NULL, NULL))) { self->conn, null, 0, NULL, NULL))) {
goto exit; goto exit;
} }
@ -1468,12 +1468,12 @@ psyco_curs_copy_to(cursorObject *self, PyObject *args, PyObject *kwargs)
goto exit; goto exit;
if (!(quoted_delimiter = psycopg_escape_string( if (!(quoted_delimiter = psycopg_escape_string(
(PyObject*)self->conn, sep, 0, NULL, NULL))) { self->conn, sep, 0, NULL, NULL))) {
goto exit; goto exit;
} }
if (!(quoted_null = psycopg_escape_string( if (!(quoted_null = psycopg_escape_string(
(PyObject*)self->conn, null, 0, NULL, NULL))) { self->conn, null, 0, NULL, NULL))) {
goto exit; goto exit;
} }

View File

@ -750,7 +750,7 @@ pq_tpc_command_locked(connectionObject *conn, const char *cmd, const char *tid,
PyEval_RestoreThread(*tstate); PyEval_RestoreThread(*tstate);
/* convert the xid into the postgres transaction_id and quote it. */ /* convert the xid into the postgres transaction_id and quote it. */
if (!(etid = psycopg_escape_string((PyObject *)conn, tid, 0, NULL, NULL))) if (!(etid = psycopg_escape_string(conn, tid, 0, NULL, NULL)))
{ goto exit; } { goto exit; }
/* prepare the command to the server */ /* prepare the command to the server */

View File

@ -116,13 +116,14 @@ typedef struct {
/* the Decimal type, used by the DECIMAL typecaster */ /* the Decimal type, used by the DECIMAL typecaster */
HIDDEN PyObject *psyco_GetDecimalType(void); HIDDEN PyObject *psyco_GetDecimalType(void);
/* forward declaration */ /* forward declarations */
typedef struct cursorObject cursorObject; typedef struct cursorObject cursorObject;
typedef struct connectionObject connectionObject;
/* some utility functions */ /* some utility functions */
RAISES HIDDEN PyObject *psyco_set_error(PyObject *exc, cursorObject *curs, const char *msg); RAISES HIDDEN PyObject *psyco_set_error(PyObject *exc, cursorObject *curs, const char *msg);
HIDDEN char *psycopg_escape_string(PyObject *conn, HIDDEN char *psycopg_escape_string(connectionObject *conn,
const char *from, Py_ssize_t len, char *to, Py_ssize_t *tolen); const char *from, Py_ssize_t len, char *to, Py_ssize_t *tolen);
HIDDEN char *psycopg_escape_identifier_easy(const char *from, Py_ssize_t len); HIDDEN char *psycopg_escape_identifier_easy(const char *from, Py_ssize_t len);
HIDDEN int psycopg_strdup(char **to, const char *from, Py_ssize_t len); HIDDEN int psycopg_strdup(char **to, const char *from, Py_ssize_t len);

View File

@ -44,11 +44,10 @@
* including quotes. * including quotes.
*/ */
char * char *
psycopg_escape_string(PyObject *obj, const char *from, Py_ssize_t len, psycopg_escape_string(connectionObject *conn, const char *from, Py_ssize_t len,
char *to, Py_ssize_t *tolen) char *to, Py_ssize_t *tolen)
{ {
Py_ssize_t ql; Py_ssize_t ql;
connectionObject *conn = (connectionObject*)obj;
int eq = (conn && (conn->equote)) ? 1 : 0; int eq = (conn && (conn->equote)) ? 1 : 0;
if (len == 0) if (len == 0)