mirror of
https://github.com/gnustep/libs-sqlclient.git
synced 2025-06-04 19:11:13 +00:00
Fixup for quoted array
This commit is contained in:
parent
869cfda7d1
commit
a496d0dd8e
2 changed files with 12 additions and 58 deletions
56
Postgres.m
56
Postgres.m
|
@ -1723,65 +1723,11 @@ static inline unsigned int trim(char *str, unsigned len)
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) _quoteArray: (NSArray *)a to: (NSMutableString*)s
|
||||
{
|
||||
NSUInteger count;
|
||||
NSUInteger index;
|
||||
|
||||
[s appendString: @"ARRAY["];
|
||||
count = [a count];
|
||||
for (index = 0; index < count; index++)
|
||||
{
|
||||
id o = [a objectAtIndex: index];
|
||||
|
||||
if (index > 0)
|
||||
{
|
||||
[s appendString: @","];
|
||||
}
|
||||
if ([o isKindOfClass: [NSArray class]])
|
||||
{
|
||||
[self _quoteArray: (NSArray *)o to: s];
|
||||
}
|
||||
else if ([o isKindOfClass: [NSString class]])
|
||||
{
|
||||
if (NO == SQLClientIsLiteral(o))
|
||||
{
|
||||
o = [self quoteString: o];
|
||||
}
|
||||
[s appendString: (NSString*)o];
|
||||
}
|
||||
else if ([o isKindOfClass: [NSDate class]])
|
||||
{
|
||||
[s appendString: [self quote: (NSString*)o]];
|
||||
[s appendString: @"::timestamp with time zone"];
|
||||
}
|
||||
else if ([o isKindOfClass: [NSData class]])
|
||||
{
|
||||
unsigned len = [self lengthOfEscapedBLOB: o];
|
||||
uint8_t *buf;
|
||||
|
||||
buf = malloc(len+1);
|
||||
[self copyEscapedBLOB: o into: buf];
|
||||
buf[len] = '\0';
|
||||
[s appendFormat: @"%s::bytea", buf];
|
||||
free(buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
o = [self quote: (NSString*)o];
|
||||
[s appendString: (NSString*)o];
|
||||
}
|
||||
}
|
||||
[s appendString: @"]"];
|
||||
}
|
||||
|
||||
- (SQLLiteral*) quoteArray: (NSArray *)a
|
||||
{
|
||||
NSMutableString *s = [NSMutableString stringWithCapacity: 1000];
|
||||
|
||||
NSAssert([a isKindOfClass: [NSArray class]], NSInvalidArgumentException);
|
||||
|
||||
[self _quoteArray: a to: s];
|
||||
[self quoteArray: a to: s quotingStrings: YES];
|
||||
return SQLClientProxyLiteral(s);
|
||||
}
|
||||
|
||||
|
|
14
SQLClient.h
14
SQLClient.h
|
@ -971,17 +971,25 @@ SQLCLIENT_PRIVATE
|
|||
- (SQLLiteral*) quotef: (NSString*)fmt, ...;
|
||||
|
||||
/* Produce a quoted string from an array on databases where arrays are
|
||||
* supported (currently only Postgres).
|
||||
* supported (currently only Postgres). This method is implemented by
|
||||
* calling -quoteArray:toString:quotingStrings: with the option to
|
||||
* quote strings found in the array.
|
||||
*/
|
||||
- (SQLLiteral*) quoteArray: (NSArray*)a;
|
||||
|
||||
/* Produce a quoted string from an array on databases where arrays are
|
||||
* supported (currently only Postgres).<br />
|
||||
* If the s argument is nil, a new mutable string is created and returned.
|
||||
* If the s argument is not nil, the quoted array is appended to it rather
|
||||
* than being produced in a new string (this method uses that feature to
|
||||
* recursively quote nested arrays).<br />
|
||||
* recursively quote nested arrays) and the method returns the argument.<br />
|
||||
* The q argument determines whether string values found in the array
|
||||
* are quoted or added literally.
|
||||
* are quoted or added literally.<br />
|
||||
* NB. Passing NO to prevent strings from being quoted is dangerous since
|
||||
* it could result in an invalid quoted array if any of the array contents
|
||||
* is a string which would not be syntactically valid; use it only when
|
||||
* you are certain that the strings in the array are either already
|
||||
* quoted or are valid representations of some other type.
|
||||
*/
|
||||
- (NSMutableString*) quoteArray: (NSArray *)a
|
||||
toString: (NSMutableString *)s
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue