Changes to avoid a client being removed from the pool longer than necessary.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@38454 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2015-04-13 08:30:31 +00:00
parent 0b828587b6
commit d089d9ce82
2 changed files with 140 additions and 46 deletions

View file

@ -1,3 +1,13 @@
2015-04-13 Richard Frith-Macdonald <rfm@gnu.org>
* SQLClientPool.m:
Make sure clients provided temporarily in convenience methods are
swallowed by the pool again as soon as possible. Also trap and
re-raise exceptions after swallowing provided client, to avoid
the client being in use longer than necessary after an exception.
Also, avoid taking clients from the pool in a few cases wehere we
don't actually need to.
2015-04-12 Richard Frith-Macdonald <rfm@gnu.org>
* SQLClient.h:

View file

@ -526,41 +526,44 @@
- (NSString*) buildQuery: (NSString*)stmt, ...
{
SQLClient *db = [self provideClient];
NSString *sql = nil;
NSString *sql;
va_list ap;
/*
* First check validity and concatenate parts of the query.
*/
va_start (ap, stmt);
sql = [[db prepare: stmt args: ap] objectAtIndex: 0];
sql = [[q prepare: stmt args: ap] objectAtIndex: 0];
va_end (ap);
[self swallowClient: db];
return sql;
}
- (NSString*) buildQuery: (NSString*)stmt with: (NSDictionary*)values
{
SQLClient *db = [self provideClient];
NSString *result = [db buildQuery: stmt with: values];
NSString *result = [q buildQuery: stmt with: values];
[self swallowClient: db];
return result;
}
- (NSMutableArray*) cache: (int)seconds
query: (NSString*)stmt,...
{
SQLClient *db = [self provideClient];
SQLClient *db;
NSMutableArray *result;
va_list ap;
va_start (ap, stmt);
stmt = [[db prepare: stmt args: ap] objectAtIndex: 0];
stmt = [[q prepare: stmt args: ap] objectAtIndex: 0];
va_end (ap);
result = [db cache: seconds simpleQuery: stmt];
db = [self provideClient];
NS_DURING
result = [db cache: seconds simpleQuery: stmt];
NS_HANDLER
[self swallowClient: db];
[localException raise];
NS_ENDHANDLER
[self swallowClient: db];
return result;
}
@ -569,18 +572,32 @@
query: (NSString*)stmt
with: (NSDictionary*)values
{
SQLClient *db = [self provideClient];
NSMutableArray *result = [db cache: seconds query: stmt with: values];
SQLClient *db;
NSMutableArray *result;
db = [self provideClient];
NS_DURING
result = [db cache: seconds query: stmt with: values];
NS_HANDLER
[self swallowClient: db];
[localException raise];
NS_ENDHANDLER
[self swallowClient: db];
return result;
}
- (NSMutableArray*) cache: (int)seconds simpleQuery: (NSString*)stmt;
{
SQLClient *db = [self provideClient];
NSMutableArray *result = [db cache: seconds simpleQuery: stmt];
SQLClient *db;
NSMutableArray *result;
db = [self provideClient];
NS_DURING
result = [db cache: seconds simpleQuery: stmt];
NS_HANDLER
[self swallowClient: db];
[localException raise];
NS_ENDHANDLER
[self swallowClient: db];
return result;
}
@ -590,13 +607,19 @@
recordType: (id)rtype
listType: (id)ltype
{
SQLClient *db = [self provideClient];
SQLClient *db;
NSMutableArray *result;
result = [db cache: seconds
simpleQuery: stmt
recordType: rtype
listType: ltype];
db = [self provideClient];
NS_DURING
result = [db cache: seconds
simpleQuery: stmt
recordType: rtype
listType: ltype];
NS_HANDLER
[self swallowClient: db];
[localException raise];
NS_ENDHANDLER
[self swallowClient: db];
return result;
}
@ -608,41 +631,61 @@
- (NSInteger) execute: (NSString*)stmt, ...
{
SQLClient *db = [self provideClient];
SQLClient *db;
NSInteger result;
NSArray *info;
va_list ap;
va_start (ap, stmt);
info = [db prepare: stmt args: ap];
info = [q prepare: stmt args: ap];
va_end (ap);
result = [db simpleExecute: info];
db = [self provideClient];
NS_DURING
result = [db simpleExecute: info];
NS_HANDLER
[self swallowClient: db];
[localException raise];
NS_ENDHANDLER
[self swallowClient: db];
return result;
}
- (NSInteger) execute: (NSString*)stmt with: (NSDictionary*)values
{
SQLClient *db = [self provideClient];
NSInteger result = [db execute: stmt with: values];
SQLClient *db;
NSInteger result;
db = [self provideClient];
NS_DURING
result = [db execute: stmt with: values];
NS_HANDLER
[self swallowClient: db];
[localException raise];
NS_ENDHANDLER
[self swallowClient: db];
return result;
}
- (NSMutableArray*) query: (NSString*)stmt, ...
{
SQLClient *db = [self provideClient];
NSMutableArray *result = nil;
SQLClient *db;
NSMutableArray *result;
va_list ap;
/*
* First check validity and concatenate parts of the query.
*/
va_start (ap, stmt);
stmt = [[db prepare: stmt args: ap] objectAtIndex: 0];
stmt = [[q prepare: stmt args: ap] objectAtIndex: 0];
va_end (ap);
result = [db simpleQuery: stmt];
db = [self provideClient];
NS_DURING
result = [db simpleQuery: stmt];
NS_HANDLER
[self swallowClient: db];
[localException raise];
NS_ENDHANDLER
[self swallowClient: db];
return result;
@ -650,24 +693,38 @@
- (NSMutableArray*) query: (NSString*)stmt with: (NSDictionary*)values
{
SQLClient *db = [self provideClient];
NSMutableArray *result = [db query: stmt with: values];
SQLClient *db;
NSMutableArray *result;
db = [self provideClient];
NS_DURING
result = [db query: stmt with: values];
NS_HANDLER
[self swallowClient: db];
[localException raise];
NS_ENDHANDLER
[self swallowClient: db];
return result;
}
- (SQLRecord*) queryRecord: (NSString*)stmt, ...
{
SQLClient *db = [self provideClient];
NSArray *result = nil;
SQLClient *db;
NSArray *result;
SQLRecord *record;
va_list ap;
va_start (ap, stmt);
stmt = [[db prepare: stmt args: ap] objectAtIndex: 0];
stmt = [[q prepare: stmt args: ap] objectAtIndex: 0];
va_end (ap);
result = [db simpleQuery: stmt];
db = [self provideClient];
NS_DURING
result = [db simpleQuery: stmt];
NS_HANDLER
[self swallowClient: db];
[localException raise];
NS_ENDHANDLER
[self swallowClient: db];
if ([result count] > 1)
@ -686,15 +743,22 @@
- (NSString*) queryString: (NSString*)stmt, ...
{
SQLClient *db = [self provideClient];
NSArray *result = nil;
SQLClient *db;
NSArray *result;
SQLRecord *record;
va_list ap;
va_start (ap, stmt);
stmt = [[db prepare: stmt args: ap] objectAtIndex: 0];
stmt = [[q prepare: stmt args: ap] objectAtIndex: 0];
va_end (ap);
result = [db simpleQuery: stmt];
db = [self provideClient];
NS_DURING
result = [db simpleQuery: stmt];
NS_HANDLER
[self swallowClient: db];
[localException raise];
NS_ENDHANDLER
[self swallowClient: db];
if ([result count] > 1)
@ -793,18 +857,32 @@
- (NSInteger) simpleExecute: (NSArray*)info
{
SQLClient *db = [self provideClient];
NSInteger result = [db simpleExecute: info];
SQLClient *db;
NSInteger result;
db = [self provideClient];
NS_DURING
result = [db simpleExecute: info];
NS_HANDLER
[self swallowClient: db];
[localException raise];
NS_ENDHANDLER
[self swallowClient: db];
return result;
}
- (NSMutableArray*) simpleQuery: (NSString*)stmt
{
SQLClient *db = [self provideClient];
NSMutableArray *result = [db simpleQuery: stmt];
SQLClient *db;
NSMutableArray *result;
db = [self provideClient];
NS_DURING
result = [db simpleQuery: stmt];
NS_HANDLER
[self swallowClient: db];
[localException raise];
NS_ENDHANDLER
[self swallowClient: db];
return result;
}
@ -813,12 +891,18 @@
recordType: (id)rtype
listType: (id)ltype
{
SQLClient *db = [self provideClient];
SQLClient *db;
NSMutableArray *result;
result = [db simpleQuery: stmt
recordType: rtype
listType: ltype];
db = [self provideClient];
NS_DURING
result = [db simpleQuery: stmt
recordType: rtype
listType: ltype];
NS_HANDLER
[self swallowClient: db];
[localException raise];
NS_ENDHANDLER
[self swallowClient: db];
return result;
}