mirror of
https://github.com/gnustep/libs-sqlclient.git
synced 2025-02-22 19:31:36 +00:00
Added quotef:,...
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@20208 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ddb21da9ed
commit
85ff6940cf
3 changed files with 46 additions and 16 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Thu Oct 08 10:30:00 2004 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* SQLClient.[hm]: Add ([-quotef:,...]) to perform efficient quoting
|
||||||
|
of a string produced using printf style format and arguments.
|
||||||
|
|
||||||
Thu Oct 07 10:30:00 2004 Richard Frith-Macdonald <rfm@gnu.org>
|
Thu Oct 07 10:30:00 2004 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* SQLClient.[hm]: Optimise timing operations somewhat.
|
* SQLClient.[hm]: Optimise timing operations somewhat.
|
||||||
|
|
|
@ -537,6 +537,11 @@ extern NSTimeInterval SQLClientTimeNow();
|
||||||
*/
|
*/
|
||||||
- (NSString*) quote: (id)obj;
|
- (NSString*) quote: (id)obj;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produce a quoted string from the supplied arguments (printf style).
|
||||||
|
*/
|
||||||
|
- (NSString*) quotef: (NSString*)fmt, ...;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a 'C' string to a string suitable for use in an SQL query.
|
* Convert a 'C' string to a string suitable for use in an SQL query.
|
||||||
*/
|
*/
|
||||||
|
|
52
SQLClient.m
52
SQLClient.m
|
@ -737,10 +737,29 @@ static unsigned int maxConnections = 8;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*) quote: (id)obj
|
static void quoteString(NSMutableString *s)
|
||||||
{
|
{
|
||||||
NSRange r;
|
NSRange r;
|
||||||
|
|
||||||
|
/* Escape the string. */
|
||||||
|
r = [s rangeOfString: @"\\"];
|
||||||
|
if (r.length != 0)
|
||||||
|
{
|
||||||
|
[s replaceString: @"\\" withString: @"\\\\"];
|
||||||
|
}
|
||||||
|
r = [s rangeOfString: @"'"];
|
||||||
|
if (r.length != 0)
|
||||||
|
{
|
||||||
|
[s replaceString: @"'" withString: @"\\'"];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add quoting around it. */
|
||||||
|
[s replaceCharactersInRange: NSMakeRange(0, 0) withString: @"'"];
|
||||||
|
[s appendString: @"'"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString*) quote: (id)obj
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* For a nil object, we return NULL.
|
* For a nil object, we return NULL.
|
||||||
*/
|
*/
|
||||||
|
@ -795,25 +814,26 @@ static unsigned int maxConnections = 8;
|
||||||
|
|
||||||
/* Get a string description of the object. */
|
/* Get a string description of the object. */
|
||||||
obj = AUTORELEASE([obj mutableCopy]);
|
obj = AUTORELEASE([obj mutableCopy]);
|
||||||
|
quoteString(obj);
|
||||||
|
|
||||||
/* Escape the string. */
|
|
||||||
r = [obj rangeOfString: @"\\"];
|
|
||||||
if (r.length != 0)
|
|
||||||
{
|
|
||||||
[obj replaceString: @"\\" withString: @"\\\\"];
|
|
||||||
}
|
|
||||||
r = [obj rangeOfString: @"'"];
|
|
||||||
if (r.length != 0)
|
|
||||||
{
|
|
||||||
[obj replaceString: @"'" withString: @"\\'"];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add quoting around it. */
|
|
||||||
[obj replaceCharactersInRange: NSMakeRange(0, 0) withString: @"'"];
|
|
||||||
[obj appendString: @"'"];
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString*) quotef: (NSString*)fmt, ...
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
NSMutableString *s;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
s = [[NSMutableString allocWithZone: NSDefaultMallocZone()]
|
||||||
|
initWithFormat: fmt arguments: ap];
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
quoteString(s);
|
||||||
|
|
||||||
|
return AUTORELEASE(s);
|
||||||
|
}
|
||||||
|
|
||||||
- (NSString*) quoteCString: (const char *)s
|
- (NSString*) quoteCString: (const char *)s
|
||||||
{
|
{
|
||||||
NSString *str = [[NSString alloc] initWithCString: s];
|
NSString *str = [[NSString alloc] initWithCString: s];
|
||||||
|
|
Loading…
Reference in a new issue