2011-08-19 40 views
0

嗨我现在使用sqlite经理现在经理向我展示数据库内的表,但是当我运行我的代码时说它没有找到表。这是我的代码。请有人指出我的错误。帮助需要与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

+0

删除模拟器您的应用程序,运行全部清除在Xcode中,然后运行你的应用程序。 – mayuur

回答

0

使用此为您的文件路径..

NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Accounts.sqlite"];