summaryrefslogtreecommitdiff
path: root/psycopg/adapter_binary.c
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 /psycopg/adapter_binary.c
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!
Diffstat (limited to 'psycopg/adapter_binary.c')
-rw-r--r--psycopg/adapter_binary.c77
1 files changed, 0 insertions, 77 deletions
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 */