Fixup for array quoting to retain old behavio of the -quoteArray: method while adding a new safe method which quotes strings in the array.

This commit is contained in:
Richard Frith-Macdonald 2020-08-12 20:30:46 +01:00
parent 8335ce336a
commit ce149e7ee3
4 changed files with 30 additions and 12 deletions

View file

@ -1723,14 +1723,6 @@ static inline unsigned int trim(char *str, unsigned len)
[super dealloc];
}
- (SQLLiteral*) quoteArray: (NSArray *)a
{
NSMutableString *s = [NSMutableString stringWithCapacity: 1000];
[self quoteArray: a toString: s quotingStrings: YES];
return SQLClientProxyLiteral(s);
}
- (NSMutableString*) quoteArray: (NSArray *)a
toString: (NSMutableString *)s
quotingStrings: (BOOL)q

View file

@ -972,11 +972,18 @@ SQLCLIENT_PRIVATE
/* Produce a quoted string from an array on databases where arrays are
* supported (currently only Postgres). This method is implemented by
* calling -quoteArray:toString:quotingStrings: with the option to
* calling -quoteArray:toString:quotingStrings: with the option to NOT
* 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). This method is implemented by
* calling -quoteArray:toString:quotingStrings: with the option to
* quote strings found in the array.
*/
- (SQLLiteral*) quoteArraySafe: (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.
@ -1933,6 +1940,7 @@ typedef struct _SQLClientPoolItem SQLClientPoolItem;
- (NSString*) queryString: (NSString*)stmt,...;
- (SQLLiteral*) quote: (id)obj;
- (SQLLiteral*) quoteArray: (NSArray *)a;
- (SQLLiteral*) quoteArraySafe: (NSArray *)a;
- (NSMutableString*) quoteArray: (NSArray *)a
toString: (NSMutableString *)s
quotingStrings: (BOOL)_q;

View file

@ -2346,9 +2346,22 @@ static int poolConnections = 0;
- (SQLLiteral*) quoteArray: (NSArray *)a
{
[NSException raise: NSGenericException
format: @"%@ not supported for this database", NSStringFromSelector(_cmd)];
return nil;
NSMutableString *s;
s = [self quoteArray: a
toString: nil
quotingStrings: NO];
return SQLClientProxyLiteral(s);
}
- (SQLLiteral*) quoteArraySafe: (NSArray *)a
{
NSMutableString *s;
s = [self quoteArray: a
toString: nil
quotingStrings: YES];
return SQLClientProxyLiteral(s);
}
- (NSMutableString*) quoteArray: (NSArray *)a

View file

@ -1326,6 +1326,11 @@ static Class cls = Nil;
return (SQLLiteral*)[_items[0].c quoteArray: a];
}
- (SQLLiteral*) quoteArraySafe: (NSArray*)a
{
return (SQLLiteral*)[_items[0].c quoteArraySafe: a];
}
- (NSMutableString*) quoteArray: (NSArray *)a
toString: (NSMutableString *)s
quotingStrings: (BOOL)_q