Skip to content

Commit 4e8963a

Browse files
bradfordboyledf7cb
authored andcommitted
Support building with libpqxx 8
Starting with version 8.0.0, libpqxx requires C++20. The commit updates both the autotools and cmake builds to detect if sqlsmith is compiling against libpqxx and set the C++ standard appropriately.
1 parent 663963e commit 4e8963a

6 files changed

Lines changed: 51 additions & 14 deletions

File tree

CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.14)
22
project(SQLsmith LANGUAGES CXX)
33

4-
set(CMAKE_CXX_STANDARD 17)
4+
set(CMAKE_CXX_STANDARD 20)
55
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
66

77
include(FeatureTests)
@@ -26,9 +26,15 @@ if (NOT USE_UPSTREAM_LIBPQXX)
2626
# This check is done by the CMakeLists.txt of the libpqxx project otherwise
2727
find_package(PQXX REQUIRED)
2828

29-
if (PQXX_VERSION GREATER 7.0)
29+
if (PQXX_VERSION VERSION_GREATER 7.0 AND PQXX_VERSION VERSION_LESS 8.0)
3030
set(HAVE_LIBPQXX7 TRUE)
31-
endif (PQXX_VERSION GREATER 7.0)
31+
set_target_properties(sqlsmith PROPERTIES CXX_STANDARD 17)
32+
endif ()
33+
34+
if (PQXX_VERSION VERSION_GREATER 8.0)
35+
set(HAVE_LIBPQXX8 TRUE)
36+
set_target_properties(sqlsmith PROPERTIES CXX_STANDARD 20)
37+
endif()
3238

3339
target_link_libraries(sqlsmith PQXX::PQXX)
3440
else (NOT USE_UPSTREAM_LIBPQXX)

config_h.cmake.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#cmakedefine HAVE_BOOST_REGEX 1
88

99
#cmakedefine HAVE_LIBPQXX7 1
10+
#cmakedefine HAVE_LIBPQXX8 1
1011

1112
#cmakedefine HAVE_LIBSQLITE3 1
1213
#cmakedefine HAVE_MONETDB 1

configure.ac

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,25 @@ AC_PROG_CXX
66

77
AX_LIB_POSTGRESQL()
88

9-
PKG_CHECK_MODULES(LIBPQXX, libpqxx < 7.0,
9+
PKG_CHECK_MODULES([LIBPQXX], [libpqxx < 7.0],
1010
[AX_CXX_COMPILE_STDCXX_11(noext,mandatory)],
11-
[PKG_CHECK_MODULES([LIBPQXX], [libpqxx >= 7.0],
11+
[PKG_CHECK_MODULES([LIBPQXX], [libpqxx < 8.0],
1212
[libpqxx7=yes],
13-
[]
13+
[PKG_CHECK_MODULES([LIBPQXX], [libpqxx >= 8.0],
14+
[libpqxx8=yes]
15+
[]
16+
)]
1417
)]
1518
)
1619

1720
AS_IF([test "x$libpqxx7" = "xyes"], AC_MSG_NOTICE([libpqxx version >= 7 detected]), [])
1821
AS_IF([test "x$libpqxx7" = "xyes"], [AC_DEFINE([HAVE_LIBPQXX7], [1], [define if libpqxx >= 7 is used])], [])
1922
AS_IF([test "x$libpqxx7" = "xyes"], [AX_CXX_COMPILE_STDCXX_17(noext,mandatory)], [])
2023

24+
AS_IF([test "x$libpqxx8" = "xyes"], AC_MSG_NOTICE([libpqxx version >= 8 detected]), [])
25+
AS_IF([test "x$libpqxx8" = "xyes"], [AC_DEFINE([HAVE_LIBPQXX8], [1], [define if libpqxx >= 8 is used])], [])
26+
AS_IF([test "x$libpqxx8" = "xyes"], [AX_CXX_COMPILE_STDCXX(20,noext,mandatory)], [])
27+
2128
PKG_CHECK_MODULES(MONETDB_MAPI, monetdb-mapi >= 11.23.0,
2229
[AC_DEFINE([HAVE_MONETDB], [1], [define if the MonetDB client library is available])],
2330
[]

grammar.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ table_subquery::table_subquery(prod *p, bool lateral)
8282
: table_ref(p), is_lateral(lateral) {
8383
query = make_shared<query_spec>(this, scope, lateral);
8484
string alias = scope->stmt_uid("subq");
85-
relation *aliased_rel = &query->select_list->derived_table;
85+
auto *aliased_rel = &query->select_list->derived_table;
8686
refs.push_back(make_shared<aliased_relation>(alias, aliased_rel));
8787
}
8888

@@ -503,7 +503,7 @@ common_table_expression::common_table_expression(prod *parent, struct scope *s)
503503
shared_ptr<query_spec> query = make_shared<query_spec>(this, s);
504504
with_queries.push_back(query);
505505
string alias = scope->stmt_uid("jennifer");
506-
relation *relation = &query->select_list->derived_table;
506+
auto *relation = &query->select_list->derived_table;
507507
auto aliased_rel = make_shared<aliased_relation>(alias, relation);
508508
refs.push_back(aliased_rel);
509509
scope->tables.push_back(&*aliased_rel);

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-
#ifdef HAVE_LIBPQXX7
149+
#if defined(HAVE_LIBPQXX7) || defined(HAVE_LIBPQXX8)
150150
result r = w.exec_prepared("instance", GITREV, target, hostname, s.version, seed.str());
151151
#else
152152
result r = w.prepared("instance")(GITREV)(target)(hostname)(s.version)(seed.str()).exec();
@@ -173,7 +173,7 @@ void pqxx_logger::error(prod &query, const dut::failure &e)
173173
work w(*c);
174174
ostringstream s;
175175
s << query;
176-
#ifdef HAVE_LIBPQXX7
176+
#if defined(HAVE_LIBPQXX7) || defined(HAVE_LIBPQXX8)
177177
w.exec_prepared("error", e.what(), s.str(), e.sqlstate);
178178
#else
179179
w.prepared("error")(e.what())(s.str())(e.sqlstate).exec();
@@ -188,7 +188,7 @@ void pqxx_logger::generated(prod &query)
188188
work w(*c);
189189
ostringstream s;
190190
impedance::report(s);
191-
#ifdef HAVE_LIBPQXX7
191+
#if defined(HAVE_LIBPQXX7) || defined(HAVE_LIBPQXX8)
192192
w.exec_prepared("stat", queries, sum_height/queries, sum_nodes/queries, sum_retries/queries, s.str());
193193
#else
194194
w.prepared("stat")(queries)(sum_height/queries)(sum_nodes/queries)(sum_retries/queries)(s.str()).exec();

postgres.cc

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ dut_pqxx::dut_pqxx(std::string conninfo)
7373
void dut_pqxx::test(const std::string &stmt)
7474
{
7575
try {
76-
#ifndef HAVE_LIBPQXX7
76+
#if !defined(HAVE_LIBPQXX7) && !defined(HAVE_LIBPQXX8)
7777
if(!c.is_open())
7878
c.activate();
7979
#endif
@@ -120,13 +120,24 @@ schema_pqxx::schema_pqxx(std::string &conninfo, bool no_catalog) : c(conninfo)
120120
"from pg_type ");
121121

122122
for (auto row = r.begin(); row != r.end(); ++row) {
123+
#ifdef HAVE_LIBPQXX8
124+
pqxx::row_ref row_ref = row[0];
125+
string name(row_ref[0].as<string>());
126+
OID oid(row_ref[1].as<OID>());
127+
string typdelim(row_ref[2].as<string>());
128+
OID typrelid(row_ref[3].as<OID>());
129+
OID typelem(row_ref[4].as<OID>());
130+
OID typarray(row_ref[5].as<OID>());
131+
string typtype(row_ref[6].as<string>());
132+
#else
123133
string name(row[0].as<string>());
124134
OID oid(row[1].as<OID>());
125135
string typdelim(row[2].as<string>());
126136
OID typrelid(row[3].as<OID>());
127137
OID typelem(row[4].as<OID>());
128138
OID typarray(row[5].as<OID>());
129139
string typtype(row[6].as<string>());
140+
#endif
130141
// if (schema == "pg_catalog")
131142
// continue;
132143
// if (schema == "information_schema")
@@ -154,14 +165,26 @@ schema_pqxx::schema_pqxx(std::string &conninfo, bool no_catalog) : c(conninfo)
154165
"from information_schema.tables");
155166

156167
for (auto row = r.begin(); row != r.end(); ++row) {
168+
#ifdef HAVE_LIBPQXX8
169+
pqxx::row_ref row_ref = row[0];
170+
string schema(row_ref[1].as<string>());
171+
string insertable(row_ref[2].as<string>());
172+
string table_type(row_ref[3].as<string>());
173+
#else
157174
string schema(row[1].as<string>());
158175
string insertable(row[2].as<string>());
159176
string table_type(row[3].as<string>());
177+
#endif
160178

161179
if (no_catalog && ((schema == "pg_catalog") || (schema == "information_schema")))
162180
continue;
163181

164-
tables.push_back(table(row[0].as<string>(),
182+
tables.push_back(
183+
#ifdef HAVE_LIBPQXX8
184+
table(row[0][0].as<string>(),
185+
#else
186+
table(row[0].as<string>(),
187+
#endif
165188
schema,
166189
((insertable == "YES") ? true : false),
167190
((table_type == "BASE TABLE") ? true : false)));
@@ -288,7 +311,7 @@ schema_pqxx::schema_pqxx(std::string &conninfo, bool no_catalog) : c(conninfo)
288311
}
289312
}
290313
cerr << "done." << endl;
291-
#ifdef HAVE_LIBPQXX7
314+
#if defined(HAVE_LIBPQXX7) || defined(HAVE_LIBPQXX8)
292315
c.close();
293316
#else
294317
c.disconnect();

0 commit comments

Comments
 (0)