Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of https://github.com/bandcampdotcom/fmdb

  • Loading branch information...
commit 451ec2bbc43d749ad4e21567771f36433a61a43c 2 parents f68c006 + d72cbb0
@ccgus authored
Showing with 12 additions and 31 deletions.
  1. +1 −2  src/FMResultSet.h
  2. +11 −29 src/FMResultSet.m
View
3  src/FMResultSet.h
@@ -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;
View
40 src/FMResultSet.m
@@ -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 {
@@ -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 {
@@ -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];
@@ -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];
Please sign in to comment.
Something went wrong with that request. Please try again.