Move private methods to separate headers

Also fixes a typo and adds two missing nullability annotations.

FossilOrigin-Name: 6307a381989719ad89067e1ae2cb5d454dd0b77a83cc6141785067365767e7f6
This commit is contained in:
Jonathan Schleifer 2017-05-10 23:46:04 +00:00
parent ae918f26c4
commit 308199f21e
10 changed files with 58 additions and 30 deletions

View file

@ -0,0 +1,9 @@
#import "PGConnection.h"
OF_ASSUME_NONNULL_BEGIN
@interface PGConnection ()
- (PGconn *)PG_connection;
@end
OF_ASSUME_NONNULL_END

View file

@ -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

View file

@ -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

11
src/PGResult+Private.h Normal file
View file

@ -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

View file

@ -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

View file

@ -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

12
src/PGResultRow+Private.h Normal file
View file

@ -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

View file

@ -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

View file

@ -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];

View file

@ -1,4 +1,5 @@
#import "PGException.h"
#import "PGConnection+Private.h"
@implementation PGException
@synthesize connection = _connection;