Created
August 17, 2011 20:25
-
-
Save betamike/1152515 to your computer and use it in GitHub Desktop.
fmdb test case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//test method which roughly mimics how I normally fetch results | |
-(NSTimeInterval)fetchResultsTest | |
{ | |
static NSString * const selectFavorites = @"SELECT songId, title FROM songs LIMIT 50"; | |
NSMutableArray *fetched = [NSMutableArray array]; | |
FMResultSet *resultSet = [[self database] executeQuery:selectFavorites]; | |
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate]; | |
while ([resultSet next]) | |
{ | |
Song *song = [Song songFromResultSet:resultSet]; | |
[fetched addObject:song]; | |
} | |
NSTimeInterval end = [NSDate timeIntervalSinceReferenceDate]; | |
return (end - start); | |
} | |
-(void)runTest | |
{ | |
NSTimeInterval processTotal = 0; | |
for (int i = 0; i < 100; i++) | |
{ | |
processTotal += [self fetchResultsTest]; | |
} | |
NSLog(@"Average time: %f", (processTotal/100)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(Song *)songFromResultSet:(FMResultSet *)resultSet | |
{ | |
return [[[Song alloc] initWithResultSet:resultSet] autorelease]; | |
} | |
-(id)initWithResultSet:(FMResultSet *)resultSet | |
{ | |
if ((self = [self init])) | |
{ | |
[self setSongID:[resultSet objectForColumnName:@"songId"]]; | |
[self setTitle:[resultSet stringForColumn:@"title"]]; | |
//a couple of columns that may not be present from all result sets | |
if ([resultSet columnIndexForName:@"offlineStatus"] != -1) | |
{ | |
offlineStatus = [resultSet intForColumn:@"offlineStatus"]; | |
} | |
if ([resultSet columnIndexForName:@"isInLibrary"] != -1) | |
{ | |
inLibrary = [resultSet boolForColumn:@"isInLibrary"]; | |
} | |
} | |
return self; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE songs (songId INTEGER PRIMARY KEY UNIQUE NOT NULL, title TEXT NOT NULL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment