Overview
Comment: | Prefix all ivars with an underscore. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
8c8a4313228bba7114d582a6802a2df5 |
User & Date: | js on 2013-02-13 23:40:59 |
Other Links: | manifest | tags |
Context
2013-02-14
| ||
23:30 | Improve Makefile. check-in: f069ee6cec user: js tags: trunk | |
2013-02-13
| ||
23:40 | Prefix all ivars with an underscore. check-in: 8c8a431322 user: js tags: trunk | |
2013-01-03
| ||
19:35 | Fix missing dealloc. check-in: 7ee61bb762 user: js tags: trunk | |
Changes
Modified PGConnection.h from [ba8da0f686] to [fdaa72966b].
1 2 3 4 5 6 7 8 | #include <libpq-fe.h> #import <ObjFW/ObjFW.h> #import "PGResult.h" @interface PGConnection: OFObject { | | | | 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" @interface PGConnection: OFObject { PGconn *_connnection; OFDictionary *_parameters; } #ifdef OF_HAVE_PROPERTIES @property (copy) OFDictionary *parameters; #endif - (void)setParameters: (OFDictionary*)parameters; |
︙ | ︙ |
Modified PGConnection.m from [19a3e925ca] to [215cf6715b].
1 2 3 4 5 6 7 8 | #import "PGConnection.h" #import "PGConnectionFailedException.h" #import "PGCommandFailedException.h" @implementation PGConnection - (void)dealloc { | | | | | | | | | | | | | | | | | | 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 31 32 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 | #import "PGConnection.h" #import "PGConnectionFailedException.h" #import "PGCommandFailedException.h" @implementation PGConnection - (void)dealloc { [_parameters release]; if (_connnection != NULL) PQfinish(_connnection); [super dealloc]; } - (void)setParameters: (OFDictionary*)parameters { OF_SETTER(_parameters, parameters, YES, YES) } - (OFDictionary*)parameters { OF_GETTER(_parameters, YES) } - (void)connect { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFEnumerator *keyEnumerator = [_parameters keyEnumerator]; OFEnumerator *objectEnumerator = [_parameters objectEnumerator]; OFMutableString *connectionInfo = nil; OFString *key, *object; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { if (connectionInfo != nil) [connectionInfo appendFormat: @" %@=%@", key, object]; else connectionInfo = [OFMutableString stringWithFormat: @"%@=%@", key, object]; } if ((_connnection = PQconnectdb([connectionInfo UTF8String])) == NULL) @throw [OFOutOfMemoryException exceptionWithClass: [self class]]; if (PQstatus(_connnection) == CONNECTION_BAD) @throw [PGConnectionFailedException exceptionWithClass: [self class] connection: self]; [pool release]; } - (void)reset { PQreset(_connnection); } - (PGResult*)executeCommand: (OFConstantString*)command { PGresult *result = PQexec(_connnection, [command UTF8String]); if (PQresultStatus(result) == PGRES_FATAL_ERROR) { PQclear(result); @throw [PGCommandFailedException exceptionWithClass: [self class] connection: self command: command]; |
︙ | ︙ | |||
123 124 125 126 127 128 129 | } else if ([parameter isKindOfClass: [OFNull class]]) values[i++] = NULL; else values[i++] = [[parameter description] UTF8String]; } while ((parameter = va_arg(args, id)) != nil); | | | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | } else if ([parameter isKindOfClass: [OFNull class]]) values[i++] = NULL; else values[i++] = [[parameter description] UTF8String]; } while ((parameter = va_arg(args, id)) != nil); result = PQexecParams(_connnection, [command UTF8String], argsCount, NULL, values, NULL, NULL, 0); } @finally { [self freeMemory: values]; } [pool release]; |
︙ | ︙ | |||
192 193 194 195 196 197 198 | values[i] = [value UTF8String]; [command appendFormat: @"$%zd", ++i]; } [command appendString: @")"]; | | | | 192 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(_connnection, [command UTF8String], (int)count, NULL, values, NULL, NULL, 0); } @finally { [self freeMemory: values]; } [pool release]; if (PQresultStatus(result) != PGRES_COMMAND_OK) { |
︙ | ︙ | |||
227 228 229 230 231 232 233 | intoTable: table]; [pool release]; } - (PGconn*)PG_connection { | | | 227 228 229 230 231 232 233 234 235 236 | intoTable: table]; [pool release]; } - (PGconn*)PG_connection { return _connnection; } @end |
Modified PGResult.h from [91d3ffeec3] to [6294089c40].
1 2 3 4 5 6 | #include <libpq-fe.h> #import <ObjFW/ObjFW.h> @interface PGResult: OFArray { | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <libpq-fe.h> #import <ObjFW/ObjFW.h> @interface PGResult: OFArray { PGresult *_result; } + PG_resultWithResult: (PGresult*)result; - PG_initWithResult: (PGresult*)result; - (PGresult*)PG_result; @end |
Modified PGResult.m from [8d3497daef] to [3b43b74b64].
1 2 3 4 5 6 7 8 9 | #import "PGResult.h" #import "PGResultRow.h" @implementation PGResult + PG_resultWithResult: (PGresult*)result { return [[[self alloc] PG_initWithResult: result] autorelease]; } | | | | | | | | | 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #import "PGResult.h" #import "PGResultRow.h" @implementation PGResult + PG_resultWithResult: (PGresult*)result { return [[[self alloc] PG_initWithResult: result] autorelease]; } - PG_initWithResult: (PGresult*)result { self = [super init]; _result = result; return self; } - (void)dealloc { if (_result != NULL) PQclear(_result); [super dealloc]; } - (size_t)count { return PQntuples(_result); } - (id)objectAtIndex: (size_t)index { if (index > PQntuples(_result)) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; return [PGResultRow rowWithResult: self row: (int)index]; } - (PGresult*)PG_result { return _result; } @end |
Modified PGResultRow.h from [da0166d00f] to [f714b4a0e3].
1 2 3 4 5 6 7 8 | #include <libpq-fe.h> #import <ObjFW/ObjFW.h> #import "PGResult.h" @interface PGResultRow: OFDictionary { | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <libpq-fe.h> #import <ObjFW/ObjFW.h> #import "PGResult.h" @interface PGResultRow: OFDictionary { PGResult *_result; PGresult *_res; int _row; } + rowWithResult: (PGResult*)result row: (int)row; - initWithResult: (PGResult*)result row: (int)row; @end |
Modified PGResultRow.m from [fce9f9ad1f] to [bf3d3626a7].
1 2 3 | #import "PGResultRow.h" static id | | | | | > | > | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 31 32 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | #import "PGResultRow.h" static id convert_type(PGresult *res, int column, OFString *string) { switch (PQftype(res, column)) { case 16: /* BOOLOID */ if ([string isEqual: @"t"]) return [OFNumber numberWithBool: YES]; else return [OFNumber numberWithBool: NO]; case 21: /* INT2OID */ return [OFNumber numberWithInt16: (int16_t)[string decimalValue]]; case 23: /* INT4OID */ return [OFNumber numberWithInt32: (int32_t)[string decimalValue]]; case 20: /* INT8OID */ return [OFNumber numberWithInt64: (int64_t)[string decimalValue]]; case 700: /* FLOAT4OID */ return [OFNumber numberWithFloat: [string floatValue]]; case 701: /* FLOAT8OID */ return [OFNumber numberWithDouble: [string doubleValue]]; } return string; } @interface PGResultRowEnumerator: OFEnumerator { PGResult *_result; PGresult *_res; int _row, _pos, _count; } - initWithResult: (PGResult*)result row: (int)row; @end @interface PGResultRowKeyEnumerator: PGResultRowEnumerator @end @interface PGResultRowObjectEnumerator: PGResultRowEnumerator @end @implementation PGResultRow + rowWithResult: (PGResult*)result row: (int)row { return [[[self alloc] initWithResult: result row: row] autorelease]; } - initWithResult: (PGResult*)result row: (int)row { self = [super init]; _result = [result retain]; _res = [result PG_result]; _row = row; return self; } - (void)dealloc { [_result release]; [super dealloc]; } - (size_t)count { int i, count, fields = PQnfields(_res); for (i = count = 0; i < fields; i++) if (!PQgetisnull(_res, _row, i)) count++; return count; } - (id)objectForKey: (id)key { int column; if ([key isKindOfClass: [OFNumber class]]) column = [key intValue]; else column = PQfnumber(_res, [key UTF8String]); if (PQgetisnull(_res, _row, column)) return nil; return convert_type(_res, column, [OFString stringWithUTF8String: PQgetvalue(_res, _row, column)]); } - (OFEnumerator*)keyEnumerator { return [[[PGResultRowKeyEnumerator alloc] initWithResult: _result row: _row] autorelease]; } - (OFEnumerator*)objectEnumerator { return [[[PGResultRowObjectEnumerator alloc] initWithResult: _result row: _row] autorelease]; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects count: (int)count { int i, j; if (state->extra[0] == 0) { state->extra[0] = 1; state->extra[1] = PQnfields(_res); } if (count > SIZE_MAX - state->state) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; if (state->state + count > state->extra[1]) count = state->extra[1] - state->state; for (i = j = 0; i < count; i++) { if (PQgetisnull(_res, _row, state->state + i)) continue; objects[j++] = [OFString stringWithUTF8String: PQfname(_res, state->state + i)]; } state->state += count; state->itemsPtr = objects; state->mutationsPtr = (unsigned long*)self; return j; } @end @implementation PGResultRowEnumerator - initWithResult: (PGResult*)result row: (int)row { self = [super init]; _result = [result retain]; _res = [result PG_result]; _row = row; _count = PQnfields(_res); return self; } - (void)dealloc { [_result release]; [super dealloc]; } - (void)reset { _pos = 0; } @end @implementation PGResultRowKeyEnumerator - (id)nextObject { if (_pos >= _count) return nil; while (_pos < _count && PQgetisnull(_res, _row, _pos)) _pos++; if (_pos >= _count) return nil; return [OFString stringWithUTF8String: PQfname(_res, _pos++)]; } @end @implementation PGResultRowObjectEnumerator - (id)nextObject { if (_pos >= _count) return nil; while (_pos < _count && PQgetisnull(_res, _row, _pos)) _pos++; if (_pos >= _count) return nil; return convert_type(_res, _pos, [OFString stringWithUTF8String: PQgetvalue(_res, _row, _pos++)]); } @end |
Modified exceptions/PGCommandFailedException.h from [edfb7baa0e] to [bd6baa8db9].
1 2 3 4 | #import "PGException.h" @interface PGCommandFailedException: PGException { | | | 1 2 3 4 5 6 7 8 9 10 11 12 | #import "PGException.h" @interface PGCommandFailedException: PGException { OFString *_command; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy, nonatomic) OFString *command; #endif + exceptionWithClass: (Class)class_ |
︙ | ︙ |
Modified exceptions/PGCommandFailedException.m from [aa429f7580] to [6309f695e9].
1 2 3 4 5 6 7 8 9 10 11 12 | #import "PGCommandFailedException.h" @implementation PGCommandFailedException + exceptionWithClass: (Class)class connection: (PGConnection*)connection command: (OFString*)command { return [[[self alloc] initWithClass: class connection: connection command: command] autorelease]; } | | | | | | | | < < | < | | < | | 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #import "PGCommandFailedException.h" @implementation PGCommandFailedException + exceptionWithClass: (Class)class connection: (PGConnection*)connection command: (OFString*)command { return [[[self alloc] initWithClass: class connection: connection command: command] autorelease]; } - initWithClass: (Class)class connection: (PGConnection*)connection command: (OFString*)command { self = [super initWithClass: class connection: connection]; @try { _command = [command copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_command release]; [super dealloc]; } - (OFString*)description { return [OFString stringWithFormat: @"A PostgreSQL command in class %@ failed: %s\nCommand: %@", [self inClass], PQerrorMessage([_connection PG_connection]), _command]; } - (OFString*)command { OF_GETTER(_command, NO) } @end |
Modified exceptions/PGConnectionFailedException.m from [9e57dfeee0] to [de24e68bdc].
1 2 3 4 5 | #import "PGConnectionFailedException.h" @implementation PGConnectionFailedException - (OFString*)description { | < | < < < < < | | | < < < | 1 2 3 4 5 6 7 8 9 10 11 12 | #import "PGConnectionFailedException.h" @implementation PGConnectionFailedException - (OFString*)description { return [OFString stringWithFormat: @"Establishing a PostgreSQL connection in class %@ failed:\n%s\n" "Parameters: %@", [self inClass], PQerrorMessage([_connection PG_connection]), [_connection parameters]]; } @end |
Modified exceptions/PGException.h from [adaf1d5292] to [c9366d7488].
1 2 3 4 5 6 | #import <ObjFW/ObjFW.h> #import "PGConnection.h" @interface PGException: OFException { | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #import <ObjFW/ObjFW.h> #import "PGConnection.h" @interface PGException: OFException { PGConnection *_connection; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) PGConnection *connection; #endif + exceptionWithClass: (Class)class_ |
︙ | ︙ |
Modified exceptions/PGException.m from [0dae36f3c9] to [603d30aa28].
1 2 3 4 5 6 7 8 9 10 | #import "PGException.h" @implementation PGException + exceptionWithClass: (Class)class connection: (PGConnection*)connection { return [[[self alloc] initWithClass: class connection: connection] autorelease]; } | | | | | | < < | < | | < < | | 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 31 32 33 34 35 36 37 38 39 | #import "PGException.h" @implementation PGException + exceptionWithClass: (Class)class connection: (PGConnection*)connection { return [[[self alloc] initWithClass: class connection: connection] autorelease]; } - initWithClass: (Class)class connection: (PGConnection*)connection { self = [super initWithClass: class]; _connection = [connection retain]; return self; } - (void)dealloc { [_connection release]; [super dealloc]; } - (OFString*)description { return [OFString stringWithFormat: @"A PostgreSQL operation in class %@ failed: %s", [self inClass], PQerrorMessage([_connection PG_connection])]; } - (PGConnection*)connection { OF_GETTER(_connection, NO) } @end |