开发者

Seg Fault with SOCI

开发者 https://www.devze.com 2023-01-18 11:32 出处:网络
So I haven\'t been coding in C++ for quite a while now, but I\'m pretty sure this issue is related to SOCI and not some general knowledge of memory usage in C++. Here is the problem : I\'m using SOCI

So I haven't been coding in C++ for quite a while now, but I'm pretty sure this issue is related to SOCI and not some general knowledge of memory usage in C++. Here is the problem : I'm using SOCI to query a table and get a field, and the sql statement line always cause a Segmentation Fault. Which is quite troublesome... Here is the code :

string engine::getReview(int rev_id) 
{
    try {
        session sql;
        string post;

        sql.open("mysql", "db=ranking_dev user=****** password=*******");
        sql << "SELECT post FROM reviews WHERE id = 3", into(post); //Faulty line

        return post;
    }
    catch (exception const &e) {
        cerr << "Error: " << e.what() << '\n';
    开发者_Python百科    return "";
    }
}

I'm positive that this line is the root of the error. I tried to initialize the "post" variable, but to no avails. Also, if I retrieve an integer value from the table (and thus store the data in an integer), there's no SEG FAULT. And so I guess the issue is related to the way I'm using this string, but I can see anything overly wrong in my function. Any ideas on this?

0

精彩评论

暂无评论...
验证码 换一张
取 消