ADDED src/PGConnection+Private.h Index: src/PGConnection+Private.h ================================================================== --- src/PGConnection+Private.h +++ src/PGConnection+Private.h @@ -0,0 +1,9 @@ +#import "PGConnection.h" + +OF_ASSUME_NONNULL_BEGIN + +@interface PGConnection () +- (PGconn *)PG_connection; +@end + +OF_ASSUME_NONNULL_END Index: src/PGConnection.h ================================================================== --- src/PGConnection.h +++ src/PGConnection.h @@ -6,26 +6,25 @@ OF_ASSUME_NONNULL_BEGIN @interface PGConnection: OFObject { - PGconn *_connnection; + PGconn *_connection; OFDictionary OF_GENERIC(OFString *, OFString *) *_parameters; } @property (nonatomic, copy) OFDictionary OF_GENERIC(OFString *, OFString *) *parameters; - (void)connect; - (void)reset; - (void)close; -- (PGResult *)executeCommand: (OFConstantString *)command; -- (PGResult *)executeCommand: (OFConstantString *)command +- (nullable PGResult *)executeCommand: (OFConstantString *)command; +- (nullable 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 @@ -1,6 +1,9 @@ #import "PGConnection.h" +#import "PGConnection+Private.h" +#import "PGResult.h" +#import "PGResult+Private.h" #import "PGConnectionFailedException.h" #import "PGCommandFailedException.h" @implementation PGConnection @@ -32,36 +35,36 @@ else connectionInfo = [OFMutableString stringWithFormat: @"%@=%@", key, object]; } - if ((_connnection = PQconnectdb([connectionInfo UTF8String])) == NULL) + if ((_connection = PQconnectdb([connectionInfo UTF8String])) == NULL) @throw [OFOutOfMemoryException exception]; - if (PQstatus(_connnection) == CONNECTION_BAD) + if (PQstatus(_connection) == CONNECTION_BAD) @throw [PGConnectionFailedException exceptionWithConnection: self]; objc_autoreleasePoolPop(pool); } - (void)reset { - PQreset(_connnection); + PQreset(_connection); } - (void)close { - if (_connnection != NULL) - PQfinish(_connnection); + if (_connection != NULL) + PQfinish(_connection); - _connnection = NULL; + _connection = NULL; } - (PGResult *)executeCommand: (OFConstantString *)command { - PGresult *result = PQexec(_connnection, [command UTF8String]); + PGresult *result = PQexec(_connection, [command UTF8String]); if (PQresultStatus(result) == PGRES_FATAL_ERROR) { PQclear(result); @throw [PGCommandFailedException exceptionWithConnection: self @@ -124,11 +127,11 @@ else values[i++] = [[parameter description] UTF8String]; } while ((parameter = va_arg(args, id)) != nil); - result = PQexecParams(_connnection, [command UTF8String], + result = PQexecParams(_connection, [command UTF8String], argsCount, NULL, values, NULL, NULL, 0); } @finally { [self freeMemory: values]; } @@ -192,11 +195,11 @@ [command appendFormat: @"$%zd", ++i]; } [command appendString: @")"]; - result = PQexecParams(_connnection, [command UTF8String], + result = PQexecParams(_connection, [command UTF8String], (int)count, NULL, values, NULL, NULL, 0); } @finally { [self freeMemory: values]; } @@ -220,8 +223,8 @@ intoTable: table]; } - (PGconn *)PG_connection { - return _connnection; + return _connection; } @end ADDED src/PGResult+Private.h Index: src/PGResult+Private.h ================================================================== --- src/PGResult+Private.h +++ src/PGResult+Private.h @@ -0,0 +1,11 @@ +#import "PGResult.h" + +OF_ASSUME_NONNULL_BEGIN + +@interface PGResult () ++ (instancetype)PG_resultWithResult: (PGresult *)result; +- PG_initWithResult: (PGresult *)result OF_METHOD_FAMILY(init); +- (PGresult *)PG_result; +@end + +OF_ASSUME_NONNULL_END Index: src/PGResult.h ================================================================== --- src/PGResult.h +++ src/PGResult.h @@ -8,12 +8,8 @@ @interface PGResult: OFArray OF_GENERIC(PGResultRow *) { PGresult *_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,16 @@ #import "PGResult.h" #import "PGResultRow.h" +#import "PGResultRow+Private.h" @implementation PGResult -+ PG_resultWithResult: (PGresult *)result ++ (instancetype)PG_resultWithResult: (PGresult *)result { return [[[self alloc] PG_initWithResult: result] autorelease]; } -- PG_initWithResult: (PGresult *)result +- (instancetype)PG_initWithResult: (PGresult *)result { self = [super init]; _result = result; @@ -32,14 +33,14 @@ - (id)objectAtIndex: (size_t)index { if (index > PQntuples(_result)) @throw [OFOutOfRangeException exception]; - return [PGResultRow rowWithResult: self - row: (int)index]; + return [PGResultRow PG_rowWithResult: self + row: (int)index]; } - (PGresult *)PG_result { return _result; } @end ADDED src/PGResultRow+Private.h Index: src/PGResultRow+Private.h ================================================================== --- src/PGResultRow+Private.h +++ src/PGResultRow+Private.h @@ -0,0 +1,12 @@ +#import "PGResultRow.h" + +OF_ASSUME_NONNULL_BEGIN + +@interface PGResultRow () ++ (instancetype)PG_rowWithResult: (PGResult *)result + row: (int)row; +- PG_initWithResult: (PGResult *)result + row: (int)row OF_METHOD_FAMILY(init); +@end + +OF_ASSUME_NONNULL_END Index: src/PGResultRow.h ================================================================== --- src/PGResultRow.h +++ src/PGResultRow.h @@ -4,19 +4,14 @@ #import "PGResult.h" OF_ASSUME_NONNULL_BEGIN -@interface PGResultRow: OFDictionary +@interface PGResultRow: OFDictionary OF_GENERIC(OFString *, id) { PGResult *_result; PGresult *_res; int _row; } - -+ rowWithResult: (PGResult *)result - row: (int)row; -- initWithResult: (PGResult *)result - row: (int)row; @end OF_ASSUME_NONNULL_END Index: src/PGResultRow.m ================================================================== --- src/PGResultRow.m +++ src/PGResultRow.m @@ -1,6 +1,7 @@ #import "PGResultRow.h" +#import "PGResult+Private.h" static id convertType(PGresult *res, int column, OFString *string) { switch (PQftype(res, column)) { @@ -43,12 +44,12 @@ @interface PGResultRowObjectEnumerator: PGResultRowEnumerator @end @implementation PGResultRow -+ rowWithResult: (PGResult *)result - row: (int)row ++ (instancetype)rowWithResult: (PGResult *)result + row: (int)row { return [[[self alloc] initWithResult: result row: row] autorelease]; } Index: src/exceptions/PGException.m ================================================================== --- src/exceptions/PGException.m +++ src/exceptions/PGException.m @@ -1,6 +1,7 @@ #import "PGException.h" +#import "PGConnection+Private.h" @implementation PGException @synthesize connection = _connection; + (instancetype)exceptionWithConnection: (PGConnection *)connection