简体   繁体   中英

What does this mean? Initialization discards qualifiers from pointer target type

I'm trying to load text from sqlite database in detailed view and I'm getting this error.

Initialization discards qualifiers from pointer target type.

What does this mean? and how can I fix it. Help please. Here is my code.

-(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;
}

Thanks.

sqlite3_column_text is declared to return a const unsigned char * , and you are assigning it to a variable of type char * . This loses the const qualifier, so the compiler is warning you of that fact.

this will also work:

char* foo = (char *)sqlite3_column_text(statement, 1);
NSString* Foo = (foo) ? [NSString stringWithUTF8String:foo] : @"";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM