-1
我正在開發一個應用程序,其中我想從SQlite中的多個表中獲取數據。如何在iPhone應用程序開發中運行多個SQlite查詢
-(void)checkAndCreateDatabase{
BOOL success;
NSFileManager *fileManager=[NSFileManager defaultManager];
success=[fileManager fileExistsAtPath:databasePath];
if(success)
return;
NSString *databasePathFromApp = [[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent:databaseName];
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
}
-(void)readData{
sqlite3 *database;
genderList=[[NSMutableArray alloc]init];
if(sqlite3_open([databasePath UTF8String], &database)== SQLITE_OK){
const char *sqlStatement = "select name from gender";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL)==SQLITE_OK){
while (sqlite3_step(compiledStatement)==SQLITE_ROW) {
NSInteger pId = sqlite3_column_int(compiledStatement, 0);
NSString *stringName=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
db *info =[[db alloc]initWithID:pId andName:stringName];
[genderList addObject:info];
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
在上面的代碼中,我通過了性別的查詢選擇名稱。同時我想通過從內容中選擇名稱並將其保存在不同的數組中。我怎樣才能做到這一點?
我想在新增兩個奎雷斯..分別以在上面的代碼中添加我的第二個查詢 – makumar
您需要創建一個類,其中有一些函數在那裏,然後逐個調用該函數 –
嗨Samuel ..謝謝..因爲我正在動態表視圖我無法從不同的類獲取數據。 。這就是我要求在不同陣列中的一個類存儲中運行所有查詢的原因。 – makumar