summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-10-08 12:27:47 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-10-08 12:27:47 +0100
commit6e71b3db057eb4a18d5ee5c112a2ab50e0a7c5ab (patch)
tree644b791a4b5b6ab58db70025cea2b85aeb6d8429
parentbaf65a0ddae18fc89af36bc1bdf44c41686dee1b (diff)
downloadpsycopg2-6e71b3db057eb4a18d5ee5c112a2ab50e0a7c5ab.tar.gz
Dropped PSYCOPG_OWN_QUOTING.
It was deprecated for version 2.1. There are bugs to be fixed made more complex by its presence and it doesn't keep into account PostgreSQL 9.0 new binary format. Time to go!
-rw-r--r--ChangeLog2
-rw-r--r--psycopg/adapter_binary.c77
-rw-r--r--psycopg/connection_int.c6
-rw-r--r--psycopg/typecast_binary.c49
-rw-r--r--psycopg/utils.c32
-rw-r--r--setup.cfg1
6 files changed, 2 insertions, 165 deletions
diff --git a/ChangeLog b/ChangeLog
index 5c5ef44..e5c8550 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
2010-10-08 Daniele Varrazzo <daniele.varrazzo@gmail.com>
+ * dropped PSYCOPG_OWN_QUOTING.
+
* psycopg/connection_int.c: Fixed access to freed memory in
conn_get_isolation_level(). Bug reported by Anton Kovalev.
diff --git a/psycopg/adapter_binary.c b/psycopg/adapter_binary.c
index 36372bc..a1dfba5 100644
--- a/psycopg/adapter_binary.c
+++ b/psycopg/adapter_binary.c
@@ -41,7 +41,6 @@
/** the quoting code */
-#ifndef PSYCOPG_OWN_QUOTING
static unsigned char *
binary_escape(unsigned char *from, size_t from_length,
size_t *to_length, PGconn *conn)
@@ -53,82 +52,6 @@ binary_escape(unsigned char *from, size_t from_length,
#endif
return PQescapeBytea(from, from_length, to_length);
}
-#else
-static unsigned char *
-binary_escape(unsigned char *from, size_t from_length,
- size_t *to_length, PGconn *conn)
-{
- unsigned char *quoted, *chptr, *newptr;
- size_t i, space, new_space;
-
- space = from_length + 2;
-
- Py_BEGIN_ALLOW_THREADS;
-
- quoted = (unsigned char*)calloc(space, sizeof(char));
- if (quoted == NULL) return NULL;
-
- chptr = quoted;
-
- for (i = 0; i < from_length; i++) {
- if (chptr - quoted > space - 6) {
- new_space = space * ((space) / (i + 1)) + 2 + 6;
- if (new_space - space < 1024) space += 1024;
- else space = new_space;
- newptr = (unsigned char *)realloc(quoted, space);
- if (newptr == NULL) {
- free(quoted);
- return NULL;
- }
- /* chptr has to be moved to the new location*/
- chptr = newptr + (chptr - quoted);
- quoted = newptr;
- Dprintf("binary_escape: reallocated %i bytes at %p", space,quoted);
- }
- if (from[i]) {
- if (from[i] >= ' ' && from[i] <= '~') {
- if (from[i] == '\'') {
- *chptr = '\'';
- chptr++;
- *chptr = '\'';
- chptr++;
- }
- else if (from[i] == '\\') {
- memcpy(chptr, "\\\\\\\\", 4);
- chptr += 4;
- }
- else {
- /* leave it as it is if ascii printable */
- *chptr = from[i];
- chptr++;
- }
- }
- else {
- unsigned char c;
-
- /* escape to octal notation \nnn */
- *chptr++ = '\\';
- *chptr++ = '\\';
- c = from[i];
- *chptr = ((c >> 6) & 0x07) + 0x30; chptr++;
- *chptr = ((c >> 3) & 0x07) + 0x30; chptr++;
- *chptr = ( c & 0x07) + 0x30; chptr++;
- }
- }
- else {
- /* escape null as \\000 */
- memcpy(chptr, "\\\\000", 5);
- chptr += 5;
- }
- }
- *chptr = '\0';
-
- Py_END_ALLOW_THREADS;
-
- *to_length = chptr - quoted + 1;
- return quoted;
-}
-#endif
/* binary_quote - do the quote process on plain and unicode strings */
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c
index 85d47d5..a69776f 100644
--- a/psycopg/connection_int.c
+++ b/psycopg/connection_int.c
@@ -174,18 +174,12 @@ conn_get_standard_conforming_strings(PGconn *pgconn)
* not escaped strings (e.g. '\001' -> "\001"), relying on the
* fact that the '\' will pass untouched the string parser.
* In this case the E'' quotes are NOT to be used.
- *
- * The PSYCOPG_OWN_QUOTING implementation always returns escaped strings.
*/
scs = PQparameterStatus(pgconn, "standard_conforming_strings");
Dprintf("conn_connect: server standard_conforming_strings parameter: %s",
scs ? scs : "unavailable");
-#ifndef PSYCOPG_OWN_QUOTING
equote = (scs && (0 == strcmp("off", scs)));
-#else
- equote = (scs != NULL);
-#endif
Dprintf("conn_connect: server requires E'' quotes: %s",
equote ? "YES" : "NO");
diff --git a/psycopg/typecast_binary.c b/psycopg/typecast_binary.c
index 0c68dc8..e2efe13 100644
--- a/psycopg/typecast_binary.c
+++ b/psycopg/typecast_binary.c
@@ -110,55 +110,6 @@ PyTypeObject chunkType = {
chunk_doc /* tp_doc */
};
-/* the function typecast_BINARY_cast_unescape is used when libpq does not
- provide PQunescapeBytea: it convert all the \xxx octal sequences to the
- proper byte value */
-
-#ifdef PSYCOPG_OWN_QUOTING
-static unsigned char *
-typecast_BINARY_cast_unescape(unsigned char *str, size_t *to_length)
-{
- char *dstptr, *dststr;
- int len, i;
-
- len = strlen(str);
- dststr = (char*)calloc(len, sizeof(char));
- dstptr = dststr;
-
- if (dststr == NULL) return NULL;
-
- Py_BEGIN_ALLOW_THREADS;
-
- for (i = 0; i < len; i++) {
- if (str[i] == '\\') {
- if ( ++i < len) {
- if (str[i] == '\\') {
- *dstptr = '\\';
- }
- else {
- *dstptr = 0;
- *dstptr |= (str[i++] & 7) << 6;
- *dstptr |= (str[i++] & 7) << 3;
- *dstptr |= (str[i] & 7);
- }
- }
- }
- else {
- *dstptr = str[i];
- }
- dstptr++;
- }
-
- Py_END_ALLOW_THREADS;
-
- *to_length = (size_t)(dstptr-dststr);
-
- return dststr;
-}
-
-#define PQunescapeBytea typecast_BINARY_cast_unescape
-#endif
-
static PyObject *
typecast_BINARY_cast(const char *s, Py_ssize_t l, PyObject *curs)
{
diff --git a/psycopg/utils.c b/psycopg/utils.c
index d0b7929..cb8b6c7 100644
--- a/psycopg/utils.c
+++ b/psycopg/utils.c
@@ -50,7 +50,6 @@ psycopg_escape_string(PyObject *obj, const char *from, Py_ssize_t len,
return NULL;
}
- #ifndef PSYCOPG_OWN_QUOTING
{
#if PG_VERSION_HEX >= 0x080104
int err;
@@ -60,37 +59,6 @@ psycopg_escape_string(PyObject *obj, const char *from, Py_ssize_t len,
#endif
ql = PQescapeString(to+eq+1, from, len);
}
- #else
- {
- int i, j;
-
- for (i=0, j=eq+1; i<len; i++) {
- switch(from[i]) {
-
- case '\'':
- to[j++] = '\'';
- to[j++] = '\'';
- break;
-
- case '\\':
- to[j++] = '\\';
- to[j++] = '\\';
- break;
-
- case '\0':
- /* do nothing, embedded \0 are discarded */
- break;
-
- default:
- to[j++] = from[i];
- }
- }
- to[j] = '\0';
-
- Dprintf("qstring_quote: to = %s", to);
- ql = strlen(to);
- }
- #endif
if (eq)
to[0] = 'E';
diff --git a/setup.cfg b/setup.cfg
index e660c38..1e13d4d 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -6,7 +6,6 @@ define=PSYCOPG_EXTENSIONS,PSYCOPG_NEW_BOOLEAN,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3
# HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.4
# HAVE_PQPROTOCOL3 should be defined on PostgreSQL >= 7.4
# PSYCOPG_DEBUG can be added to enable verbose debug information
-# PSYCOPG_OWN_QUOTING can be added, but it is deprecated (will go away in 2.1)
# PSYCOPG_NEW_BOOLEAN to format booleans as true/false vs 't'/'f'
# Set to 1 to use Python datatime objects for default date/time representation.