help needed with sqlite manager
hi i m using sqlite manager now the manager is showing me tables inside the database but when i m running my code it says that the table is not found. Here is my code. please can someone point out my mistake.
- (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(NSDocum开发者_如何学PythonentDirectory, 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);
}
}
The error is Error: no such table: Account
Use this for your file path..
NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Accounts.sqlite"];
精彩评论