/* utils.c - miscellaneous utility functions * */ #include #include #include "psycopg/config.h" #include "psycopg/psycopg.h" #include "psycopg/connection.h" #include "psycopg/pgtypes.h" #include "psycopg/pgversion.h" #include char * psycopg_escape_string(PyObject *obj, const char *from, Py_ssize_t len, char *to, Py_ssize_t *tolen) { Py_ssize_t ql; connectionObject *conn = (connectionObject*)obj; int eq = (conn && (conn->equote)) ? 1 : 0; if (len == 0) len = strlen(from); if (to == NULL) { to = (char *)PyMem_Malloc((len * 2 + 4) * sizeof(char)); if (to == NULL) return NULL; } #ifndef PSYCOPG_OWN_QUOTING { #if PG_MAJOR_VERSION > 8 || \ (PG_MAJOR_VERSION == 8 && PG_MINOR_VERSION > 1) || \ (PG_MAJOR_VERSION == 8 && PG_MINOR_VERSION == 1 && PG_PATCH_VERSION >= 4) int err; if (conn && conn->pgconn) ql = PQescapeStringConn(conn->pgconn, to+eq+1, from, len, &err); else #endif ql = PQescapeString(to+eq+1, from, len); } #else { int i, j; for (i=0, j=eq+1; i