Adjust to recent ObjFW changes

FossilOrigin-Name: fc8e42990e7f6476b8b806521222620bbac0496c61a91b20f9e3787fc20fdbb4
This commit is contained in:
Jonathan Schleifer 2017-05-09 23:19:19 +00:00
parent 6d64ce5a68
commit ae918f26c4
12 changed files with 88 additions and 65 deletions

View file

@ -4,13 +4,16 @@
#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;
@ -21,6 +24,8 @@
- (PGconn *)PG_connection;
- (void)insertRow: (OFDictionary *)row
intoTable: (OFString *)table;
- (void)insertRows: (OFArray*)rows
- (void)insertRows: (OFArray OF_GENERIC(OFDictionary *) *)rows
intoTable: (OFString *)table;
@end
OF_ASSUME_NONNULL_END

View file

@ -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
@ -83,7 +85,7 @@
- (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:
@ -149,7 +151,7 @@
- (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,18 +212,12 @@
PQclear(result);
}
- (void)insertRows: (OFArray*)rows
- (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

View file

@ -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;
+ (instancetype)PG_resultWithResult: (PGresult *)result;
- PG_initWithResult: (PGresult *)result OF_METHOD_FAMILY(init);
- (PGresult *)PG_result;
@end
OF_ASSUME_NONNULL_END

View file

@ -4,6 +4,8 @@
#import "PGResult.h"
OF_ASSUME_NONNULL_BEGIN
@interface PGResultRow: OFDictionary
{
PGResult *_result;
@ -16,3 +18,5 @@
- initWithResult: (PGResult *)result
row: (int)row;
@end
OF_ASSUME_NONNULL_END

View file

@ -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;
@end
OF_ASSUME_NONNULL_END

View file

@ -1,4 +1,8 @@
#import "PGException.h"
OF_ASSUME_NONNULL_BEGIN
@interface PGConnectionFailedException: PGException
@end
OF_ASSUME_NONNULL_END

View file

@ -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;
@end
OF_ASSUME_NONNULL_END