Skip to content

Commit 229d832

Browse files
authored
Merge pull request #2125 from joto/refactor-db-connection
Refactor db connection: Use const ref instead of ptr
2 parents 3e79e6e + 0a9e7de commit 229d832

File tree

4 files changed

+32
-33
lines changed

4 files changed

+32
-33
lines changed

src/flex-table.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ void table_connection_t::connect(std::string const &conninfo)
249249
m_db_connection->exec("SET synchronous_commit = off");
250250
}
251251

252-
static void
253-
enable_check_trigger(pg_conn_t *db_connection, flex_table_t const &table)
252+
static void enable_check_trigger(pg_conn_t const &db_connection,
253+
flex_table_t const &table)
254254
{
255255
std::string checks;
256256

@@ -291,7 +291,7 @@ void table_connection_t::start(bool append)
291291
: flex_table_t::table_type::permanent,
292292
table().full_name()));
293293

294-
enable_check_trigger(m_db_connection.get(), table());
294+
enable_check_trigger(*m_db_connection, table());
295295
}
296296

297297
prepare();
@@ -310,7 +310,7 @@ void table_connection_t::stop(bool updateable, bool append)
310310

311311
if (table().cluster_by_geom()) {
312312
if (table().geom_column().needs_isvalid()) {
313-
drop_geom_check_trigger(m_db_connection.get(), table().schema(),
313+
drop_geom_check_trigger(*m_db_connection, table().schema(),
314314
table().name());
315315
}
316316

@@ -357,7 +357,7 @@ void table_connection_t::stop(bool updateable, bool append)
357357
m_id_index_created = false;
358358

359359
if (updateable) {
360-
enable_check_trigger(m_db_connection.get(), table());
360+
enable_check_trigger(*m_db_connection, table());
361361
}
362362
}
363363

src/pgsql-helper.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,45 @@ idlist_t get_ids_from_result(pg_result_t const &result) {
2525
return ids;
2626
}
2727

28-
void create_geom_check_trigger(pg_conn_t *db_connection,
28+
void create_geom_check_trigger(pg_conn_t const &db_connection,
2929
std::string const &schema,
3030
std::string const &table,
3131
std::string const &condition)
3232
{
3333
std::string const func_name =
3434
qualified_name(schema, table + "_osm2pgsql_valid");
3535

36-
db_connection->exec("CREATE OR REPLACE FUNCTION {}()\n"
37-
"RETURNS TRIGGER AS $$\n"
38-
"BEGIN\n"
39-
" IF {} THEN \n"
40-
" RETURN NEW;\n"
41-
" END IF;\n"
42-
" RETURN NULL;\n"
43-
"END;"
44-
"$$ LANGUAGE plpgsql",
45-
func_name, condition);
36+
db_connection.exec("CREATE OR REPLACE FUNCTION {}()\n"
37+
"RETURNS TRIGGER AS $$\n"
38+
"BEGIN\n"
39+
" IF {} THEN \n"
40+
" RETURN NEW;\n"
41+
" END IF;\n"
42+
" RETURN NULL;\n"
43+
"END;"
44+
"$$ LANGUAGE plpgsql",
45+
func_name, condition);
4646

47-
db_connection->exec("CREATE TRIGGER \"{}\""
48-
" BEFORE INSERT OR UPDATE"
49-
" ON {}"
50-
" FOR EACH ROW EXECUTE PROCEDURE"
51-
" {}()",
52-
table + "_osm2pgsql_valid",
53-
qualified_name(schema, table), func_name);
47+
db_connection.exec("CREATE TRIGGER \"{}\""
48+
" BEFORE INSERT OR UPDATE"
49+
" ON {}"
50+
" FOR EACH ROW EXECUTE PROCEDURE"
51+
" {}()",
52+
table + "_osm2pgsql_valid",
53+
qualified_name(schema, table), func_name);
5454
}
5555

56-
void drop_geom_check_trigger(pg_conn_t *db_connection,
56+
void drop_geom_check_trigger(pg_conn_t const &db_connection,
5757
std::string const &schema,
5858
std::string const &table)
5959
{
6060
std::string const func_name =
6161
qualified_name(schema, table + "_osm2pgsql_valid");
6262

63-
db_connection->exec(R"(DROP TRIGGER "{}" ON {})",
64-
table + "_osm2pgsql_valid",
65-
qualified_name(schema, table));
63+
db_connection.exec(R"(DROP TRIGGER "{}" ON {})", table + "_osm2pgsql_valid",
64+
qualified_name(schema, table));
6665

67-
db_connection->exec("DROP FUNCTION IF EXISTS {} ()", func_name);
66+
db_connection.exec("DROP FUNCTION IF EXISTS {} ()", func_name);
6867
}
6968

7069
void analyze_table(pg_conn_t const &db_connection, std::string const &schema,

src/pgsql-helper.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class pg_result_t;
2727
*/
2828
idlist_t get_ids_from_result(pg_result_t const &result);
2929

30-
void create_geom_check_trigger(pg_conn_t *db_connection,
30+
void create_geom_check_trigger(pg_conn_t const &db_connection,
3131
std::string const &schema,
3232
std::string const &table,
3333
std::string const &condition);
3434

35-
void drop_geom_check_trigger(pg_conn_t *db_connection,
35+
void drop_geom_check_trigger(pg_conn_t const &db_connection,
3636
std::string const &schema,
3737
std::string const &table);
3838

src/table.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void table_t::start(std::string const &conninfo, std::string const &table_space)
132132
m_sql_conn->exec(sql);
133133

134134
if (m_srid != "4326") {
135-
create_geom_check_trigger(m_sql_conn.get(), m_target->schema(),
135+
create_geom_check_trigger(*m_sql_conn, m_target->schema(),
136136
m_target->name(), "ST_IsValid(NEW.way)");
137137
}
138138
}
@@ -188,7 +188,7 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
188188

189189
if (!m_append) {
190190
if (m_srid != "4326") {
191-
drop_geom_check_trigger(m_sql_conn.get(), m_target->schema(),
191+
drop_geom_check_trigger(*m_sql_conn, m_target->schema(),
192192
m_target->name());
193193
}
194194

@@ -237,7 +237,7 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
237237
m_sql_conn->exec("CREATE INDEX ON {} USING BTREE (osm_id) {}",
238238
qual_name, tablespace_clause(table_space_index));
239239
if (m_srid != "4326") {
240-
create_geom_check_trigger(m_sql_conn.get(), m_target->schema(),
240+
create_geom_check_trigger(*m_sql_conn, m_target->schema(),
241241
m_target->name(),
242242
"ST_IsValid(NEW.way)");
243243
}

0 commit comments

Comments
 (0)