views:

68

answers:

0

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';
    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?