@@ -28,12 +28,11 @@ #import "PGConnectionFailedException.h" #import "PGCommandFailedException.h" @implementation PGConnection -@synthesize pg_connection = _connection; -@synthesize parameters = _parameters; +@synthesize pg_connection = _connection, parameters = _parameters; - (void)dealloc { [_parameters release]; @@ -121,33 +120,29 @@ va_start(args, parameter); va_copy(args2, args); for (argsCount = 1; va_arg(args2, id) != nil; argsCount++); - values = [self allocMemoryWithSize: sizeof(*values) - count: argsCount]; + values = OFAllocMemory(argsCount, sizeof(*values)); @try { size_t i = 0; do { if ([parameter isKindOfClass: [OFString class]]) values[i++] = [parameter UTF8String]; else if ([parameter isKindOfClass: [OFNumber class]]) { OFNumber *number = parameter; - switch (number.type) { - case OF_NUMBER_TYPE_BOOL: + if (strcmp(number.objCType, + @encode(bool)) == 0) { if (number.boolValue) values[i++] = "t"; else values[i++] = "f"; - break; - default: + } else values[i++] = number.description.UTF8String; - break; - } } else if ([parameter isKindOfClass: [OFNull class]]) values[i++] = NULL; else values[i++] = [parameter description].UTF8String; @@ -154,11 +149,11 @@ } while ((parameter = va_arg(args, id)) != nil); result = PQexecParams(_connection, command.UTF8String, argsCount, NULL, values, NULL, NULL, 0); } @finally { - [self freeMemory: values]; + OFFreeMemory(values); } objc_autoreleasePoolPop(pool); switch (PQresultStatus(result)) { @@ -173,12 +168,11 @@ exceptionWithConnection: self command: command]; } } -- (void)insertRow: (OFDictionary *)row - intoTable: (OFString *)table +- (void)insertRow: (PGRow)row intoTable: (OFString *)table { void *pool = objc_autoreleasePoolPush(); OFMutableString *command; OFEnumerator *enumerator; const char **values; @@ -203,12 +197,11 @@ i++; } [command appendString: @") VALUES ("]; - values = [self allocMemoryWithSize: sizeof(*values) - count: count]; + values = OFAllocMemory(count, sizeof(*values)); @try { i = 0; enumerator = [row objectEnumerator]; while ((value = [enumerator nextObject]) != nil) { if (i > 0) @@ -222,11 +215,11 @@ [command appendString: @")"]; result = PQexecParams(_connection, command.UTF8String, (int)count, NULL, values, NULL, NULL, 0); } @finally { - [self freeMemory: values]; + OFFreeMemory(values); } objc_autoreleasePoolPop(pool); if (PQresultStatus(result) != PGRES_COMMAND_OK) { @@ -237,13 +230,12 @@ } PQclear(result); } -- (void)insertRows: (OFArray OF_GENERIC(OFDictionary *) *)rows +- (void)insertRows: (OFArray OF_GENERIC(PGRow) *)rows intoTable: (OFString *)table { for (OFDictionary *row in rows) - [self insertRow: row - intoTable: table]; + [self insertRow: row intoTable: table]; } @end