diff --git a/src/PGConnection+Private.h b/src/PGConnection+Private.h new file mode 100644 index 0000000..5c64703 --- /dev/null +++ b/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 diff --git a/src/PGConnection.h b/src/PGConnection.h index 365a95a..81ae498 100644 --- a/src/PGConnection.h +++ b/src/PGConnection.h @@ -8,7 +8,7 @@ OF_ASSUME_NONNULL_BEGIN @interface PGConnection: OFObject { - PGconn *_connnection; + PGconn *_connection; OFDictionary OF_GENERIC(OFString *, OFString *) *_parameters; } @@ -18,10 +18,9 @@ OF_ASSUME_NONNULL_BEGIN - (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 diff --git a/src/PGConnection.m b/src/PGConnection.m index 88a4cb2..17b2b5e 100644 --- a/src/PGConnection.m +++ b/src/PGConnection.m @@ -1,4 +1,7 @@ #import "PGConnection.h" +#import "PGConnection+Private.h" +#import "PGResult.h" +#import "PGResult+Private.h" #import "PGConnectionFailedException.h" #import "PGCommandFailedException.h" @@ -34,10 +37,10 @@ @"%@=%@", 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]; @@ -46,20 +49,20 @@ - (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); @@ -126,7 +129,7 @@ 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]; @@ -194,7 +197,7 @@ [command appendString: @")"]; - result = PQexecParams(_connnection, [command UTF8String], + result = PQexecParams(_connection, [command UTF8String], (int)count, NULL, values, NULL, NULL, 0); } @finally { [self freeMemory: values]; @@ -222,6 +225,6 @@ - (PGconn *)PG_connection { - return _connnection; + return _connection; } @end diff --git a/src/PGResult+Private.h b/src/PGResult+Private.h new file mode 100644 index 0000000..bf08c17 --- /dev/null +++ b/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 diff --git a/src/PGResult.h b/src/PGResult.h index 354c817..c2a71f8 100644 --- a/src/PGResult.h +++ b/src/PGResult.h @@ -10,10 +10,6 @@ OF_ASSUME_NONNULL_BEGIN { PGresult *_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 b6ca303..daeea81 100644 --- a/src/PGResult.m +++ b/src/PGResult.m @@ -1,13 +1,14 @@ #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]; @@ -34,8 +35,8 @@ 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 diff --git a/src/PGResultRow+Private.h b/src/PGResultRow+Private.h new file mode 100644 index 0000000..31b8eb6 --- /dev/null +++ b/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 diff --git a/src/PGResultRow.h b/src/PGResultRow.h index f1c1432..be481fa 100644 --- a/src/PGResultRow.h +++ b/src/PGResultRow.h @@ -6,17 +6,12 @@ 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 diff --git a/src/PGResultRow.m b/src/PGResultRow.m index f6d7f9d..3920539 100644 --- a/src/PGResultRow.m +++ b/src/PGResultRow.m @@ -1,4 +1,5 @@ #import "PGResultRow.h" +#import "PGResult+Private.h" static id convertType(PGresult *res, int column, OFString *string) @@ -45,8 +46,8 @@ convertType(PGresult *res, int column, OFString *string) @end @implementation PGResultRow -+ rowWithResult: (PGResult *)result - row: (int)row ++ (instancetype)rowWithResult: (PGResult *)result + row: (int)row { return [[[self alloc] initWithResult: result row: row] autorelease]; diff --git a/src/exceptions/PGException.m b/src/exceptions/PGException.m index c451872..0f8a468 100644 --- a/src/exceptions/PGException.m +++ b/src/exceptions/PGException.m @@ -1,4 +1,5 @@ #import "PGException.h" +#import "PGConnection+Private.h" @implementation PGException @synthesize connection = _connection;