diff --git a/src/flex-table.cpp b/src/flex-table.cpp index 8a25d35a7..f154e02e5 100644 --- a/src/flex-table.cpp +++ b/src/flex-table.cpp @@ -249,8 +249,8 @@ void table_connection_t::connect(std::string const &conninfo) m_db_connection->exec("SET synchronous_commit = off"); } -static void -enable_check_trigger(pg_conn_t *db_connection, flex_table_t const &table) +static void enable_check_trigger(pg_conn_t const &db_connection, + flex_table_t const &table) { std::string checks; @@ -291,7 +291,7 @@ void table_connection_t::start(bool append) : flex_table_t::table_type::permanent, table().full_name())); - enable_check_trigger(m_db_connection.get(), table()); + enable_check_trigger(*m_db_connection, table()); } prepare(); @@ -310,7 +310,7 @@ void table_connection_t::stop(bool updateable, bool append) if (table().cluster_by_geom()) { if (table().geom_column().needs_isvalid()) { - drop_geom_check_trigger(m_db_connection.get(), table().schema(), + drop_geom_check_trigger(*m_db_connection, table().schema(), table().name()); } @@ -357,7 +357,7 @@ void table_connection_t::stop(bool updateable, bool append) m_id_index_created = false; if (updateable) { - enable_check_trigger(m_db_connection.get(), table()); + enable_check_trigger(*m_db_connection, table()); } } diff --git a/src/pgsql-helper.cpp b/src/pgsql-helper.cpp index f8d0db29d..8d367a6a5 100644 --- a/src/pgsql-helper.cpp +++ b/src/pgsql-helper.cpp @@ -25,7 +25,7 @@ idlist_t get_ids_from_result(pg_result_t const &result) { return ids; } -void create_geom_check_trigger(pg_conn_t *db_connection, +void create_geom_check_trigger(pg_conn_t const &db_connection, std::string const &schema, std::string const &table, std::string const &condition) @@ -33,38 +33,37 @@ void create_geom_check_trigger(pg_conn_t *db_connection, std::string const func_name = qualified_name(schema, table + "_osm2pgsql_valid"); - db_connection->exec("CREATE OR REPLACE FUNCTION {}()\n" - "RETURNS TRIGGER AS $$\n" - "BEGIN\n" - " IF {} THEN \n" - " RETURN NEW;\n" - " END IF;\n" - " RETURN NULL;\n" - "END;" - "$$ LANGUAGE plpgsql", - func_name, condition); + db_connection.exec("CREATE OR REPLACE FUNCTION {}()\n" + "RETURNS TRIGGER AS $$\n" + "BEGIN\n" + " IF {} THEN \n" + " RETURN NEW;\n" + " END IF;\n" + " RETURN NULL;\n" + "END;" + "$$ LANGUAGE plpgsql", + func_name, condition); - db_connection->exec("CREATE TRIGGER \"{}\"" - " BEFORE INSERT OR UPDATE" - " ON {}" - " FOR EACH ROW EXECUTE PROCEDURE" - " {}()", - table + "_osm2pgsql_valid", - qualified_name(schema, table), func_name); + db_connection.exec("CREATE TRIGGER \"{}\"" + " BEFORE INSERT OR UPDATE" + " ON {}" + " FOR EACH ROW EXECUTE PROCEDURE" + " {}()", + table + "_osm2pgsql_valid", + qualified_name(schema, table), func_name); } -void drop_geom_check_trigger(pg_conn_t *db_connection, +void drop_geom_check_trigger(pg_conn_t const &db_connection, std::string const &schema, std::string const &table) { std::string const func_name = qualified_name(schema, table + "_osm2pgsql_valid"); - db_connection->exec(R"(DROP TRIGGER "{}" ON {})", - table + "_osm2pgsql_valid", - qualified_name(schema, table)); + db_connection.exec(R"(DROP TRIGGER "{}" ON {})", table + "_osm2pgsql_valid", + qualified_name(schema, table)); - db_connection->exec("DROP FUNCTION IF EXISTS {} ()", func_name); + db_connection.exec("DROP FUNCTION IF EXISTS {} ()", func_name); } void analyze_table(pg_conn_t const &db_connection, std::string const &schema, diff --git a/src/pgsql-helper.hpp b/src/pgsql-helper.hpp index 52f187e14..15a46785d 100644 --- a/src/pgsql-helper.hpp +++ b/src/pgsql-helper.hpp @@ -27,12 +27,12 @@ class pg_result_t; */ idlist_t get_ids_from_result(pg_result_t const &result); -void create_geom_check_trigger(pg_conn_t *db_connection, +void create_geom_check_trigger(pg_conn_t const &db_connection, std::string const &schema, std::string const &table, std::string const &condition); -void drop_geom_check_trigger(pg_conn_t *db_connection, +void drop_geom_check_trigger(pg_conn_t const &db_connection, std::string const &schema, std::string const &table); diff --git a/src/table.cpp b/src/table.cpp index 9d148831d..d8f8b446c 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -132,7 +132,7 @@ void table_t::start(std::string const &conninfo, std::string const &table_space) m_sql_conn->exec(sql); if (m_srid != "4326") { - create_geom_check_trigger(m_sql_conn.get(), m_target->schema(), + create_geom_check_trigger(*m_sql_conn, m_target->schema(), m_target->name(), "ST_IsValid(NEW.way)"); } } @@ -188,7 +188,7 @@ void table_t::stop(bool updateable, bool enable_hstore_index, if (!m_append) { if (m_srid != "4326") { - drop_geom_check_trigger(m_sql_conn.get(), m_target->schema(), + drop_geom_check_trigger(*m_sql_conn, m_target->schema(), m_target->name()); } @@ -237,7 +237,7 @@ void table_t::stop(bool updateable, bool enable_hstore_index, m_sql_conn->exec("CREATE INDEX ON {} USING BTREE (osm_id) {}", qual_name, tablespace_clause(table_space_index)); if (m_srid != "4326") { - create_geom_check_trigger(m_sql_conn.get(), m_target->schema(), + create_geom_check_trigger(*m_sql_conn, m_target->schema(), m_target->name(), "ST_IsValid(NEW.way)"); }