从SQLite数据库获取数据;

时间:2012-02-14 06:44:08

标签: iphone

无法获取数据..

- (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");
                        }
               }
     }
}

1 个答案:

答案 0 :(得分:0)

问题在于你的sql语句试试这个:

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