ObjPgSQL  test.m at [9b7427552b]

File test.m artifact 777240ca2a part of check-in 9b7427552b


#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!"]];
	[connection executeCommand: @"INSERT INTO test (id, name, content) "
				    @"VALUES($1, $2, $3)"
			parameters: @[@"2", @"bla", @"Blup!!"]];

	result = [connection executeCommand: @"SELECT * FROM test"];
	of_log(@"%@", result);
	of_log(@"JSON: %@", [result JSONRepresentation]);

	[OFApplication terminate];
}
@end