Differences From Artifact [942a6e30f4]:
- File src/PGResultRow.m — part of check-in [31c5599df5] at 2024-08-11 09:22:44 on branch trunk — Change license to unmodified ISC (user: js, size: 4860) [annotate] [blame] [check-ins using]
To Artifact [459d0b869b]:
- File
src/PGSQLResultRow.m
— part of check-in
[77c26b4fce]
at
2024-08-11 18:00:52
on branch trunk
— Change prefix to PGSQL
Two letter prefixes are too risky to cause collisions. (user: js, size: 4914) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
12 13 14 15 16 17 18 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ | | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ #import "PGSQLResultRow.h" #import "PGSQLResult+Private.h" static id convertType(PGresult *res, int column, OFString *string) { switch (PQftype(res, column)) { case 16: /* BOOLOID */ if ([string isEqual: @"t"]) |
︙ | ︙ | |||
42 43 44 45 46 47 48 | case 701: /* FLOAT8OID */ return [OFNumber numberWithDouble: string.doubleValue]; } return string; } | | | | | | | | | | 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 | case 701: /* FLOAT8OID */ return [OFNumber numberWithDouble: string.doubleValue]; } return string; } @interface PGSQLResultRowEnumerator: OFEnumerator { PGSQLResult *_result; PGresult *_res; int _row, _pos, _count; } - (instancetype)initWithResult: (PGSQLResult*)result row: (int)row; @end @interface PGSQLResultRowKeyEnumerator: PGSQLResultRowEnumerator @end @interface PGSQLResultRowObjectEnumerator: PGSQLResultRowEnumerator @end @implementation PGSQLResultRow + (instancetype)pg_rowWithResult: (PGSQLResult *)result row: (int)row { return [[[self alloc] pg_initWithResult: result row: row] autorelease]; } - (instancetype)pg_initWithResult: (PGSQLResult *)result row: (int)row { self = [super init]; _result = [result retain]; _res = result.pg_result; _row = row; |
︙ | ︙ | |||
111 112 113 114 115 116 117 | return convertType(_res, column, [OFString stringWithUTF8String: PQgetvalue(_res, _row, column)]); } - (OFEnumerator *)keyEnumerator { | | | | 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | return convertType(_res, column, [OFString stringWithUTF8String: PQgetvalue(_res, _row, column)]); } - (OFEnumerator *)keyEnumerator { return [[[PGSQLResultRowKeyEnumerator alloc] initWithResult: _result row: _row] autorelease]; } - (OFEnumerator *)objectEnumerator { return [[[PGSQLResultRowObjectEnumerator alloc] initWithResult: _result row: _row] autorelease]; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count |
︙ | ︙ | |||
156 157 158 159 160 161 162 | state->itemsPtr = objects; state->mutationsPtr = (unsigned long *)self; return j; } @end | | | | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | state->itemsPtr = objects; state->mutationsPtr = (unsigned long *)self; return j; } @end @implementation PGSQLResultRowEnumerator - (instancetype)initWithResult: (PGSQLResult *)result row: (int)row { self = [super init]; _result = [result retain]; _res = result.pg_result; _row = row; _count = PQnfields(_res); |
︙ | ︙ | |||
182 183 184 185 186 187 188 | - (void)reset { _pos = 0; } @end | | | | 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 207 208 209 210 211 212 | - (void)reset { _pos = 0; } @end @implementation PGSQLResultRowKeyEnumerator - (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 PGSQLResultRowObjectEnumerator - (id)nextObject { id object; if (_pos >= _count) return nil; |
︙ | ︙ |