mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 17:06:33 +03:00
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!
This commit is contained in:
parent
baf65a0dda
commit
6e71b3db05
|
@ -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.
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user