[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fix GDL2, PostgreSQLExpression (+formatValue:forAttribute:): writing of
From: |
Georg Fleischmann |
Subject: |
Fix GDL2, PostgreSQLExpression (+formatValue:forAttribute:): writing of escaped strings |
Date: |
Thu, 3 Apr 2008 13:09:41 +0800 |
Hi,
here is a fix for GDL2, PostgreSQLExpression.m
(+formatValue:forAttribute:).
The patch allows writing the quote character "'" and encoded
characters to PostgreSQL 8.3. This has been tested on Mac OS 10.4, so
far.
The changes in detail:
1. \' has to be '' to work without Warning message from the sql server
WARNING: nonstandard use of \' in a string literal
LINE 14: ', 'User\'s Guide', ...
^
HINT: Use '' to write quotes in strings, or use the escape
string syntax (E'...').
2. the cString copy (tempString) of string doesn't work with encodings,
because the cString has different length and character positions
as the NSString.
Additionally on Mac OS, the cString is not always save from being
updated when
changing the corresponding NSString!
The suggested solution simply uses [NSString -characterAtIndex:]
without the cString copy.
Best wishes,
Georg Fleischmann
vhf interservice GmbH
*** EOAdaptors/PostgreSQLAdaptor/PostgreSQLExpression.m.old Sun Dec
31 09:32:05 2006
--- EOAdaptors/PostgreSQLAdaptor/PostgreSQLExpression.m Mon Mar 31
14:21:18 2008
***************
*** 97,103 ****
NSString *formatted = nil;
NSString *externalType;
NSMutableString *string;
- const char *tempString;
int i, dif;
EOFLOGObjectFnStart();
--- 97,102 ----
***************
*** 342,358 ****
EOFLOGObjectLevelArgs(@"EOSQLExpression", @"string %p='%@'",
string, string);
! length=[string cStringLength];
! tempString = [string cString];
! EOFLOGObjectLevelArgs(@"EOSQLExpression", @"string '%@'
tempString=%s",
! string, tempString);
for (i = 0, dif = 0; i < length; i++)
{
! switch (tempString[i])
{
- case '\\':
case '\'':
[string insertString: @"\\" atIndex: dif + i];
dif++;
break;
--- 341,358 ----
EOFLOGObjectLevelArgs(@"EOSQLExpression", @"string %p='%@'",
string, string);
! length=[string length];
! EOFLOGObjectLevelArgs(@"EOSQLExpression", @"string '%@'",
string);
for (i = 0, dif = 0; i < length; i++)
{
! switch ([string characterAtIndex:dif+i])
{
case '\'':
+ [string insertString: @"'" atIndex: dif + i];
+ dif++;
+ break;
+ case '\\':
[string insertString: @"\\" atIndex: dif + i];
dif++;
break;
***************
*** 364,371 ****
break;
}
}
! EOFLOGObjectLevelArgs(@"EOSQLExpression", @"string '%@'
tempString=%s",
! string, tempString);
formatted = [NSString stringWithFormat: @"'%@'", string];
--- 364,370 ----
break;
}
}
! EOFLOGObjectLevelArgs(@"EOSQLExpression", @"string '%@'",
string);
formatted = [NSString stringWithFormat: @"'%@'", string];
- Fix GDL2, PostgreSQLExpression (+formatValue:forAttribute:): writing of escaped strings,
Georg Fleischmann <=