嗨,我使用sqlite管理器现在的管理器显示我表内的数据库,但当我运行我的代码,它说,表没有找到。这是我的代码。谁能指出我的错误?
- (IBAction)saveDatabase
{
float x = [_openingBalance.text floatValue];
NSNumber *amount = [NSNumber numberWithFloat:x];
float y = [_monthlyBudget.text floatValue];
NSNumber *budget = [NSNumber numberWithFloat:y];
_uuid = [[UIDevice currentDevice] uniqueIdentifier];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"Accounts.sqlite"];
sqlite3 *database;
if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = "insert into Account (name, type , currencyCode , parentAccount , currentBalance , monthlyBudget , monthlyBudgetPercentage ) VALUES ( ? , ? , ? , ? , ? , ? , ?)";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
sqlite3_bind_text( compiledStatement, 1, [_accountName.text UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_int(compiledStatement, 2, 1);
sqlite3_bind_text(compiledStatement, 3, [@"PKR" UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_int(compiledStatement, 4, 1);
sqlite3_bind_double(compiledStatement, 5, [amount doubleValue]);
sqlite3_bind_double(compiledStatement, 6, [budget doubleValue]);
sqlite3_bind_int(compiledStatement, 7, 0);
}
if(sqlite3_step(compiledStatement) != SQLITE_DONE ) {
NSLog( @"Error: %s", sqlite3_errmsg(database) );
} else {
NSLog( @"Insert into row id = %lld", sqlite3_last_insert_rowid(database));
}
char* errmsg;
sqlite3_exec(database, "COMMIT", NULL, NULL, &errmsg);
sqlite3_finalize(compiledStatement);
sqlite3_close(database);
}
}
错误是Error: no such table: Account
使用此文件路径..
NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Accounts.sqlite"];