我正在尝试在详细视图中从sqlite数据库加载文本,我收到此错误。
初始化会从指针目标类型中丢弃限定符。
这是什么意思?以及如何解决它。请帮忙。这是我的代码。
-(void) hydrateDetailViewData {
if (isDetailViewHydrated) return;
if (detailStmt == nil) {
const char *sql = "Select ClubAddress from clubNames Where clubID = ?";
if (sqlite3_prepare_v2(database, sql, -1, &detailStmt, NULL) !=SQLITE_OK)
NSAssert1(0, @"Error while creating detail view statment. '%s'", sqlite3_errmsg(database));
}
sqlite3_bind_int(detailStmt, 1, clubID);
if (SQLITE_DONE != sqlite3_step(detailStmt)) {
char *db_text = sqlite3_column_text(detailStmt, 2); //error showing here
NSString *address = [NSString stringWithUTF8String: db_text];
self.ClubAddress = address;
}
else
NSAssert1(0, @"Error while getting the address of club. '%s'", sqlite3_errmsg(database));
sqlite3_reset(detailStmt);
isDetailViewHydrated = YES;
}
感谢。
答案 0 :(得分:3)
sqlite3_column_text
返回const unsigned char *
,并将其分配给char *
类型的变量。这会丢失const
限定符,因此编译器会警告您这一事实。
答案 1 :(得分:1)
这也有效:
char* foo = (char *)sqlite3_column_text(statement, 1);
NSString* Foo = (foo) ? [NSString stringWithUTF8String:foo] : @"";