add convenience method

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@28691 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2009-09-16 08:59:59 +00:00
parent c4c65eca9f
commit 050edb2fd4
3 changed files with 52 additions and 0 deletions

View file

@ -1,3 +1,10 @@
2009-09-16 Richard Frith-Macdonald <rfm@gnu.org>
* SQLClient.h:
* SQLClient.m:
Add convenience method to convert array of rows into an array of
columns.
2009-09-08 Richard Frith-Macdonald <rfm@gnu.org> 2009-09-08 Richard Frith-Macdonald <rfm@gnu.org>
* SQLClient.h: * SQLClient.h:

View file

@ -1046,6 +1046,13 @@ extern unsigned SQLClientTimeTick();
*/ */
- (SQLTransaction*) batch: (BOOL)stopOnFailure; - (SQLTransaction*) batch: (BOOL)stopOnFailure;
/**
* Convenience method to deal with the results of a query converting the
* normal array of records into an array of record columns. Each column
* in the array is an array containing all the values from that column.
*/
- (NSMutableArray*) columns: (NSMutableArray*)records;
/** /**
* Executes a query (like the -query:,... method) and checks the result * Executes a query (like the -query:,... method) and checks the result
* (raising an exception if the query did not contain a single record) * (raising an exception if the query did not contain a single record)

View file

@ -2150,6 +2150,7 @@ static unsigned int maxConnections = 8;
} }
NS_HANDLER NS_HANDLER
{ {
result = nil;
[lock unlock]; [lock unlock];
[localException raise]; [localException raise];
} }
@ -2460,6 +2461,43 @@ static unsigned int maxConnections = 8;
return AUTORELEASE((SQLTransaction*)transaction); return AUTORELEASE((SQLTransaction*)transaction);
} }
- (NSMutableArray*) columns: (NSMutableArray*)records
{
SQLRecord *r = [records lastObject];
unsigned rowCount = [records count];
unsigned colCount = [r count];
NSMutableArray *m;
if (rowCount == 0 || colCount == 0)
{
m = [NSMutableArray array];
}
else
{
NSMutableArray *cols[colCount];
unsigned i;
m = [NSMutableArray arrayWithCapacity: colCount];
for (i = 0; i < colCount; i++)
{
cols[i] = [[NSMutableArray alloc] initWithCapacity: rowCount];
[m addObject: cols[i]];
[cols[i] release];
}
for (i = 0; i < rowCount; i++)
{
unsigned j;
r = [records objectAtIndex: i];
for (j = 0; j < colCount; j++)
{
[cols[j] addObject: [r objectAtIndex: j]];
}
}
}
return m;
}
- (SQLRecord*) queryRecord: (NSString*)stmt, ... - (SQLRecord*) queryRecord: (NSString*)stmt, ...
{ {
va_list ap; va_list ap;