Skip to content

Commit

Permalink
Fixed attempting to have several transactions per connection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Grandro committed Jan 22, 2025
1 parent e581138 commit 808a3ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/qlever-petrimaps/SQLCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ void SQLCache::loadNew() {
// Use cursor to process data in batches
LOG(INFO) << "[GEOMCACHE] Process Query: " << _finalQuery;
try {
pqxx::work w(*_sqlConn);
pqxx::connection c(_sqlCredentials.c_str());
pqxx::work w(c);
pqxx::stateless_cursor<pqxx::cursor_base::read_only, pqxx::cursor_base::owned> cursor(w, _finalQuery, "myCursor", false);
for (size_t pos = 0; pos < _rowCount; pos += _batchSize) {
_loadStatusStage = _LoadStatusStages::FinalQuery;
Expand Down Expand Up @@ -478,7 +479,8 @@ std::vector<std::map<std::string, std::string>> SQLCache::getAttr() const {
attr.reserve(_rowCount);

try {
pqxx::work w(*_sqlConn);
pqxx::connection c(_sqlCredentials.c_str());
pqxx::work w(c);
pqxx::stateless_cursor<pqxx::cursor_base::read_only, pqxx::cursor_base::owned> cursor(w, _finalQuery, "myCursor", false);
for (size_t pos = 0; pos < _rowCount; pos += _batchSize) {
pqxx::result result = cursor.retrieve(pos, pos + _batchSize);
Expand Down Expand Up @@ -508,7 +510,8 @@ std::vector<std::map<std::string, std::string>> SQLCache::getAttrIncludeGeom() c
attr.reserve(_rowCount);

try {
pqxx::work w(*_sqlConn);
pqxx::connection c(_sqlCredentials.c_str());
pqxx::work w(c);
pqxx::stateless_cursor<pqxx::cursor_base::read_only, pqxx::cursor_base::owned> cursor(w, _finalQuery, "myCursor", false);
for (size_t pos = 0; pos < _rowCount; pos += _batchSize) {
pqxx::result result = cursor.retrieve(pos, pos + _batchSize);
Expand Down Expand Up @@ -538,8 +541,11 @@ pqxx::result SQLCache::processQuery(std::string query, int limit, int offset) co

pqxx::result result;
try {
// Start a transaction
pqxx::work w(*_sqlConn);
// Open connection
pqxx::connection c(_sqlCredentials.c_str());

// Start transaction
pqxx::work w(c);

// Execute query
result = w.exec(query);
Expand Down
2 changes: 0 additions & 2 deletions src/qlever-petrimaps/SQLCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class SQLCache : public GeomCache {
// _____________________________________________________________________________
SQLCache() {
_curl = curl_easy_init();
_sqlConn = new pqxx::connection(_sqlCredentials.c_str());
}

SQLCache& operator=(SQLCache&& o) {
Expand Down Expand Up @@ -71,7 +70,6 @@ class SQLCache : public GeomCache {

// PostgreSQL
std::string _sqlCredentials = "host=localhost port=5432 dbname=test_database user=test_user password=123456";
pqxx::connection* _sqlConn;

pqxx::result processQuery(std::string query, int limit = -1, int offset = -1) const;
std::vector<std::string> expandSelectStatements(std::vector<std::string> selectStatements, std::map<pqxx::oid, std::string> originColumnTables,
Expand Down

0 comments on commit 808a3ab

Please sign in to comment.