2012-02-14 162 views
0

無法獲取數據..從SQLite數據庫獲取數據;

- (void)getAmountFromDB 
{ 
    expensesArray = [[NSMutableArray alloc]init]; 

    NSString *destinationPath = [self getDestinationPath]; 

    const char *dbpath = [destinationPath UTF8String]; 
    sqlite3_stmt *statement; 

    if (sqlite3_open(dbpath, &database) == SQLITE_OK) 
    { 
     NSLog(@"month String is = %@",monthString); 
     NSString *querySQL = [NSString stringWithFormat: @"SELECT breakFastAmt,lunchAmt,dinnerAmt,dailyTravelAmt,outStationTravelAmt FROM TABLE_For_Expenses WHERE month=\"%@\"",monthString]; 


     const char *query_stmt = [querySQL UTF8String]; 

     if (sqlite3_prepare_v2(database, query_stmt, -1, &statement, NULL) == SQLITE_OK) 
     { 

      while (sqlite3_step(statement) == SQLITE_ROW) 
      { 
       NSLog(@"hi"); 
       }   

流動以下條件未進入。

if (sqlite3_prepare_v2(database, query_stmt, -1, &statement, NULL) == SQLITE_OK) 

但是它的工作代碼如下:

- (void) getDataFromDB 
{ 
    expensesArray = [[NSMutableArray alloc]init]; 

    NSString *destinationPath = [self getDestinationPath]; 

    const char *dbpath = [destinationPath UTF8String]; 
    sqlite3_stmt *statement; 

    if (sqlite3_open(dbpath, &database) == SQLITE_OK) 
    { 
     NSString *querySQL = [NSString stringWithFormat: @"SELECT * FROM TABLE_For_Expenses"]; 


     const char *query_stmt = [querySQL UTF8String]; 

     if (sqlite3_prepare_v2(database, query_stmt, -1, &statement, NULL) == SQLITE_OK) 
     { 

      while (sqlite3_step(statement) == SQLITE_ROW) 
      { 
          NSLog (@"hi"); 
         } 
       } 
    } 
} 
+0

你爲什麼不使用CoreData呢? – 2012-02-14 06:54:16

+0

與mogenerator ...? – SEG 2012-02-14 09:03:49

+0

雖然FMDB是一個很酷的選項.. – utsabiem 2013-05-15 13:19:02

回答

0

問題是烏爾SQL statment試試這個:

NSString *querySQL = [NSString stringWithFormat: @"SELECT breakFastAmt,lunchAmt,dinnerAmt,dailyTravelAmt,outStationTravelAmt FROM TABLE_For_Expenses WHERE month= '%@'",monthString]; 
+0

還有同樣的問題 – Shreedhar 2012-02-14 06:56:48

+0

什麼是問題,請打印您的錯誤 – Deepesh 2012-02-14 07:36:58