Overview
Comment: | Implement fast enumeration. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
2da674855b3d179b7524f02132638c40 |
User & Date: | js 2012-10-30 22:33:40 |
Context
2013-01-03
| ||
19:35 | Fix missing dealloc. check-in: 7ee61bb762 user: js tags: trunk | |
2012-10-30
| ||
22:33 | Implement fast enumeration. check-in: 2da674855b user: js tags: trunk | |
17:51 | Make use of OF_SENTINEL. check-in: 455ca009cd user: js tags: trunk | |
Changes
Changes to PGResultRow.m.
︙ | |||
104 105 106 107 108 109 110 111 112 113 114 115 116 117 | 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 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | - (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]; |
︙ |
Changes to test.m.
︙ | |||
37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | + + + + | parameters: @2, @2, @YES, nil]; [connection insertRow: @{ @"content": @"Hallo!", @"name": @"foo" } intoTable: @"test"]; result = [connection executeCommand: @"SELECT * FROM test"]; of_log(@"%@", result); of_log(@"JSON: %@", [result JSONRepresentation]); for (id row in result) for (id col in row) of_log(@"%@", col); result = [connection executeCommand: @"SELECT COUNT(*) FROM test"]; of_log(@"%@", result); [OFApplication terminate]; } @end |