- (void)readProductsFromDatabase { //设置数据库对象 sqlite3 *数据库;
// 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 =“SELECT DISTINCT productname FROM iphone”;
此行未执行,我使用的是sqlite3, 提前谢谢,
答案 0 :(得分:0)
问题在于此步骤 NSString * aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement,2)];
而不是2使用0