Index: src/PGConnection.h ================================================================== --- src/PGConnection.h +++ src/PGConnection.h @@ -1,26 +1,31 @@ #include #import #import "PGResult.h" + +OF_ASSUME_NONNULL_BEGIN @interface PGConnection: OFObject { PGconn *_connnection; - OFDictionary *_parameters; + OFDictionary OF_GENERIC(OFString *, OFString *) *_parameters; } -@property (copy) OFDictionary *parameters; +@property (nonatomic, copy) + OFDictionary OF_GENERIC(OFString *, OFString *) *parameters; - (void)connect; - (void)reset; - (void)close; -- (PGResult*)executeCommand: (OFConstantString*)command; -- (PGResult*)executeCommand: (OFConstantString*)command - parameters: (id)firstParameter, ... OF_SENTINEL; -- (PGconn*)PG_connection; -- (void)insertRow: (OFDictionary*)row - intoTable: (OFString*)table; -- (void)insertRows: (OFArray*)rows - intoTable: (OFString*)table; +- (PGResult *)executeCommand: (OFConstantString *)command; +- (PGResult *)executeCommand: (OFConstantString *)command + parameters: (id)firstParameter, ... OF_SENTINEL; +- (PGconn *)PG_connection; +- (void)insertRow: (OFDictionary *)row + intoTable: (OFString *)table; +- (void)insertRows: (OFArray OF_GENERIC(OFDictionary *) *)rows + intoTable: (OFString *)table; @end + +OF_ASSUME_NONNULL_END Index: src/PGConnection.m ================================================================== --- src/PGConnection.m +++ src/PGConnection.m @@ -15,13 +15,15 @@ [super dealloc]; } - (void)connect { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFEnumerator *keyEnumerator = [_parameters keyEnumerator]; - OFEnumerator *objectEnumerator = [_parameters objectEnumerator]; + void *pool = objc_autoreleasePoolPush(); + OFEnumerator OF_GENERIC(OFString *) *keyEnumerator = + [_parameters keyEnumerator]; + OFEnumerator OF_GENERIC(OFString *) *objectEnumerator = + [_parameters objectEnumerator]; OFMutableString *connectionInfo = nil; OFString *key, *object; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { @@ -37,11 +39,11 @@ if (PQstatus(_connnection) == CONNECTION_BAD) @throw [PGConnectionFailedException exceptionWithConnection: self]; - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)reset { PQreset(_connnection); @@ -53,11 +55,11 @@ PQfinish(_connnection); _connnection = NULL; } -- (PGResult*)executeCommand: (OFConstantString*)command +- (PGResult *)executeCommand: (OFConstantString *)command { PGresult *result = PQexec(_connnection, [command UTF8String]); if (PQresultStatus(result) == PGRES_FATAL_ERROR) { PQclear(result); @@ -78,14 +80,14 @@ exceptionWithConnection: self command: command]; } } -- (PGResult*)executeCommand: (OFConstantString*)command - parameters: (id)parameter, ... +- (PGResult *)executeCommand: (OFConstantString *)command + parameters: (id)parameter, ... { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); PGresult *result; const char **values; va_list args, args2; int argsCount; @@ -128,11 +130,11 @@ argsCount, NULL, values, NULL, NULL, 0); } @finally { [self freeMemory: values]; } - [pool release]; + objc_autoreleasePoolPop(pool); switch (PQresultStatus(result)) { case PGRES_TUPLES_OK: return [PGResult PG_resultWithResult: result]; case PGRES_COMMAND_OK: @@ -144,14 +146,14 @@ exceptionWithConnection: self command: command]; } } -- (void)insertRow: (OFDictionary*)row - intoTable: (OFString*)table +- (void)insertRow: (OFDictionary *)row + intoTable: (OFString *)table { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFMutableString *command; OFEnumerator *enumerator; const char **values; PGresult *result; OFString *key, *value; @@ -196,11 +198,11 @@ (int)count, NULL, values, NULL, NULL, 0); } @finally { [self freeMemory: values]; } - [pool release]; + objc_autoreleasePoolPop(pool); if (PQresultStatus(result) != PGRES_COMMAND_OK) { PQclear(result); @throw [PGCommandFailedException exceptionWithConnection: self @@ -208,24 +210,18 @@ } PQclear(result); } -- (void)insertRows: (OFArray*)rows - intoTable: (OFString*)table -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFEnumerator *enumerator = [rows objectEnumerator]; - OFDictionary *row; - - while ((row = [enumerator nextObject]) != nil) +- (void)insertRows: (OFArray OF_GENERIC(OFDictionary *) *)rows + intoTable: (OFString *)table +{ + for (OFDictionary *row in rows) [self insertRow: row intoTable: table]; - - [pool release]; } -- (PGconn*)PG_connection +- (PGconn *)PG_connection { return _connnection; } @end Index: src/PGResult.h ================================================================== --- src/PGResult.h +++ src/PGResult.h @@ -1,13 +1,19 @@ #include #import -@interface PGResult: OFArray +OF_ASSUME_NONNULL_BEGIN + +@class PGResultRow; + +@interface PGResult: OFArray OF_GENERIC(PGResultRow *) { PGresult *_result; } -+ PG_resultWithResult: (PGresult*)result; -- PG_initWithResult: (PGresult*)result; -- (PGresult*)PG_result; ++ (instancetype)PG_resultWithResult: (PGresult *)result; +- PG_initWithResult: (PGresult *)result OF_METHOD_FAMILY(init); +- (PGresult *)PG_result; @end + +OF_ASSUME_NONNULL_END Index: src/PGResult.m ================================================================== --- src/PGResult.m +++ src/PGResult.m @@ -1,15 +1,15 @@ #import "PGResult.h" #import "PGResultRow.h" @implementation PGResult -+ PG_resultWithResult: (PGresult*)result ++ PG_resultWithResult: (PGresult *)result { return [[[self alloc] PG_initWithResult: result] autorelease]; } -- PG_initWithResult: (PGresult*)result +- PG_initWithResult: (PGresult *)result { self = [super init]; _result = result; @@ -36,10 +36,10 @@ return [PGResultRow rowWithResult: self row: (int)index]; } -- (PGresult*)PG_result +- (PGresult *)PG_result { return _result; } @end Index: src/PGResultRow.h ================================================================== --- src/PGResultRow.h +++ src/PGResultRow.h @@ -1,18 +1,22 @@ #include #import #import "PGResult.h" + +OF_ASSUME_NONNULL_BEGIN @interface PGResultRow: OFDictionary { PGResult *_result; PGresult *_res; int _row; } -+ rowWithResult: (PGResult*)result ++ rowWithResult: (PGResult *)result row: (int)row; -- initWithResult: (PGResult*)result +- initWithResult: (PGResult *)result row: (int)row; @end + +OF_ASSUME_NONNULL_END Index: src/PGResultRow.m ================================================================== --- src/PGResultRow.m +++ src/PGResultRow.m @@ -43,18 +43,18 @@ @interface PGResultRowObjectEnumerator: PGResultRowEnumerator @end @implementation PGResultRow -+ rowWithResult: (PGResult*)result ++ rowWithResult: (PGResult *)result row: (int)row { return [[[self alloc] initWithResult: result row: row] autorelease]; } -- initWithResult: (PGResult*)result +- initWithResult: (PGResult *)result row: (int)row { self = [super init]; _result = [result retain]; @@ -96,26 +96,26 @@ return convertType(_res, column, [OFString stringWithUTF8String: PQgetvalue(_res, _row, column)]); } -- (OFEnumerator*)keyEnumerator +- (OFEnumerator *)keyEnumerator { return [[[PGResultRowKeyEnumerator alloc] initWithResult: _result row: _row] autorelease]; } -- (OFEnumerator*)objectEnumerator +- (OFEnumerator *)objectEnumerator { return [[[PGResultRowObjectEnumerator alloc] initWithResult: _result row: _row] autorelease]; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state - objects: (id*)objects + objects: (id *)objects count: (int)count { int i, j; if (state->extra[0] == 0) { @@ -144,11 +144,11 @@ return j; } @end @implementation PGResultRowEnumerator -- initWithResult: (PGResult*)result +- initWithResult: (PGResult *)result row: (int)row { self = [super init]; _result = [result retain]; Index: src/exceptions/PGCommandFailedException.h ================================================================== --- src/exceptions/PGCommandFailedException.h +++ src/exceptions/PGCommandFailedException.h @@ -1,14 +1,18 @@ #import "PGException.h" + +OF_ASSUME_NONNULL_BEGIN @interface PGCommandFailedException: PGException { OFString *_command; } -@property (readonly, copy) OFString *command; +@property (readonly, nonatomic) OFString *command; -+ (instancetype)exceptionWithConnection: (PGConnection*)connection - command: (OFString*)command; -- initWithConnection: (PGConnection*)connection - command: (OFString*)command; ++ (instancetype)exceptionWithConnection: (PGConnection *)connection + command: (OFString *)command; +- initWithConnection: (PGConnection *)connection + command: (OFString *)command; @end + +OF_ASSUME_NONNULL_END Index: src/exceptions/PGCommandFailedException.m ================================================================== --- src/exceptions/PGCommandFailedException.m +++ src/exceptions/PGCommandFailedException.m @@ -1,19 +1,19 @@ #import "PGCommandFailedException.h" @implementation PGCommandFailedException @synthesize command = _command; -+ (instancetype)exceptionWithConnection: (PGConnection*)connection - command: (OFString*)command ++ (instancetype)exceptionWithConnection: (PGConnection *)connection + command: (OFString *)command { return [[[self alloc] initWithConnection: connection command: command] autorelease]; } -- initWithConnection: (PGConnection*)connection - command: (OFString*)command +- initWithConnection: (PGConnection *)connection + command: (OFString *)command { self = [super initWithConnection: connection]; @try { _command = [command copy]; @@ -30,11 +30,11 @@ [_command release]; [super dealloc]; } -- (OFString*)description +- (OFString *)description { return [OFString stringWithFormat: @"A PostgreSQL command failed: %@\n" @"Command: %@", _error, _command]; } @end Index: src/exceptions/PGConnectionFailedException.h ================================================================== --- src/exceptions/PGConnectionFailedException.h +++ src/exceptions/PGConnectionFailedException.h @@ -1,4 +1,8 @@ #import "PGException.h" + +OF_ASSUME_NONNULL_BEGIN @interface PGConnectionFailedException: PGException @end + +OF_ASSUME_NONNULL_END Index: src/exceptions/PGConnectionFailedException.m ================================================================== --- src/exceptions/PGConnectionFailedException.m +++ src/exceptions/PGConnectionFailedException.m @@ -1,10 +1,10 @@ #import "PGConnectionFailedException.h" @implementation PGConnectionFailedException -- (OFString*)description +- (OFString *)description { return [OFString stringWithFormat: @"Establishing a PostgreSQL connection failed:\n%@\n" "Parameters: %@", _error, [_connection parameters]]; } @end Index: src/exceptions/PGException.h ================================================================== --- src/exceptions/PGException.h +++ src/exceptions/PGException.h @@ -1,15 +1,19 @@ #import #import "PGConnection.h" + +OF_ASSUME_NONNULL_BEGIN @interface PGException: OFException { PGConnection *_connection; OFString *_error; } -@property (readonly, retain) PGConnection *connection; +@property (readonly, nonatomic) PGConnection *connection; -+ (instancetype)exceptionWithConnection: (PGConnection*)connection; -- initWithConnection: (PGConnection*)connection; ++ (instancetype)exceptionWithConnection: (PGConnection *)connection; +- initWithConnection: (PGConnection *)connection; @end + +OF_ASSUME_NONNULL_END Index: src/exceptions/PGException.m ================================================================== --- src/exceptions/PGException.m +++ src/exceptions/PGException.m @@ -1,16 +1,16 @@ #import "PGException.h" @implementation PGException @synthesize connection = _connection; -+ (instancetype)exceptionWithConnection: (PGConnection*)connection ++ (instancetype)exceptionWithConnection: (PGConnection *)connection { return [[[self alloc] initWithConnection: connection] autorelease]; } -- initWithConnection: (PGConnection*)connection +- initWithConnection: (PGConnection *)connection { self = [super init]; @try { _connection = [connection retain]; @@ -31,11 +31,11 @@ [_error release]; [super dealloc]; } -- (OFString*)description +- (OFString *)description { return [OFString stringWithFormat: @"A PostgreSQL operation failed: %@", _error]; } @end