ObjPgSQL  Diff

Differences From Artifact [942a6e30f4]:

To Artifact [459d0b869b]:


12
13
14
15
16
17
18
19
20


21
22
23
24
25
26
27
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 "PGResultRow.h"
#import "PGResult+Private.h"
#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
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
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 PGResultRowEnumerator: OFEnumerator
@interface PGSQLResultRowEnumerator: OFEnumerator
{
	PGResult *_result;
	PGSQLResult *_result;
	PGresult *_res;
	int _row, _pos, _count;
}

- (instancetype)initWithResult: (PGResult*)result row: (int)row;
- (instancetype)initWithResult: (PGSQLResult*)result row: (int)row;
@end

@interface PGResultRowKeyEnumerator: PGResultRowEnumerator
@interface PGSQLResultRowKeyEnumerator: PGSQLResultRowEnumerator
@end

@interface PGResultRowObjectEnumerator: PGResultRowEnumerator
@interface PGSQLResultRowObjectEnumerator: PGSQLResultRowEnumerator
@end

@implementation PGResultRow
+ (instancetype)pg_rowWithResult: (PGResult *)result row: (int)row
@implementation PGSQLResultRow
+ (instancetype)pg_rowWithResult: (PGSQLResult *)result row: (int)row
{
	return [[[self alloc] pg_initWithResult: result row: row] autorelease];
}

- (instancetype)pg_initWithResult: (PGResult *)result row: (int)row
- (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
118

119
120
121
122
123
124
125

126
127
128
129
130
131
132
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 [[[PGResultRowKeyEnumerator alloc]
	return [[[PGSQLResultRowKeyEnumerator alloc]
	    initWithResult: _result
		       row: _row] autorelease];
}

- (OFEnumerator *)objectEnumerator
{
	return [[[PGResultRowObjectEnumerator alloc]
	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
163
164


165
166
167
168
169
170
171
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 PGResultRowEnumerator
- (instancetype)initWithResult: (PGResult *)result row: (int)row
@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
189

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205

206
207
208
209
210
211
212
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 PGResultRowKeyEnumerator
@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 PGResultRowObjectEnumerator
@implementation PGSQLResultRowObjectEnumerator
- (id)nextObject
{
	id object;

	if (_pos >= _count)
		return nil;