Adjust to recent ObjFW changes
FossilOrigin-Name: fc8e42990e7f6476b8b806521222620bbac0496c61a91b20f9e3787fc20fdbb4
This commit is contained in:
parent
6d64ce5a68
commit
ae918f26c4
12 changed files with 88 additions and 65 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -2,12 +2,18 @@
|
|||
|
||||
#import <ObjFW/ObjFW.h>
|
||||
|
||||
@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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#import "PGException.h"
|
||||
|
||||
OF_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface PGConnectionFailedException: PGException
|
||||
@end
|
||||
|
||||
OF_ASSUME_NONNULL_END
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#import "PGConnectionFailedException.h"
|
||||
|
||||
@implementation PGConnectionFailedException
|
||||
- (OFString*)description
|
||||
- (OFString *)description
|
||||
{
|
||||
return [OFString stringWithFormat:
|
||||
@"Establishing a PostgreSQL connection failed:\n%@\n"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue