Created
August 7, 2011 07:35
-
-
Save anonymous/1130160 to your computer and use it in GitHub Desktop.
Fetch data from sqlite
This file contains hidden or 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
-(NSMutableArray *) getChapters{ | |
sqlite3 *database = Pc2MacDatabase(); | |
NSMutableArray *chapters = [[[NSMutableArray alloc] init] autorelease]; | |
NSString *nsquery = [[NSString alloc] initWithFormat:@"SELECT * FROM CHAPTER ORDER BY ID"]; | |
const char *query = [nsquery UTF8String]; | |
[nsquery release]; | |
sqlite3_stmt *statement; | |
int prepareCode = (sqlite3_prepare_v2( database, query, -1, &statement, NULL)); | |
if(prepareCode == SQLITE_OK) { | |
while (sqlite3_step(statement) == SQLITE_ROW) { | |
Chapter *newChapter= [[Chapter alloc] init]; | |
newChapter.chapterNumber = sqlite3_column_int(statement, 0); | |
newChapter.chapterName = [NSString stringWithCString:(char *)sqlite3_column_text(statement, 1) encoding:NSUTF8StringEncoding]; | |
newChapter.isFree = sqlite3_column_int(statement, 2); | |
[chapters addObject:newChapter]; | |
[newChapter release]; | |
} | |
sqlite3_finalize(statement); | |
} | |
return chapters; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment