Skip to content

Commit 420af08

Browse files
committed
Change handling of libpqxx classes to support version 7.
pqxx::connection::activate() and pqxx::connection::disconnect() are gone, the former doesn't have a corresponding substitute. Instead the caller is encouraged to watch out for broken_connection exception. Also the explicit activation of a PostgreSQL connection is no longer supported. work::prepared() is also no longer supported, so change this to work::exec_prepared(). There's no need to special case this for older libpqxx versions, since this method is already present there, too. This commit wraps those deprecated API calls into a ifdef to support builds with an older libpqxx version. We might get rid of this if we don't want to have support for those older ones.
1 parent 2dc83ee commit 420af08

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ PKG_CHECK_MODULES(LIBPQXX, libpqxx < 7.0,
1414
)]
1515
)
1616

17+
AS_IF([test "x$libpqxx7" = "xyes"], AC_MSG_NOTICE([libpqxx version >= 7 detected]), [])
1718
AS_IF([test "x$libpqxx7" = "xyes"], [AC_DEFINE([HAVE_LIBPQXX7], [1], [define if libpqxx >= 7 is used])], [])
1819
AS_IF([test "x$libpqxx7" = "xyes"], [AX_CXX_COMPILE_STDCXX_17(noext,mandatory)], [])
1920

log.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pqxx_logger::pqxx_logger(std::string target, std::string conninfo, struct schema
146146
ostringstream seed;
147147
seed << smith::rng;
148148

149-
result r = w.prepared("instance")(GITREV)(target)(hostname)(s.version)(seed.str()).exec();
149+
result r = w.exec_prepared("instance", GITREV, target, hostname, s.version, seed.str());
150150

151151
id = r[0][0].as<long>(id);
152152

@@ -169,7 +169,7 @@ void pqxx_logger::error(prod &query, const dut::failure &e)
169169
work w(*c);
170170
ostringstream s;
171171
s << query;
172-
w.prepared("error")(e.what())(s.str())(e.sqlstate).exec();
172+
w.exec_prepared("error", e.what(), s.str(), e.sqlstate);
173173
w.commit();
174174
}
175175

@@ -180,7 +180,7 @@ void pqxx_logger::generated(prod &query)
180180
work w(*c);
181181
ostringstream s;
182182
impedance::report(s);
183-
w.prepared("stat")(queries)(sum_height/queries)(sum_nodes/queries)(sum_retries/queries)(s.str()).exec();
183+
w.exec_prepared("stat", queries, sum_height/queries, sum_nodes/queries, sum_retries/queries, s.str());
184184
w.commit();
185185
}
186186
}

postgres.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ dut_pqxx::dut_pqxx(std::string conninfo)
7171
void dut_pqxx::test(const std::string &stmt)
7272
{
7373
try {
74+
#ifndef HAVE_LIBPQXX7
7475
if(!c.is_open())
7576
c.activate();
77+
#endif
7678

7779
pqxx::work w(c);
7880
w.exec(stmt.c_str());
@@ -282,7 +284,11 @@ schema_pqxx::schema_pqxx(std::string &conninfo, bool no_catalog) : c(conninfo)
282284
}
283285
}
284286
cerr << "done." << endl;
287+
#ifdef HAVE_LIBPQXX7
288+
c.close();
289+
#else
285290
c.disconnect();
291+
#endif
286292
generate_indexes();
287293
}
288294

0 commit comments

Comments
 (0)