我正在使用 xCode 4.3.2。在这里,我试图从数据库中加载列名和值。当我使用 sqlQuery:“select * from mytable Where company like 'SONY'”时,它不起作用,但“select * from mytable”工作正常。请你帮助我好吗?
static int loadCallback(void *context, int count, char **values, char **columns)
{
NSString *columnName;
NSString *columnValue;
for (int i=0; i < count; i++)
{
columnName = [NSString stringWithUTF8String:columns[i]];
if (values[i])
columnValue = [NSString stringWithUTF8String:values[i]];
else
columnValue = @"";
NSLog(@"%@:%@", columnName, columnValue);
}
return SQLITE_OK;
}
- (void)loadDataFromDatabase
{
NSString *file = [self getWritableDBPath];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL success = [fileManager fileExistsAtPath:file];
// If its not a local copy set it to the bundle copy
if(!success) {
//file = [[NSBundle mainBundle] pathForResource:DATABASE_TITLE ofType:@"db"];
[self createEditableCopyOfDatabaseIfNeeded];
}
sqlite3 *database = NULL;
if (sqlite3_open([file UTF8String], &database) == SQLITE_OK) {
//QUERY WORKING
//sqlite3_exec(database, "select * from mytable", loadCallback, valueArray, NULL);
//QUERY NOT WORKING
sqlite3_exec(database, "select * from mytable Where company like 'SONY'", loadCallback, valueArray, NULL);
}
sqlite3_close(database);
}