C++ PQXX 工作事务崩溃
C++ pqxx work transaction crashing
我正在使用c ++ PostgreSQL libpqxx库,我不确定为什么我无法打开事务/非事务对象。
我的代码目前如下
#include <iostream>
#include <pqxx/pqxx>
using namespace std;
using namespace pqxx;
int main() {
// define variables
string params;
connection* pgsql;
string sql;
// db connection parameters
params = "dbname=dummy user=postgres password=postgres hostaddr=10.10.0.2 port=5431";
try {
// make connection
pgsql = new connection(params);
} catch(const exception &log) {
// connection failed
cerr << log.what() << endl;
}
// prepare sql
sql = " select * from categories where cat_idno = $1 ";
pgsql->prepare("categories", sql)("integer");
// execute transaction
// this bit doesn't work
work tr(pgsql);
result row = tr.prepared("categories")(1).exec();
tr.commit();
// disconnect
pgsql->disconnect();
}
它使与数据库的连接很好,并且也很好地准备了我的sql,但它无法编译(顺便说一句,我正在CentOS 5上编译(
g++ -o ./pgsqltest ./pgsqltest02.cpp -lpqxx
给我以下错误
./pgsqltest02.cpp: In function ‘int main()’:
./pgsqltest02.cpp:24: error: no matching function for call to ‘pqxx::transaction<read_committed, read_write>::transaction(pqxx::connection*&)’
/usr/include/pqxx/transaction.hxx:102: note: candidates are: pqxx::transaction<ISOLATIONLEVEL, READWRITE>::transaction(pqxx::connection_base&) [with pqxx::isolation_level ISOLATIONLEVEL = read_committed, pqxx::readwrite_policy READWRITE = read_write]
/usr/include/pqxx/transaction.hxx:97: note: pqxx::transaction<ISOLATIONLEVEL, READWRITE>::transaction(pqxx::connection_base&, const std::string&) [with pqxx::isolation_level ISOLATIONLEVEL = read_committed, pqxx::readwrite_policy READWRITE = read_write]
/usr/include/pqxx/transaction.hxx:87: note: pqxx::transaction<read_committed, read_write>::transaction(const pqxx::transaction<read_committed, read_write>&)
我不确定为什么会这样,也许我错过了一些非常明显的东西
该错误与编译命令有关,它需要指向libpqxx标头和二进制文件的其他参数。正确的编译命令是
g++ -o ./pgsqltest ./pgsqltest02.cpp -I /opt/libpqxx/include -L /opt/libpqxx/lib -lpq -lpqxx
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 内联映射初始化的动态atexit析构函数崩溃
- 执行函数时导致崩溃的变量
- 程序崩溃并显示"std::out_of_range"错误
- CoInitialize()在单独的线程上崩溃而不返回
- 使用调试/崩溃报告将应用程序部署到客户端
- 为什么所有C++编译器都会崩溃或挂起此代码
- 为什么lambda在clang上崩溃而不是在gcc上崩溃
- 为什么我的多线程作业队列崩溃
- ExtractIconEx:可以工作,但偶尔会崩溃
- 为什么引用传递会导致此崩溃(C++)
- 试图创建流或fopen时程序崩溃
- 类对象数组的问题会导致崩溃
- 排序时无法执行交换操作.我做的时候它会崩溃.为什么
- 为什么要增加导致崩溃的指针
- 在虚幻引擎中删除NXOpen对象时崩溃
- 为什么它只打印双链接列表的第一个值,而我的程序却崩溃了
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- Visual Studio在尝试读取resource.txt文件时崩溃
- C++ PQXX 工作事务崩溃