I try to create a Sqlite3 wrapper class for easy to use.
I can get the select result in NSArray with NSDictionary items using as code as below, my question is what I want to instead of NSMutableDictionary *row to MyDatatClass *row, and MyDataClass is not fixed, I want to this wrapper class can be used for all of my data class, what can I do?:
I can get the select result in NSArray with NSDictionary items using as code as below, my question is what I want to instead of NSMutableDictionary *row to MyDatatClass *row, and MyDataClass is not fixed, I want to this wrapper class can be used for all of my data class, what can I do?:
Code:
-(NSArray *) selectData:(NSString *) sql {
NSMutableArray *rows = [NSMutableArray array];
sqlite3_stmt *statement = NULL;
if (sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL) == SQLITE) {
while (sqlite3_step(statement) == SQLITE_ROW) {
NSMutableDictionary *row = [[NSMutableDictionary alloc] init];
[self copyValuesFromStatement:statement toRow:row];
[rows addObject:row];
[row release];
}
}
sqlite3_finalize(statement);
return rows;
}