- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在第一个实现文件上,所有步骤
- (void) readCitiesFromDatabase {
databaseName = @"123.sqlite";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
// Setup the database object
sqlite3 *database;
// Setup the SQL Statement and compile it for faster access
NSString *querySQL = [NSString stringWithFormat:@"SELECT City_Name, City_Picture, City_Id FROM CITIES, COUNTRIES WHERE CITIES.Country_Id=COUNTRIES.Country_Id AND COUNTRIES.Country_Id = '%@'", self.countryID];
const char *sqlStatement = [querySQL UTF8String];
sqlite3_stmt *compiledStatement;
// Init the countries Array
self.cities = [[NSMutableArray alloc] init];
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
NSLog(@"success");
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
NSLog(@"success");
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{
NSLog(@"success");
// Read the data from the result row
char *temp_cName = (char *)sqlite3_column_text(compiledStatement, 0);
NSString *cName = temp_cName == NULL ? nil : [[NSString alloc] initWithUTF8String:temp_cName];
char *temp_cPicture = (char *)sqlite3_column_text(compiledStatement, 1);
NSString *cPicture = temp_cPicture == NULL ? nil : [[NSString alloc] initWithUTF8String:temp_cPicture];
char *temp_cId = (char *)sqlite3_column_text(compiledStatement, 2);
NSString *cId = temp_cId == NULL ? nil : [[NSString alloc] initWithUTF8String:temp_cPicture];
NSMutableDictionary *city = [[NSMutableDictionary alloc] init];
[city setObject:cName forKey:@"City_Name"];
[city setObject:cPicture forKey:@"City_Picture"];
[city setObject:cId forKey:@"City_Id"];
[self.cities addObject:city];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
现在我得到了城市列表。当我选择一个城市时,我看不到城市信息。这是第二次实现。
- (void) readCityInfoFromDatabase:(NSString *)querySQL
{
databaseName = @"123.sqlite";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
// Setup the database object
sqlite3 *database;
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = [querySQL UTF8String];
sqlite3_stmt *compiledStatement;
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
NSLog(@"success");
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
NSLog(@"success");
if (sqlite3_step(compiledStatement) == SQLITE_ROW)
{
NSLog(@"success");
char *temp_content = (char *)sqlite3_column_text(compiledStatement, 0);
[self.cityTextView setText:temp_content == NULL ? nil : [[NSString alloc] initWithUTF8String:temp_content]];
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
前两步是成功的,但是,
if (sqlite3_step(compiledStatement) == SQLITE_ROW)
{
NSLog(@"success");
我看不到这一步成功。
请帮忙。
最佳答案
你真的应该保存 sqlite3_step()
的结果并检查它是否:
SQLITE_ROW
= 检索到的数据行SQLITE_DONE
= 没有(更多)数据要检索不过,根据您分享的内容,您很可能只是收到了 SQLITE_DONE
,因为没有找到任何东西。如果 SQL 中有错误(例如错误的连接、不正确的 WHERE
子句等),您可能会得到它。如果没有看到 readCityInfoFromDatabase
使用的 SQL 和数据库中的一些代表性数据,很难说。
顺便说一句,不仅对于 sqlite3_step()
,而且对于所有的 sqlite3_xxx()
调用,如果您收到错误,您应该记录 sqlite3_errmsg()
。现在,如果出现错误,您必须猜测问题的根源是什么。
关于ios - 如果 (sqlite3_step(compiledStatement) == SQLITE_ROW) 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22336332/
我的应用程序中有一个 sqlite,一切似乎都正常,但是我的数据库方法没有执行 while 循环,而且我无法从查询中获得结果。有人可以帮助我吗?任何帮助将不胜感激! 我还为数据库创建了一个副本,正如我
我正在尝试从 SQLite 中的表中获取行: _tempPath = [[NSSearchPathForDirectoriesInDomains
大家好我在 IOS 中使用 sqlite 时遇到一些问题。我从数据库中选择了数据,然后我想将该数据保存在一个变量中。但是当我使用 while(sqlite3_step(statement) == SQ
在第一个实现文件上,所有步骤 - (void) readCitiesFromDatabase { databaseName = @"123.sqlite"; NSArray *docu
我不知道确切的问题,但现在已经挠头了将近 4 个小时。 if (sqlite3_open([dataBasePath UTF8String], &bookDB) == SQLITE_OK) {
我是一名优秀的程序员,十分优秀!