получение данных из базы данных SQLite; - PullRequest
0 голосов
/ 14 февраля 2012

Невозможно получить данные ..

- (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 голосов
/ 14 февраля 2012

Проблема в том, что ваш sql statment попробуйте это:

NSString *querySQL = [NSString stringWithFormat: @"SELECT breakFastAmt,lunchAmt,dinnerAmt,dailyTravelAmt,outStationTravelAmt FROM TABLE_For_Expenses WHERE month= '%@'",monthString];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...