线程4:EXC_BAD_ACCESS(代码= 1,地址= 0x0)

时间:2019-04-01 14:51:32

标签: c++ string sqlite

当我尝试使用引号传递SQL命令时,我一直收到此错误。其他简单查询也可以,只要是带引号或百分比符号的查询就会出现此错误。

我尝试将其作为output string stream传递,但仍然遇到相同的错误。

std::vector<Post *> sql::selectSpecificPosts(sqlite3 *db, int languageNum){
    sqlite3_open("test.db", &db);
    std::vector<Post *> posts;
    char *errMsg;
    std::string select;

    if (languageNum == 1) {
        select = "SELECT * FROM POST WHERE CONTENTTYPE = \'Kotlin\'";
    }else if (languageNum == 2){
        select = "SELECT * FROM POST WHERE CONTENTTYPE = \'Objective-C\'";
    }else if (languageNum == 3){
        select = "SELECT * FROM POST WHERE CONTENTTYPE = \'JavaScript\'";
    }

    sqlite3_exec(db, select.c_str(), post_callback, &posts, &errMsg);

    sqlite3_close(db);
    return posts;
}

是否有更好的方法来传递带引号的SQL查询?

0 个答案:

没有答案