Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/bandcampdotcom/fmdb
Browse files Browse the repository at this point in the history
  • Loading branch information
ccgus committed Jan 31, 2013
2 parents f68c006 + d72cbb0 commit 451ec2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
3 changes: 1 addition & 2 deletions src/FMResultSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@

NSString *_query;
NSMutableDictionary *_columnNameToIndexMap;
BOOL _columnNamesSetup;
}

@property (atomic, retain) NSString *query;
@property (atomic, retain) NSMutableDictionary *columnNameToIndexMap;
@property (readonly) NSMutableDictionary *columnNameToIndexMap;
@property (atomic, retain) FMStatement *statement;

+ (id)resultSetWithStatement:(FMStatement *)statement usingParentDatabase:(FMDatabase*)aDB;
Expand Down
40 changes: 11 additions & 29 deletions src/FMResultSet.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@ - (void)resultSetDidClose:(FMResultSet *)resultSet;
@end


@interface FMResultSet (Private)
- (NSMutableDictionary *)columnNameToIndexMap;
- (void)setColumnNameToIndexMap:(NSMutableDictionary *)value;
@end

@implementation FMResultSet
@synthesize query=_query;
@synthesize columnNameToIndexMap=_columnNameToIndexMap;
@synthesize statement=_statement;

+ (id)resultSetWithStatement:(FMStatement *)statement usingParentDatabase:(FMDatabase*)aDB {
Expand Down Expand Up @@ -61,20 +55,17 @@ - (int)columnCount {
return sqlite3_column_count([_statement statement]);
}

- (void)setupColumnNames {

- (NSMutableDictionary *)columnNameToIndexMap {
if (!_columnNameToIndexMap) {
[self setColumnNameToIndexMap:[NSMutableDictionary dictionary]];
}

int columnCount = sqlite3_column_count([_statement statement]);

int columnIdx = 0;
for (columnIdx = 0; columnIdx < columnCount; columnIdx++) {
[_columnNameToIndexMap setObject:[NSNumber numberWithInt:columnIdx]
forKey:[[NSString stringWithUTF8String:sqlite3_column_name([_statement statement], columnIdx)] lowercaseString]];
int columnCount = sqlite3_column_count([_statement statement]);
_columnNameToIndexMap = [[NSMutableDictionary alloc] initWithCapacity:columnCount];
int columnIdx = 0;
for (columnIdx = 0; columnIdx < columnCount; columnIdx++) {
[_columnNameToIndexMap setObject:[NSNumber numberWithInt:columnIdx]
forKey:[[NSString stringWithUTF8String:sqlite3_column_name([_statement statement], columnIdx)] lowercaseString]];
}
}
_columnNamesSetup = YES;
return _columnNameToIndexMap;
}

- (void)kvcMagic:(id)object {
Expand Down Expand Up @@ -105,11 +96,7 @@ - (NSDictionary*)resultDict {
if (num_cols > 0) {
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:num_cols];

if (!_columnNamesSetup) {
[self setupColumnNames];
}

NSEnumerator *columnNames = [_columnNameToIndexMap keyEnumerator];
NSEnumerator *columnNames = [self.columnNameToIndexMap keyEnumerator];
NSString *columnName = nil;
while ((columnName = [columnNames nextObject])) {
id objectValue = [self objectForColumnName:columnName];
Expand Down Expand Up @@ -219,14 +206,9 @@ - (BOOL)hasAnotherRow {
}

- (int)columnIndexForName:(NSString*)columnName {

if (!_columnNamesSetup) {
[self setupColumnNames];
}

columnName = [columnName lowercaseString];

NSNumber *n = [_columnNameToIndexMap objectForKey:columnName];
NSNumber *n = [self.columnNameToIndexMap objectForKey:columnName];

if (n) {
return [n intValue];
Expand Down

0 comments on commit 451ec2b

Please sign in to comment.