-
Notifications
You must be signed in to change notification settings - Fork 228
/
SQLRow.m
100 lines (74 loc) · 1.59 KB
/
SQLRow.m
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
//
// SQLRow.m
// SQLite Test
//
// Created by Dustin Mierau on Tue Apr 02 2002.
// Copyright (c) 2002 Blackhole Media, Inc. All rights reserved.
//
#import "SQLDatabase.h"
#import "SQLDatabasePrivate.h"
@implementation SQLRow
-(id)initWithColumns:(char**)inColumns rowData:(char**)inRowData columns:(int)inColumnCount
{
if( ![super init])
return nil;
mRowData = inRowData;
mColumns = inColumns;
mColumnCount = inColumnCount;
return self;
}
-(id)init
{
if( ![super init])
return nil;
mRowData = NULL;
mColumns = NULL;
mColumnCount = 0;
return self;
}
-(void)dealloc
{
[super dealloc];
}
#pragma mark -
-(int)columnCount
{
return mColumnCount;
}
#pragma mark -
-(NSString*)stringForColumn:(NSString*)inColumnName
{
int index;
if( ![self valid])
return nil;
for( index = 0; index < mColumnCount; index++ )
if( strcmp( mColumns[ index ], [inColumnName cStringUsingEncoding:NSASCIIStringEncoding]) == 0 )
break;
return [self stringForColumnAtIndex:index];
}
-(NSString*)stringForColumnAtIndex:(int)inIndex
{
if( inIndex >= mColumnCount || ![self valid])
return nil;
if (mRowData[ inIndex ] == nil)
return nil;
return [NSString stringWithUTF8String:mRowData[ inIndex ]];
}
#pragma mark -
-(NSString*)description
{
NSMutableString* string = [NSMutableString string];
int column;
for( column = 0; column < mColumnCount; column++ )
{
if( column ) [string appendString:@" | "];
[string appendFormat:@"%s", mRowData[ column ]];
}
return string;
}
#pragma mark -
-(BOOL)valid
{
return ( mRowData != NULL && mColumns != NULL && mColumnCount > 0 );
}
@end