Move private methods to separate headers
Also fixes a typo and adds two missing nullability annotations. FossilOrigin-Name: 6307a381989719ad89067e1ae2cb5d454dd0b77a83cc6141785067365767e7f6
This commit is contained in:
parent
ae918f26c4
commit
308199f21e
10 changed files with 58 additions and 30 deletions
9
src/PGConnection+Private.h
Normal file
9
src/PGConnection+Private.h
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#import "PGConnection.h"
|
||||||
|
|
||||||
|
OF_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@interface PGConnection ()
|
||||||
|
- (PGconn *)PG_connection;
|
||||||
|
@end
|
||||||
|
|
||||||
|
OF_ASSUME_NONNULL_END
|
|
@ -8,7 +8,7 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface PGConnection: OFObject
|
@interface PGConnection: OFObject
|
||||||
{
|
{
|
||||||
PGconn *_connnection;
|
PGconn *_connection;
|
||||||
OFDictionary OF_GENERIC(OFString *, OFString *) *_parameters;
|
OFDictionary OF_GENERIC(OFString *, OFString *) *_parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,10 +18,9 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
- (void)connect;
|
- (void)connect;
|
||||||
- (void)reset;
|
- (void)reset;
|
||||||
- (void)close;
|
- (void)close;
|
||||||
- (PGResult *)executeCommand: (OFConstantString *)command;
|
- (nullable PGResult *)executeCommand: (OFConstantString *)command;
|
||||||
- (PGResult *)executeCommand: (OFConstantString *)command
|
- (nullable PGResult *)executeCommand: (OFConstantString *)command
|
||||||
parameters: (id)firstParameter, ... OF_SENTINEL;
|
parameters: (id)firstParameter, ... OF_SENTINEL;
|
||||||
- (PGconn *)PG_connection;
|
|
||||||
- (void)insertRow: (OFDictionary *)row
|
- (void)insertRow: (OFDictionary *)row
|
||||||
intoTable: (OFString *)table;
|
intoTable: (OFString *)table;
|
||||||
- (void)insertRows: (OFArray OF_GENERIC(OFDictionary *) *)rows
|
- (void)insertRows: (OFArray OF_GENERIC(OFDictionary *) *)rows
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
#import "PGConnection.h"
|
#import "PGConnection.h"
|
||||||
|
#import "PGConnection+Private.h"
|
||||||
|
#import "PGResult.h"
|
||||||
|
#import "PGResult+Private.h"
|
||||||
|
|
||||||
#import "PGConnectionFailedException.h"
|
#import "PGConnectionFailedException.h"
|
||||||
#import "PGCommandFailedException.h"
|
#import "PGCommandFailedException.h"
|
||||||
|
@ -34,10 +37,10 @@
|
||||||
@"%@=%@", key, object];
|
@"%@=%@", key, object];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((_connnection = PQconnectdb([connectionInfo UTF8String])) == NULL)
|
if ((_connection = PQconnectdb([connectionInfo UTF8String])) == NULL)
|
||||||
@throw [OFOutOfMemoryException exception];
|
@throw [OFOutOfMemoryException exception];
|
||||||
|
|
||||||
if (PQstatus(_connnection) == CONNECTION_BAD)
|
if (PQstatus(_connection) == CONNECTION_BAD)
|
||||||
@throw [PGConnectionFailedException
|
@throw [PGConnectionFailedException
|
||||||
exceptionWithConnection: self];
|
exceptionWithConnection: self];
|
||||||
|
|
||||||
|
@ -46,20 +49,20 @@
|
||||||
|
|
||||||
- (void)reset
|
- (void)reset
|
||||||
{
|
{
|
||||||
PQreset(_connnection);
|
PQreset(_connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)close
|
- (void)close
|
||||||
{
|
{
|
||||||
if (_connnection != NULL)
|
if (_connection != NULL)
|
||||||
PQfinish(_connnection);
|
PQfinish(_connection);
|
||||||
|
|
||||||
_connnection = NULL;
|
_connection = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (PGResult *)executeCommand: (OFConstantString *)command
|
- (PGResult *)executeCommand: (OFConstantString *)command
|
||||||
{
|
{
|
||||||
PGresult *result = PQexec(_connnection, [command UTF8String]);
|
PGresult *result = PQexec(_connection, [command UTF8String]);
|
||||||
|
|
||||||
if (PQresultStatus(result) == PGRES_FATAL_ERROR) {
|
if (PQresultStatus(result) == PGRES_FATAL_ERROR) {
|
||||||
PQclear(result);
|
PQclear(result);
|
||||||
|
@ -126,7 +129,7 @@
|
||||||
UTF8String];
|
UTF8String];
|
||||||
} while ((parameter = va_arg(args, id)) != nil);
|
} while ((parameter = va_arg(args, id)) != nil);
|
||||||
|
|
||||||
result = PQexecParams(_connnection, [command UTF8String],
|
result = PQexecParams(_connection, [command UTF8String],
|
||||||
argsCount, NULL, values, NULL, NULL, 0);
|
argsCount, NULL, values, NULL, NULL, 0);
|
||||||
} @finally {
|
} @finally {
|
||||||
[self freeMemory: values];
|
[self freeMemory: values];
|
||||||
|
@ -194,7 +197,7 @@
|
||||||
|
|
||||||
[command appendString: @")"];
|
[command appendString: @")"];
|
||||||
|
|
||||||
result = PQexecParams(_connnection, [command UTF8String],
|
result = PQexecParams(_connection, [command UTF8String],
|
||||||
(int)count, NULL, values, NULL, NULL, 0);
|
(int)count, NULL, values, NULL, NULL, 0);
|
||||||
} @finally {
|
} @finally {
|
||||||
[self freeMemory: values];
|
[self freeMemory: values];
|
||||||
|
@ -222,6 +225,6 @@
|
||||||
|
|
||||||
- (PGconn *)PG_connection
|
- (PGconn *)PG_connection
|
||||||
{
|
{
|
||||||
return _connnection;
|
return _connection;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
11
src/PGResult+Private.h
Normal file
11
src/PGResult+Private.h
Normal 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
|
|
@ -10,10 +10,6 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
{
|
{
|
||||||
PGresult *_result;
|
PGresult *_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (instancetype)PG_resultWithResult: (PGresult *)result;
|
|
||||||
- PG_initWithResult: (PGresult *)result OF_METHOD_FAMILY(init);
|
|
||||||
- (PGresult *)PG_result;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
OF_ASSUME_NONNULL_END
|
OF_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
#import "PGResult.h"
|
#import "PGResult.h"
|
||||||
#import "PGResultRow.h"
|
#import "PGResultRow.h"
|
||||||
|
#import "PGResultRow+Private.h"
|
||||||
|
|
||||||
@implementation PGResult
|
@implementation PGResult
|
||||||
+ PG_resultWithResult: (PGresult *)result
|
+ (instancetype)PG_resultWithResult: (PGresult *)result
|
||||||
{
|
{
|
||||||
return [[[self alloc] PG_initWithResult: result] autorelease];
|
return [[[self alloc] PG_initWithResult: result] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
- PG_initWithResult: (PGresult *)result
|
- (instancetype)PG_initWithResult: (PGresult *)result
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@
|
||||||
if (index > PQntuples(_result))
|
if (index > PQntuples(_result))
|
||||||
@throw [OFOutOfRangeException exception];
|
@throw [OFOutOfRangeException exception];
|
||||||
|
|
||||||
return [PGResultRow rowWithResult: self
|
return [PGResultRow PG_rowWithResult: self
|
||||||
row: (int)index];
|
row: (int)index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/PGResultRow+Private.h
Normal file
12
src/PGResultRow+Private.h
Normal 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
|
|
@ -6,17 +6,12 @@
|
||||||
|
|
||||||
OF_ASSUME_NONNULL_BEGIN
|
OF_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface PGResultRow: OFDictionary
|
@interface PGResultRow: OFDictionary OF_GENERIC(OFString *, id)
|
||||||
{
|
{
|
||||||
PGResult *_result;
|
PGResult *_result;
|
||||||
PGresult *_res;
|
PGresult *_res;
|
||||||
int _row;
|
int _row;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ rowWithResult: (PGResult *)result
|
|
||||||
row: (int)row;
|
|
||||||
- initWithResult: (PGResult *)result
|
|
||||||
row: (int)row;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
OF_ASSUME_NONNULL_END
|
OF_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#import "PGResultRow.h"
|
#import "PGResultRow.h"
|
||||||
|
#import "PGResult+Private.h"
|
||||||
|
|
||||||
static id
|
static id
|
||||||
convertType(PGresult *res, int column, OFString *string)
|
convertType(PGresult *res, int column, OFString *string)
|
||||||
|
@ -45,7 +46,7 @@ convertType(PGresult *res, int column, OFString *string)
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation PGResultRow
|
@implementation PGResultRow
|
||||||
+ rowWithResult: (PGResult *)result
|
+ (instancetype)rowWithResult: (PGResult *)result
|
||||||
row: (int)row
|
row: (int)row
|
||||||
{
|
{
|
||||||
return [[[self alloc] initWithResult: result
|
return [[[self alloc] initWithResult: result
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#import "PGException.h"
|
#import "PGException.h"
|
||||||
|
#import "PGConnection+Private.h"
|
||||||
|
|
||||||
@implementation PGException
|
@implementation PGException
|
||||||
@synthesize connection = _connection;
|
@synthesize connection = _connection;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue