fixup for 'standard_conforming_strings'

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@25413 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2007-08-23 17:05:30 +00:00
parent bdbbcdda11
commit 61dcdc8acf

View file

@ -185,11 +185,10 @@ connectQuote(NSString *str)
} }
else else
{ {
#ifdef HAVE_PQESCAPESTRINGCONN const char *p;
char buf[8];
int err;
if (PQescapeStringConn(connection, buf, "\\", 1, &err) == 1) p = PQparameterStatus(connection, "standard_conforming_strings");
if (p != 0 && strcmp(p, "on") == 0)
{ {
standardEscaping = YES; standardEscaping = YES;
} }
@ -197,7 +196,7 @@ connectQuote(NSString *str)
{ {
standardEscaping = NO; standardEscaping = NO;
} }
#endif
connected = YES; connected = YES;
if ([self debugging] > 0) if ([self debugging] > 0)
{ {
@ -544,40 +543,72 @@ static unsigned int trim(char *str)
unsigned i; unsigned i;
ptr[length++] = '\''; ptr[length++] = '\'';
for (i = 0; i < sLen; i++) if (YES == standardEscaping)
{ {
unsigned char c = src[i]; for (i = 0; i < sLen; i++)
{
unsigned char c = src[i];
if (c < 32 || c > 126) if (c < 32 || c > 126)
{ {
ptr[length] = '\\'; ptr[length] = '\\';
ptr[length+1] = '\\'; ptr[length + 3] = (c & 7) + '0';
ptr[length + 4] = (c & 7) + '0'; c >>= 3;
c >>= 3; ptr[length + 2] = (c & 7) + '0';
ptr[length + 3] = (c & 7) + '0'; c >>= 3;
c >>= 3; ptr[length + 1] = (c & 7) + '0';
ptr[length + 2] = (c & 7) + '0'; length += 4;
length += 5; }
} else if (c == '\\')
else if (c == '\\') {
{ ptr[length++] = '\\';
if (standardEscaping == NO) ptr[length++] = '\\';
{ }
ptr[length++] = '\\'; else if (c == '\'')
ptr[length++] = '\\'; {
} ptr[length++] = '\'';
ptr[length++] = '\\'; ptr[length++] = '\'';
ptr[length++] = '\\'; }
} else
else if (c == '\'') {
{ ptr[length++] = c;
ptr[length++] = '\''; }
ptr[length++] = '\''; }
} }
else else
{ {
ptr[length++] = c; for (i = 0; i < sLen; i++)
} {
unsigned char c = src[i];
if (c < 32 || c > 126)
{
ptr[length] = '\\';
ptr[length+1] = '\\';
ptr[length + 4] = (c & 7) + '0';
c >>= 3;
ptr[length + 3] = (c & 7) + '0';
c >>= 3;
ptr[length + 2] = (c & 7) + '0';
length += 5;
}
else if (c == '\\')
{
ptr[length++] = '\\';
ptr[length++] = '\\';
ptr[length++] = '\\';
ptr[length++] = '\\';
}
else if (c == '\'')
{
ptr[length++] = '\'';
ptr[length++] = '\'';
}
else
{
ptr[length++] = c;
}
}
} }
ptr[length++] = '\''; ptr[length++] = '\'';
return length; return length;
@ -590,26 +621,45 @@ static unsigned int trim(char *str)
unsigned int length = sLen + 2; unsigned int length = sLen + 2;
unsigned int i; unsigned int i;
for (i = 0; i < sLen; i++) if (YES == standardEscaping)
{ {
unsigned char c = src[i]; for (i = 0; i < sLen; i++)
{
unsigned char c = src[i];
if (c < 32 || c > 126) if (c < 32 || c > 126)
{ {
length += 4; length += 3;
} }
else if (c == '\\') else if (c == '\\')
{ {
if (standardEscaping == NO) length += 1;
{ }
length += 2; else if (c == '\'')
} {
length += 1; length += 1;
} }
else if (c == '\'') }
{ }
length += 1; else
} {
for (i = 0; i < sLen; i++)
{
unsigned char c = src[i];
if (c < 32 || c > 126)
{
length += 4;
}
else if (c == '\\')
{
length += 3;
}
else if (c == '\'')
{
length += 1;
}
}
} }
return length; return length;
} }