SOCI 段故障
所以我已经有一段时间没有用 C++ 编码了,但我很确定这个问题与 SOCI 有关,而不是 C++ 中内存使用的一些常识。问题是:我使用 SOCI 查询表并获取字段,而 sql 语句行总是导致分段错误。这是相当麻烦的...这是代码:
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 "";
}
}
我确信这一行是错误的根源。我尝试初始化“post”变量,但无济于事。另外,如果我从表中检索整数值(从而将数据存储在整数中),则不会出现 SEG FAULT。所以我猜这个问题与我使用这个字符串的方式有关,但我可以看到我的函数中有任何过度错误的地方。对此有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论