在AppDelegate中我找回我的數據庫的路徑:未知錯誤而執行select語句
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory=[paths objectAtIndex:0];
self.sqlFile=[[NSString alloc]init];
self.sqlFile=[documentDirectory stringByAppendingPathComponent:@"AnimalData.sqlite"];
在我的視圖控制器之一,我必須從數據庫中選擇值,代碼:
NSString *trimString=[appDelegate.mainBreedSelected stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *selectSQL=[NSString stringWithFormat:@"select breed from AnimalsTable where mainBreed=\"%@\"",trimString];
sqlite3_stmt *selectStatement;
const char *select_stmt=[selectSQL UTF8String];
if (sqlite3_open([appDelegate.sqlFile UTF8String],&database)==SQLITE_OK)
{
sqlite3_prepare_v2(database,select_stmt,-1,&selectStatement,NULL);
if (sqlite3_step(selectStatement)==SQLITE_DONE)
{
while(sqlite3_step(selectStatement) == SQLITE_ROW)
{
NSString *animalBreed = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectStatement, 2)];
NSLog(@"Breed:%@",animalBreed);
}
}
else
NSAssert1(0, @"Error while deleting. '%s'", sqlite3_errmsg(database));
sqlite3_finalize(selectStatement);
sqlite3_close(database);
}
else
NSLog(@"Database cannot be opened");
我得到的錯誤爲:
*終止應用程序由於uncaug ht異常'NSInternalInconsistencyException', 原因:'選擇時出錯。 '未知錯誤''
如何解決此問題?
我做了另一個改變,看它是否會工作但我得到新的錯誤更改是NSString * selectSQL = [NSString stringWithFormat:@「從動物列表中選擇品種,其中mainBreed =%@」,trimString];新的錯誤是:***終止應用程序由於未捕獲的異常'NSInternalInconsistencyException',原因:'錯誤,同時刪除。 '沒有這樣的專欄:羊'' – anjum 2012-04-17 08:38:03