Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -32,10 +32,11 @@ --builddir build \ ${CPPFLAGS} \ ${LIBS} \ ${SRCS} +.PHONY: test test: @objfw-compile \ -o test \ --builddir build \ -L. \ Index: PGConnection.m ================================================================== --- PGConnection.m +++ PGConnection.m @@ -97,11 +97,24 @@ size_t i = 0; do { if ([parameter isKindOfClass: [OFNull class]]) values[i++] = NULL; - else + else if ([parameter isKindOfClass: [OFNumber class]]) { + switch ([parameter type]) { + case OF_NUMBER_BOOL: + if ([parameter boolValue]) + values[i++] = "t"; + else + values[i++] = "f"; + break; + default: + values[i++] = [[parameter description] + UTF8String]; + break; + } + } else values[i++] = [parameter UTF8String]; } while ((parameter = va_arg(args, id)) != nil); result = PQexecParams(conn, [command UTF8String], argsCount, NULL, values, NULL, NULL, 0); Index: PGResultRow.m ================================================================== --- PGResultRow.m +++ PGResultRow.m @@ -1,6 +1,26 @@ #import "PGResultRow.h" + +static id +convert_type(PGresult *res, int col, OFString *str) +{ + switch (PQftype(res, col)) { + case 16: /* BOOLOID */ + if ([str isEqual: @"t"]) + return [OFNumber numberWithBool: YES]; + else + return [OFNumber numberWithBool: NO]; + case 21: /* INT2OID */ + return [OFNumber numberWithInt16: (int16_t)[str decimalValue]]; + case 23: /* INT4OID */ + return [OFNumber numberWithInt32: (int32_t)[str decimalValue]]; + case 20: /* INT8OID */ + return [OFNumber numberWithInt64: (int64_t)[str decimalValue]]; + } + + return str; +} @interface PGResultRowEnumerator: OFEnumerator { PGResult *result; PGresult *res; @@ -65,11 +85,12 @@ col = PQfnumber(res, [key UTF8String]); if (PQgetisnull(res, row, col)) return nil; - return [OFString stringWithUTF8String: PQgetvalue(res, row, col)]; + return convert_type(res, col, + [OFString stringWithUTF8String: PQgetvalue(res, row, col)]); } - (OFEnumerator*)keyEnumerator { return [[[PGResultRowKeyEnumerator alloc] @@ -131,8 +152,9 @@ pos++; if (pos >= count) return nil; - return [OFString stringWithUTF8String: PQgetvalue(res, row, pos++)]; + return convert_type(res, pos, + [OFString stringWithUTF8String: PQgetvalue(res, row, pos++)]); } @end Index: test.m ================================================================== --- test.m +++ test.m @@ -24,18 +24,19 @@ [connection executeCommand: @"DROP TABLE IF EXISTS test"]; [connection executeCommand: @"CREATE TABLE test (" @" id integer," @" name varchar(255)," - @" content text" + @" content text," + @" success boolean" @")"]; [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]; + @"VALUES ($1, $2, $3)" + parameters: @1, @"foo", @"Hallo Welt!", nil]; + [connection executeCommand: @"INSERT INTO test (id, content, success) " + @"VALUES ($1, $2, $3)" + parameters: @2, @2, @YES]; [connection insertRow: @{ @"content": @"Hallo!", @"name": @"foo" } intoTable: @"test"]; result = [connection executeCommand: @"SELECT * FROM test"]; of_log(@"%@", result);