我有一個需要數據庫的應用程序。該應用程序在模擬器中運行良好。但是當我嘗試將它部署到iPhone上時,它給了我'沒有這種表動物'的錯誤。哪裏有問題?我更好地理解使用我的iphone應用部署數據庫比較困難
(void)viewDidLoad
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"AnimalDatabase.sql"];
sqlite3 *database;
if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK)
{
const char *sqlStatement = "insert into animal (id, name) VALUES (?, ?)";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
//NSLog(filePath);
sqlite3_bind_int(compiledStatement, 1, 12);
//NSLog(@"A");
sqlite3_bind_text(compiledStatement, 2, [@"abc" UTF8String], -1, SQLITE_TRANSIENT);
//NSLog(@"B");
if(sqlite3_step(compiledStatement) != SQLITE_DONE)
{
//NSLog(@"C");
NSLog(@"Error: %s", sqlite3_errmsg(database));
}
else
{
//NSLog(@"D");
NSLog(@"Insert into row id = %d", sqlite3_last_insert_rowid(database));
}
}
else
{
NSAssert1(0, @"Error while creating insert statement. '%s'", sqlite3_errmsg(database));
}
sqlite3_finalize(compiledStatement);
}
else
{
NSLog(@"Error Occured");
}
sqlite3_close(database);
[super viewDidLoad];
}提供的代碼
但我會不同意你的。因爲如果動物數據庫不存在,程序如何在模擬器上運行? – Joy 2010-04-23 07:47:41
這可能是問題所在。從我記得的地方來看,模擬器如何處理文件的大小寫敏感性與手機處理靈敏度的方式有所不同 – Liam 2010-04-23 08:12:50