Initial import.
FossilOrigin-Name: de46b0e10c5d9f516acbbf2ea01d84d0d5ac126412949d459265279262a1b87e
This commit is contained in:
commit
dbfce3528e
15 changed files with 586 additions and 0 deletions
117
PGResultRow.m
Normal file
117
PGResultRow.m
Normal file
|
@ -0,0 +1,117 @@
|
|||
#import "PGResultRow.h"
|
||||
|
||||
@interface PGResultRowEnumerator: OFEnumerator
|
||||
{
|
||||
PGResult *result;
|
||||
PGresult *res;
|
||||
size_t row, pos, count;
|
||||
}
|
||||
|
||||
- initWithResult: (PGResult*)result
|
||||
row: (size_t)row;
|
||||
@end
|
||||
|
||||
@interface PGResultRowKeyEnumerator: PGResultRowEnumerator
|
||||
@end
|
||||
|
||||
@interface PGResultRowObjectEnumerator: PGResultRowEnumerator
|
||||
@end
|
||||
|
||||
@implementation PGResultRow
|
||||
+ rowWithResult: (PGResult*)result
|
||||
row: (size_t)row
|
||||
{
|
||||
return [[[self alloc] initWithResult: result
|
||||
row: row] autorelease];
|
||||
}
|
||||
|
||||
- initWithResult: (PGResult*)result_
|
||||
row: (size_t)row_
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
result = [result_ retain];
|
||||
res = [result PG_result];
|
||||
row = row_;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[result release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (size_t)count
|
||||
{
|
||||
return PQnfields(res);
|
||||
}
|
||||
|
||||
- (id)objectForKey: (id)key
|
||||
{
|
||||
int col;
|
||||
|
||||
if ([key isKindOfClass: [OFNumber class]])
|
||||
col = [key intValue];
|
||||
else
|
||||
col = PQfnumber(res, [key UTF8String]);
|
||||
|
||||
return [OFString stringWithUTF8String: PQgetvalue(res, row, col)];
|
||||
}
|
||||
|
||||
- (OFEnumerator*)keyEnumerator
|
||||
{
|
||||
return [[[PGResultRowKeyEnumerator alloc]
|
||||
initWithResult: result
|
||||
row: row] autorelease];
|
||||
}
|
||||
|
||||
- (OFEnumerator*)objectEnumerator
|
||||
{
|
||||
return [[[PGResultRowObjectEnumerator alloc]
|
||||
initWithResult: result
|
||||
row: row] autorelease];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation PGResultRowEnumerator
|
||||
- initWithResult: (PGResult*)result_
|
||||
row: (size_t)row_
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
result = [result_ retain];
|
||||
res = [result PG_result];
|
||||
row = row_;
|
||||
count = PQnfields(res);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)reset
|
||||
{
|
||||
pos = 0;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation PGResultRowKeyEnumerator
|
||||
- (id)nextObject
|
||||
{
|
||||
if (pos >= count)
|
||||
return nil;
|
||||
|
||||
return [OFString stringWithUTF8String: PQfname(res, pos++)];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation PGResultRowObjectEnumerator
|
||||
- (id)nextObject
|
||||
{
|
||||
if (pos >= count)
|
||||
return nil;
|
||||
|
||||
return [OFString stringWithUTF8String: PQgetvalue(res, row, pos++)];
|
||||
}
|
||||
@end
|
Loading…
Add table
Add a link
Reference in a new issue