Index: PGConnection.h ================================================================== --- PGConnection.h +++ PGConnection.h @@ -18,8 +18,8 @@ - (OFDictionary*)parameters; - (void)connect; - (void)reset; - (PGResult*)executeCommand: (OFString*)command; - (PGResult*)executeCommand: (OFString*)command - parameters: (OFArray*)parameters; + parameters: (id)firstParameter, ...; - (PGconn*)PG_connection; @end Index: PGConnection.m ================================================================== --- PGConnection.m +++ PGConnection.m @@ -76,32 +76,37 @@ PQclear(result); return nil; } - (PGResult*)executeCommand: (OFString*)command - parameters: (OFArray*)parameters_ + parameters: (id)parameter, ... { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; PGresult *result; const char **values; + va_list args, args2; + size_t argsCount; + + va_start(args, parameter); + va_copy(args2, args); + + for (argsCount = 1; va_arg(args2, id) != nil; argsCount++); values = [self allocMemoryWithSize: sizeof(*values) - count: [parameters_ count]]; + count: argsCount]; @try { - OFEnumerator *enumerator = [parameters_ objectEnumerator]; size_t i = 0; - id parameter; - while ((parameter = [enumerator nextObject]) != nil) { + do { if ([parameter isKindOfClass: [OFNull class]]) values[i++] = NULL; else values[i++] = [parameter UTF8String]; - } + } while ((parameter = va_arg(args, id)) != nil); result = PQexecParams(conn, [command UTF8String], - [parameters_ count], NULL, values, NULL, NULL, 0); + argsCount, NULL, values, NULL, NULL, 0); } @finally { [self freeMemory: values]; } [pool release]; Index: test.m ================================================================== --- test.m +++ test.m @@ -28,17 +28,20 @@ @" name varchar(255)," @" content text" @")"]; [connection executeCommand: @"INSERT INTO test (id, name, content) " @"VALUES($1, $2, $3)" - parameters: @[@"1", @"foo", @"Hallo Welt!"]]; + parameters: @"1", @"foo", @"Hallo Welt!", nil]; [connection executeCommand: @"INSERT INTO test (id, content) " @"VALUES($1, $2)" - parameters: @[@"2", @"Blup!!"]]; + parameters: @"2", @"Blup!!", nil]; result = [connection executeCommand: @"SELECT * FROM test"]; of_log(@"%@", result); of_log(@"JSON: %@", [result JSONRepresentation]); + + result = [connection executeCommand: @"SELECT COUNT(*) FROM test"]; + of_log(@"%@", result); [OFApplication terminate]; } @end