Artifact f9e8525602bb73e91c08b7a0b70bbe339c9166aed3e457b7264d6d553fc4aa7a:
- File
test.m
— part of check-in
[d2fe40f160]
at
2012-10-05 20:17:45
on branch trunk
— Nicer API.
-[executeCommand:parameters:] is now a variadic function instead of
taking an array as argument. (user: js size: 1221)
#import <ObjFW/ObjFW.h> #import "PGConnection.h" #import "PGConnectionFailedException.h" @interface Test: OFObject { PGConnection *connection; } @end OF_APPLICATION_DELEGATE(Test) @implementation Test - (void)applicationDidFinishLaunching { PGResult *result; connection = [[PGConnection alloc] init]; [connection setParameters: [OFDictionary dictionaryWithKeysAndObjects: @"user", @"js", @"dbname", @"js", nil]]; [connection connect]; [connection executeCommand: @"DROP TABLE IF EXISTS test"]; [connection executeCommand: @"CREATE TABLE test (" @" id integer," @" name varchar(255)," @" content text" @")"]; [connection executeCommand: @"INSERT INTO test (id, name, content) " @"VALUES($1, $2, $3)" parameters: @"1", @"foo", @"Hallo Welt!", nil]; [connection executeCommand: @"INSERT INTO test (id, content) " @"VALUES($1, $2)" 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