From 4d61ee5a20babf92e0860a3d34bb0c0f0920dd67 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 15 Nov 2017 17:47:20 +0200 Subject: Work around PostgreSQL transaction poisoning in schema version query Note that this only works in 9.4+. For older versions the workaround is to "pre-call" database::schema_version() outside of any transaction. --- evolution/embedded/driver.cxx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/evolution/embedded/driver.cxx b/evolution/embedded/driver.cxx index 8966c5b..1cae9de 100644 --- a/evolution/embedded/driver.cxx +++ b/evolution/embedded/driver.cxx @@ -16,6 +16,10 @@ #include // DATABASE_XXX #include +#ifdef DATABASE_PGSQL +# include +#endif + #include "test2.hxx" #include "test3.hxx" #include "test2-odb.hxx" @@ -49,12 +53,22 @@ main (int argc, char* argv[]) t.commit (); } - // PostgreSQL cannot continue a transaction after a query failed. + // PostgreSQL cannot continue a transaction after a query failed. We + // have a workaround but only for 9.4+. // - assert (db->schema_version () == 0); +#ifdef DATABASE_PGSQL + { + odb::connection_ptr c (db->connection ()); + int v (static_cast (*c).server_version ()); + if (v < 90400) + assert (db->schema_version () == 0); + } +#endif { transaction t (db->begin ()); + assert (db->schema_version () == 0); + schema_catalog::create_schema (*db, "", false); assert (db->schema_version () == 1 && !db->schema_migration ()); -- cgit v1.1