嗨,我现在正在使用 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