Из xcode не удалось выполнить ключевое слово DISTINCT для sqlite

- (void) readProductsFromDatabase {// Настройка объекта базы данных sqlite3 * database;

// Init the animals Array
products = [[NSMutableArray alloc] init];

// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
    NSLog(@"db opened");
    // Setup the SQL Statement and compile it for faster access
    const char *sqlStatement = "SELECT DISTINCT productname FROM iphone ";
            sqlite3_stmt *compiledStatement;
    if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) 
    {
        // Loop through the results and add them to the feeds array
        while(sqlite3_step(compiledStatement) == SQLITE_ROW)
        {
            NSLog(@"inside sqlite3 prepare");
            // Read the data from the result row
            NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];


                    }
    }
    // Release the compiled statement from memory
    sqlite3_finalize(compiledStatement);

}
sqlite3_close(database);

}

Моя проблема

const char * sqlStatement = "ВЫБРАТЬ РАЗЛИЧНОЕ название продукта ИЗ iphone";

Эта строка не выполняется, я использую sqlite3, заранее спасибо,


person mac    schedule 12.03.2010    source источник
comment
Что вы имеете в виду, говоря, что эта строка не выполняется?   -  person Paul R    schedule 12.03.2010


Ответы (1)


проблема в этом шаге NSString * aName = [NSString stringWithUTF8String: (char *) sqlite3_column_text (compiledStatement, 2)];

вместо 2 используйте 0

person mac    schedule 12.03.2010