ObjPgSQL/test.m
Jonathan Schleifer 728b3d1e2a Add -[insertRows:intoTable:].
FossilOrigin-Name: 7b335b3af81d4506f2842748671541073f4c455b4a0ce8a108eab0d43280f3ad
2012-10-06 21:02:01 +00:00

49 lines
1.3 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];
[connection insertRow: @{ @"content": @"Hallo!", @"name": @"foo" }
intoTable: @"test"];
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