0
我正在開發iPhone應用程序。我創建了一個可用的類,其中寫入了一個sqlite getData方法。我想從我的控制器傳遞一個sql語句,並希望返回所有行的數組。如何將sqlite3_stmt返回到調用對象
我可以將sqlite3_stmt對象存儲到數組中並返回該數組,因此在調用點處我可以將其轉換並找出每列值?
我當前的代碼就是這樣:
-(NSMutableArray*)getData:(NSString*) SqlQuery
{
// The Database is stoed in the application bundle
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"sqliteClasses.sqlite"];
if(sqlite3_open([path UTF8String], &contactDB) == SQLITE_OK)
{
const char *sql = (const char*)[SqlQuery UTF8String];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(contactDB, sql, -1, &compiledStatement, NULL) == SQLITE_OK)
{
// Loop through the results and add them to the feeds array
while (sqlite3_step(compiledStatement) == SQLITE_ROW)//(stepResult == SQLITE_ROW)
{
// [arrayRecords addObject:compiledStatement];
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(contactDB);
return arrayRecords;
}
誤差線爲:[arrayRecords ADDOBJECT:compiledStatement];
我該如何做到這一點?任何替代實施?
謝謝。