Error converting NSString to UTF8String

点点圈 提交于 2019-12-11 18:59:34

问题


-(id)select:(NSString *)original_query
{
    sqlite3_stmt *statement;
    const char * converted = [original_query UTF8String];

    NSLog(@"[INFO] converted char = %@", converted);

    if (sqlite3_prepare_v2(db, converted, -1, &statement, NULL) != SQLITE_OK) {
        @throw [NSException exceptionWithName: @"DB Encriptor" reason: [NSString stringWithFormat: @"Query \"%s\" has failed, we could not execute the SQL statement. '%s'",  converted, sqlite3_errmsg(db) ] userInfo: nil];
    }
    else {
        @try {
             ...
        }
        @catch (NSException * e) {
            NSLog(@"Exception: %@", e);
            return NULL;
        }
    }
}

When the execution reaches the line :

const char * converted = [original_query UTF8String];

I get the following error:

 2013-06-27 02:17:33.505 proof[25200:3c03] -[__NSArrayM UTF8String]: unrecognized selector sent to instance 0xc954a30

This is probably a very simple and silly error, I would appreciate if anyone could give me some guidance, I've spent hours trying different schemas to convert the string to UTF8 but no success so far.

Thanks!

EDIT: Some more information: I am creating a native iOS module to work along Titanium. I call this method from JavaScript (in Titanium) passing a string, something like:

 encriptmydb.select("SELECT count(*) FROM sqlite_master;") 

But the error persists ...

来源:https://stackoverflow.com/questions/17335137/error-converting-nsstring-to-utf8string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!