diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-11-15 17:47:20 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-11-15 17:47:20 +0200 |
commit | 4d61ee5a20babf92e0860a3d34bb0c0f0920dd67 (patch) | |
tree | 590cfb5ea3859992a6af0d70034516c4b9d19d29 /evolution/embedded | |
parent | 791a918ba26cfc59c0009e94de43b88cb697f4fb (diff) |
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.
Diffstat (limited to 'evolution/embedded')
-rw-r--r-- | evolution/embedded/driver.cxx | 18 |
1 files 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 <common/config.hxx> // DATABASE_XXX #include <common/common.hxx> +#ifdef DATABASE_PGSQL +# include <odb/pgsql/connection.hxx> +#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<odb::pgsql::connection&> (*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 ()); |