diff --git a/src/PGConnection.h b/src/PGConnection.h index b40d2f2..365a95a 100644 --- a/src/PGConnection.h +++ b/src/PGConnection.h @@ -4,23 +4,28 @@ #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 diff --git a/src/PGConnection.m b/src/PGConnection.m index a83980b..88a4cb2 100644 --- a/src/PGConnection.m +++ b/src/PGConnection.m @@ -17,9 +17,11 @@ - (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; @@ -39,7 +41,7 @@ @throw [PGConnectionFailedException exceptionWithConnection: self]; - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)reset @@ -55,7 +57,7 @@ _connnection = NULL; } -- (PGResult*)executeCommand: (OFConstantString*)command +- (PGResult *)executeCommand: (OFConstantString *)command { PGresult *result = PQexec(_connnection, [command UTF8String]); @@ -80,10 +82,10 @@ } } -- (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; @@ -130,7 +132,7 @@ [self freeMemory: values]; } - [pool release]; + objc_autoreleasePoolPop(pool); switch (PQresultStatus(result)) { case PGRES_TUPLES_OK: @@ -146,10 +148,10 @@ } } -- (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; @@ -198,7 +200,7 @@ [self freeMemory: values]; } - [pool release]; + objc_autoreleasePoolPop(pool); if (PQresultStatus(result) != PGRES_COMMAND_OK) { PQclear(result); @@ -210,21 +212,15 @@ PQclear(result); } -- (void)insertRows: (OFArray*)rows - intoTable: (OFString*)table +- (void)insertRows: (OFArray OF_GENERIC(OFDictionary *) *)rows + intoTable: (OFString *)table { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFEnumerator *enumerator = [rows objectEnumerator]; - OFDictionary *row; - - while ((row = [enumerator nextObject]) != nil) + for (OFDictionary *row in rows) [self insertRow: row intoTable: table]; - - [pool release]; } -- (PGconn*)PG_connection +- (PGconn *)PG_connection { return _connnection; } diff --git a/src/PGResult.h b/src/PGResult.h index 93db46a..354c817 100644 --- a/src/PGResult.h +++ b/src/PGResult.h @@ -2,12 +2,18 @@ #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 diff --git a/src/PGResult.m b/src/PGResult.m index a29dcbd..b6ca303 100644 --- a/src/PGResult.m +++ b/src/PGResult.m @@ -2,12 +2,12 @@ #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]; @@ -38,7 +38,7 @@ row: (int)index]; } -- (PGresult*)PG_result +- (PGresult *)PG_result { return _result; } diff --git a/src/PGResultRow.h b/src/PGResultRow.h index d66e2d8..f1c1432 100644 --- a/src/PGResultRow.h +++ b/src/PGResultRow.h @@ -4,6 +4,8 @@ #import "PGResult.h" +OF_ASSUME_NONNULL_BEGIN + @interface PGResultRow: OFDictionary { PGResult *_result; @@ -11,8 +13,10 @@ 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 diff --git a/src/PGResultRow.m b/src/PGResultRow.m index 089ebfc..f6d7f9d 100644 --- a/src/PGResultRow.m +++ b/src/PGResultRow.m @@ -45,14 +45,14 @@ convertType(PGresult *res, int column, OFString *string) @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]; @@ -98,14 +98,14 @@ convertType(PGresult *res, int column, OFString *string) [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 @@ -113,7 +113,7 @@ convertType(PGresult *res, int column, OFString *string) } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state - objects: (id*)objects + objects: (id *)objects count: (int)count { int i, j; @@ -146,7 +146,7 @@ convertType(PGresult *res, int column, OFString *string) @end @implementation PGResultRowEnumerator -- initWithResult: (PGResult*)result +- initWithResult: (PGResult *)result row: (int)row { self = [super init]; diff --git a/src/exceptions/PGCommandFailedException.h b/src/exceptions/PGCommandFailedException.h index fbc1725..3678f1e 100644 --- a/src/exceptions/PGCommandFailedException.h +++ b/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 diff --git a/src/exceptions/PGCommandFailedException.m b/src/exceptions/PGCommandFailedException.m index 88325ca..05e1bbc 100644 --- a/src/exceptions/PGCommandFailedException.m +++ b/src/exceptions/PGCommandFailedException.m @@ -3,15 +3,15 @@ @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]; @@ -32,7 +32,7 @@ [super dealloc]; } -- (OFString*)description +- (OFString *)description { return [OFString stringWithFormat: @"A PostgreSQL command failed: %@\n" @"Command: %@", _error, _command]; diff --git a/src/exceptions/PGConnectionFailedException.h b/src/exceptions/PGConnectionFailedException.h index 6766321..42718f1 100644 --- a/src/exceptions/PGConnectionFailedException.h +++ b/src/exceptions/PGConnectionFailedException.h @@ -1,4 +1,8 @@ #import "PGException.h" +OF_ASSUME_NONNULL_BEGIN + @interface PGConnectionFailedException: PGException @end + +OF_ASSUME_NONNULL_END diff --git a/src/exceptions/PGConnectionFailedException.m b/src/exceptions/PGConnectionFailedException.m index 52f5732..3fa8a45 100644 --- a/src/exceptions/PGConnectionFailedException.m +++ b/src/exceptions/PGConnectionFailedException.m @@ -1,7 +1,7 @@ #import "PGConnectionFailedException.h" @implementation PGConnectionFailedException -- (OFString*)description +- (OFString *)description { return [OFString stringWithFormat: @"Establishing a PostgreSQL connection failed:\n%@\n" diff --git a/src/exceptions/PGException.h b/src/exceptions/PGException.h index 22d0928..f301db5 100644 --- a/src/exceptions/PGException.h +++ b/src/exceptions/PGException.h @@ -2,14 +2,18 @@ #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 diff --git a/src/exceptions/PGException.m b/src/exceptions/PGException.m index 99fb2a4..c451872 100644 --- a/src/exceptions/PGException.m +++ b/src/exceptions/PGException.m @@ -3,12 +3,12 @@ @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]; @@ -33,7 +33,7 @@ [super dealloc]; } -- (OFString*)description +- (OFString *)description { return [OFString stringWithFormat: @"A PostgreSQL operation failed: %@", _error];