Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup of some code + notes on what is going on

  • Loading branch information...
commit 5a463d036d8f8ab8cc4db6e7a174805d148106e1 1 parent 451ec2b
@ccgus authored
View
3  CHANGES_AND_TODO_LIST.txt
@@ -3,6 +3,9 @@ Zip, nada, zilch. Got any ideas?
If you would like to contribute some code- awesome! I just ask that you make it conform to the coding conventions already set in here, and to add a couple of tests for your new code to fmdb.m. And of course, the code should be of general use to more than just a couple of folks. Send your patches to gus@flyingmeat.com.
+2013.01.31
+ Lazy init of columnNameToIndexMap in FMResultSet, and you are now able to use it before asking for any rows first. Thanks to Daniel Dickison for the patch!
+
2012.12.17
Now resetting cached statements before executing a query on them (as well as resetting them at the close of a result set). There was an issue where if you used the same query twice without closing the result set of the first one, you would get results back from the previous query, or maybe an exhausted result set. Thanks to note173 on github for pointing out the problem.
View
1  CONTRIBUTORS.txt
@@ -34,5 +34,6 @@ Sriram Patil
Geoffrey Foster
Robert Ryan
Samuel Chen
+Daniel Dickison
Aaaaannnd, Gus Mueller (that's me!)
View
6 src/FMResultSet.m
@@ -58,7 +58,7 @@ - (int)columnCount {
- (NSMutableDictionary *)columnNameToIndexMap {
if (!_columnNameToIndexMap) {
int columnCount = sqlite3_column_count([_statement statement]);
- _columnNameToIndexMap = [[NSMutableDictionary alloc] initWithCapacity:columnCount];
+ _columnNameToIndexMap = [[NSMutableDictionary alloc] initWithCapacity:(NSUInteger)columnCount];
int columnIdx = 0;
for (columnIdx = 0; columnIdx < columnCount; columnIdx++) {
[_columnNameToIndexMap setObject:[NSNumber numberWithInt:columnIdx]
@@ -96,7 +96,7 @@ - (NSDictionary*)resultDict {
if (num_cols > 0) {
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:num_cols];
- NSEnumerator *columnNames = [self.columnNameToIndexMap keyEnumerator];
+ NSEnumerator *columnNames = [[self columnNameToIndexMap] keyEnumerator];
NSString *columnName = nil;
while ((columnName = [columnNames nextObject])) {
id objectValue = [self objectForColumnName:columnName];
@@ -208,7 +208,7 @@ - (BOOL)hasAnotherRow {
- (int)columnIndexForName:(NSString*)columnName {
columnName = [columnName lowercaseString];
- NSNumber *n = [self.columnNameToIndexMap objectForKey:columnName];
+ NSNumber *n = [[self columnNameToIndexMap] objectForKey:columnName];
if (n) {
return [n intValue];
View
26 src/fmdb.m
@@ -890,6 +890,28 @@ int main (int argc, const char * argv[]) {
}];
}
+ {
+
+
+ [queue inDatabase:^(FMDatabase *adb) {
+ [adb executeUpdate:@"create table colNameTest (a, b, c, d)"];
+ FMDBQuickCheck([adb executeUpdate:@"insert into colNameTest values (1, 2, 3, 4)"]);
+
+ FMResultSet *ars = [adb executeQuery:@"select * from colNameTest"];
+
+ NSDictionary *d = [ars columnNameToIndexMap];
+ FMDBQuickCheck([d count] == 4);
+
+ FMDBQuickCheck([[d objectForKey:@"a"] intValue] == 0);
+ FMDBQuickCheck([[d objectForKey:@"b"] intValue] == 1);
+ FMDBQuickCheck([[d objectForKey:@"c"] intValue] == 2);
+ FMDBQuickCheck([[d objectForKey:@"d"] intValue] == 3);
+
+ [ars close];
+
+ }];
+
+ }
{
@@ -1214,7 +1236,7 @@ void testPool(NSString *dbPath) {
size_t ops = 128;
- dispatch_queue_t dqueue = dispatch_get_global_queue(0, DISPATCH_QUEUE_PRIORITY_HIGH);
+ dispatch_queue_t dqueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_apply(ops, dqueue, ^(size_t nby) {
@@ -1249,7 +1271,7 @@ void testPool(NSString *dbPath) {
int ops = 16;
- dispatch_queue_t dqueue = dispatch_get_global_queue(0, DISPATCH_QUEUE_PRIORITY_HIGH);
+ dispatch_queue_t dqueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_apply(ops, dqueue, ^(size_t nby) {
Please sign in to comment.
Something went wrong with that request. Please try again.