Overview
Comment: | Move private methods to separate headers
Also fixes a typo and adds two missing nullability annotations. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
6307a381989719ad89067e1ae2cb5d45 |
User & Date: | js on 2017-05-10 23:46:05 |
Other Links: | manifest | tags |
Context
2017-05-10
| ||
23:51 | Do not depend on object literals for tests check-in: 2105581c29 user: js tags: trunk | |
23:46 | Move private methods to separate headers check-in: 6307a38198 user: js tags: trunk | |
2017-05-09
| ||
23:19 | Adjust to recent ObjFW changes check-in: fc8e42990e user: js tags: trunk | |
Changes
Added src/PGConnection+Private.h version [1ea31d7eef].
Modified src/PGConnection.h from [89f43193e6] to [6e9f843adc].
1 2 3 4 5 6 7 8 9 10 | #include <libpq-fe.h> #import <ObjFW/ObjFW.h> #import "PGResult.h" OF_ASSUME_NONNULL_BEGIN @interface PGConnection: OFObject { | | | | < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <libpq-fe.h> #import <ObjFW/ObjFW.h> #import "PGResult.h" OF_ASSUME_NONNULL_BEGIN @interface PGConnection: OFObject { PGconn *_connection; OFDictionary OF_GENERIC(OFString *, OFString *) *_parameters; } @property (nonatomic, copy) OFDictionary OF_GENERIC(OFString *, OFString *) *parameters; - (void)connect; - (void)reset; - (void)close; - (nullable PGResult *)executeCommand: (OFConstantString *)command; - (nullable PGResult *)executeCommand: (OFConstantString *)command parameters: (id)firstParameter, ... OF_SENTINEL; - (void)insertRow: (OFDictionary *)row intoTable: (OFString *)table; - (void)insertRows: (OFArray OF_GENERIC(OFDictionary *) *)rows intoTable: (OFString *)table; @end OF_ASSUME_NONNULL_END |
Modified src/PGConnection.m from [12a5dca2c4] to [b625cd9199].
1 2 3 4 5 6 7 8 | #import "PGConnection.h" #import "PGConnectionFailedException.h" #import "PGCommandFailedException.h" @implementation PGConnection @synthesize parameters = _parameters; | > > > | 1 2 3 4 5 6 7 8 9 10 11 | #import "PGConnection.h" #import "PGConnection+Private.h" #import "PGResult.h" #import "PGResult+Private.h" #import "PGConnectionFailedException.h" #import "PGCommandFailedException.h" @implementation PGConnection @synthesize parameters = _parameters; |
︙ | ︙ | |||
30 31 32 33 34 35 36 | if (connectionInfo != nil) [connectionInfo appendFormat: @" %@=%@", key, object]; else connectionInfo = [OFMutableString stringWithFormat: @"%@=%@", key, object]; } | | | | | | | | | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | if (connectionInfo != nil) [connectionInfo appendFormat: @" %@=%@", key, object]; else connectionInfo = [OFMutableString stringWithFormat: @"%@=%@", key, object]; } if ((_connection = PQconnectdb([connectionInfo UTF8String])) == NULL) @throw [OFOutOfMemoryException exception]; if (PQstatus(_connection) == CONNECTION_BAD) @throw [PGConnectionFailedException exceptionWithConnection: self]; objc_autoreleasePoolPop(pool); } - (void)reset { PQreset(_connection); } - (void)close { if (_connection != NULL) PQfinish(_connection); _connection = NULL; } - (PGResult *)executeCommand: (OFConstantString *)command { PGresult *result = PQexec(_connection, [command UTF8String]); if (PQresultStatus(result) == PGRES_FATAL_ERROR) { PQclear(result); @throw [PGCommandFailedException exceptionWithConnection: self command: command]; } |
︙ | ︙ | |||
122 123 124 125 126 127 128 | } else if ([parameter isKindOfClass: [OFNull class]]) values[i++] = NULL; else values[i++] = [[parameter description] UTF8String]; } while ((parameter = va_arg(args, id)) != nil); | | | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | } else if ([parameter isKindOfClass: [OFNull class]]) values[i++] = NULL; else values[i++] = [[parameter description] UTF8String]; } while ((parameter = va_arg(args, id)) != nil); result = PQexecParams(_connection, [command UTF8String], argsCount, NULL, values, NULL, NULL, 0); } @finally { [self freeMemory: values]; } objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
190 191 192 193 194 195 196 | values[i] = [value UTF8String]; [command appendFormat: @"$%zd", ++i]; } [command appendString: @")"]; | | | 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | values[i] = [value UTF8String]; [command appendFormat: @"$%zd", ++i]; } [command appendString: @")"]; result = PQexecParams(_connection, [command UTF8String], (int)count, NULL, values, NULL, NULL, 0); } @finally { [self freeMemory: values]; } objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
218 219 220 221 222 223 224 | for (OFDictionary *row in rows) [self insertRow: row intoTable: table]; } - (PGconn *)PG_connection { | | | 221 222 223 224 225 226 227 228 229 230 | for (OFDictionary *row in rows) [self insertRow: row intoTable: table]; } - (PGconn *)PG_connection { return _connection; } @end |
Added src/PGResult+Private.h version [1af74e4c75].
Modified src/PGResult.h from [b70e0a8f15] to [421ad0603f].
1 2 3 4 5 6 7 8 9 10 11 12 | #include <libpq-fe.h> #import <ObjFW/ObjFW.h> OF_ASSUME_NONNULL_BEGIN @class PGResultRow; @interface PGResult: OFArray OF_GENERIC(PGResultRow *) { PGresult *_result; } | < < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <libpq-fe.h> #import <ObjFW/ObjFW.h> OF_ASSUME_NONNULL_BEGIN @class PGResultRow; @interface PGResult: OFArray OF_GENERIC(PGResultRow *) { PGresult *_result; } @end OF_ASSUME_NONNULL_END |
Modified src/PGResult.m from [1b1566e654] to [b80f854ff0].
1 2 3 4 | #import "PGResult.h" #import "PGResultRow.h" @implementation PGResult | > | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #import "PGResult.h" #import "PGResultRow.h" #import "PGResultRow+Private.h" @implementation PGResult + (instancetype)PG_resultWithResult: (PGresult *)result { return [[[self alloc] PG_initWithResult: result] autorelease]; } - (instancetype)PG_initWithResult: (PGresult *)result { self = [super init]; _result = result; return self; } |
︙ | ︙ | |||
30 31 32 33 34 35 36 | } - (id)objectAtIndex: (size_t)index { if (index > PQntuples(_result)) @throw [OFOutOfRangeException exception]; | | | | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | } - (id)objectAtIndex: (size_t)index { if (index > PQntuples(_result)) @throw [OFOutOfRangeException exception]; return [PGResultRow PG_rowWithResult: self row: (int)index]; } - (PGresult *)PG_result { return _result; } @end |
Added src/PGResultRow+Private.h version [052a63f6f7].
Modified src/PGResultRow.h from [4c4b6ee6a8] to [c389ce6aac].
1 2 3 4 5 6 7 8 | #include <libpq-fe.h> #import <ObjFW/ObjFW.h> #import "PGResult.h" OF_ASSUME_NONNULL_BEGIN | | < < < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <libpq-fe.h> #import <ObjFW/ObjFW.h> #import "PGResult.h" OF_ASSUME_NONNULL_BEGIN @interface PGResultRow: OFDictionary OF_GENERIC(OFString *, id) { PGResult *_result; PGresult *_res; int _row; } @end OF_ASSUME_NONNULL_END |
Modified src/PGResultRow.m from [2a3cc24231] to [b6c2a37189].
1 2 3 4 5 6 7 8 | #import "PGResultRow.h" static id convertType(PGresult *res, int column, OFString *string) { switch (PQftype(res, column)) { case 16: /* BOOLOID */ if ([string isEqual: @"t"]) | > | 1 2 3 4 5 6 7 8 9 | #import "PGResultRow.h" #import "PGResult+Private.h" static id convertType(PGresult *res, int column, OFString *string) { switch (PQftype(res, column)) { case 16: /* BOOLOID */ if ([string isEqual: @"t"]) |
︙ | ︙ | |||
41 42 43 44 45 46 47 | @interface PGResultRowKeyEnumerator: PGResultRowEnumerator @end @interface PGResultRowObjectEnumerator: PGResultRowEnumerator @end @implementation PGResultRow | | | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | @interface PGResultRowKeyEnumerator: PGResultRowEnumerator @end @interface PGResultRowObjectEnumerator: PGResultRowEnumerator @end @implementation PGResultRow + (instancetype)rowWithResult: (PGResult *)result row: (int)row { return [[[self alloc] initWithResult: result row: row] autorelease]; } - initWithResult: (PGResult *)result row: (int)row |
︙ | ︙ |
Modified src/exceptions/PGException.m from [f39a379181] to [0525cbb5f6].
1 2 3 4 5 6 7 8 | #import "PGException.h" @implementation PGException @synthesize connection = _connection; + (instancetype)exceptionWithConnection: (PGConnection *)connection { return [[[self alloc] initWithConnection: connection] autorelease]; | > | 1 2 3 4 5 6 7 8 9 | #import "PGException.h" #import "PGConnection+Private.h" @implementation PGException @synthesize connection = _connection; + (instancetype)exceptionWithConnection: (PGConnection *)connection { return [[[self alloc] initWithConnection: connection] autorelease]; |
︙ | ︙ |