这是什么意思?初始化会丢弃指针目标类型的限定符

时间:2011-04-07 02:39:11

标签: iphone xcode sqlite

我正在尝试在详细视图中从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;
}

感谢。

2 个答案:

答案 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] : @"";