ObjPgSQL/test.m
Jonathan Schleifer 6e1eda2f24 Nicer API.
-[executeCommand:parameters:] is now a variadic function instead of
taking an array as argument.

FossilOrigin-Name: d2fe40f16065b5ccf5ba135af1ec95f09ed2f8ee96e661a7a7d085da833e972e
2012-10-05 20:17:44 +00:00

47 lines
1.2 KiB
Objective-C

#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