Skip to content

Commit ba56530

Browse files
committed
Consistently use name m_db_connection in table.[ch]pp
Instead of using m_sql_conn.
1 parent 0343ae8 commit ba56530

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

src/table.cpp

+33-30
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,26 @@ table_t::table_t(table_t const &other,
5454
// if the other table has already started, then we want to execute
5555
// the same stuff to get into the same state. but if it hasn't, then
5656
// this would be premature.
57-
if (other.m_sql_conn) {
57+
if (other.m_db_connection) {
5858
connect();
5959
prepare();
6060
}
6161
}
6262

63-
void table_t::teardown() { m_sql_conn.reset(); }
63+
void table_t::teardown() { m_db_connection.reset(); }
6464

6565
void table_t::sync() { m_copy.sync(); }
6666

6767
void table_t::connect()
6868
{
69-
m_sql_conn = std::make_unique<pg_conn_t>(m_connection_params, "out.pgsql");
69+
m_db_connection =
70+
std::make_unique<pg_conn_t>(m_connection_params, "out.pgsql");
7071
}
7172

7273
void table_t::start(connection_params_t const &connection_params,
7374
std::string const &table_space)
7475
{
75-
if (m_sql_conn) {
76+
if (m_db_connection) {
7677
throw fmt_error("{} cannot start, its already started.",
7778
m_target->name());
7879
}
@@ -88,11 +89,11 @@ void table_t::start(connection_params_t const &connection_params,
8889

8990
// we are making a new table
9091
if (!m_append) {
91-
m_sql_conn->exec("DROP TABLE IF EXISTS {} CASCADE", qual_name);
92+
m_db_connection->exec("DROP TABLE IF EXISTS {} CASCADE", qual_name);
9293
}
9394

9495
// These _tmp tables can be left behind if we run out of disk space.
95-
m_sql_conn->exec("DROP TABLE IF EXISTS {}", qual_tmp_name);
96+
m_db_connection->exec("DROP TABLE IF EXISTS {}", qual_tmp_name);
9697

9798
//making a new table
9899
if (!m_append) {
@@ -128,10 +129,10 @@ void table_t::start(connection_params_t const &connection_params,
128129
sql += m_table_space;
129130

130131
//create the table
131-
m_sql_conn->exec(sql);
132+
m_db_connection->exec(sql);
132133

133134
if (m_srid != "4326") {
134-
create_geom_check_trigger(*m_sql_conn, m_target->schema(),
135+
create_geom_check_trigger(*m_db_connection, m_target->schema(),
135136
m_target->name(), "ST_IsValid(NEW.way)");
136137
}
137138
}
@@ -143,9 +144,9 @@ void table_t::prepare()
143144
{
144145
//let postgres cache this query as it will presumably happen a lot
145146
auto const qual_name = qualified_name(m_target->schema(), m_target->name());
146-
m_sql_conn->exec("PREPARE get_wkb(int8) AS"
147-
" SELECT way FROM {} WHERE osm_id = $1",
148-
qual_name);
147+
m_db_connection->exec("PREPARE get_wkb(int8) AS"
148+
" SELECT way FROM {} WHERE osm_id = $1",
149+
qual_name);
149150
}
150151

151152
void table_t::generate_copy_column_list()
@@ -187,7 +188,7 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
187188

188189
if (!m_append) {
189190
if (m_srid != "4326") {
190-
drop_geom_check_trigger(*m_sql_conn, m_target->schema(),
191+
drop_geom_check_trigger(*m_db_connection, m_target->schema(),
191192
m_target->name());
192193
}
193194

@@ -216,27 +217,29 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
216217
sql += "way";
217218
}
218219

219-
m_sql_conn->exec(sql);
220+
m_db_connection->exec(sql);
220221

221-
m_sql_conn->exec("DROP TABLE {}", qual_name);
222-
m_sql_conn->exec(R"(ALTER TABLE {} RENAME TO "{}")", qual_tmp_name,
223-
m_target->name());
222+
m_db_connection->exec("DROP TABLE {}", qual_name);
223+
m_db_connection->exec(R"(ALTER TABLE {} RENAME TO "{}")", qual_tmp_name,
224+
m_target->name());
224225

225226
log_info("Creating geometry index on table '{}'...", m_target->name());
226227

227228
// Use fillfactor 100 for un-updatable imports
228-
m_sql_conn->exec("CREATE INDEX ON {} USING GIST (way) {} {}", qual_name,
229-
(updateable ? "" : "WITH (fillfactor = 100)"),
230-
tablespace_clause(table_space_index));
229+
m_db_connection->exec("CREATE INDEX ON {} USING GIST (way) {} {}",
230+
qual_name,
231+
(updateable ? "" : "WITH (fillfactor = 100)"),
232+
tablespace_clause(table_space_index));
231233

232234
/* slim mode needs this to be able to apply diffs */
233235
if (updateable) {
234236
log_info("Creating osm_id index on table '{}'...",
235237
m_target->name());
236-
m_sql_conn->exec("CREATE INDEX ON {} USING BTREE (osm_id) {}",
237-
qual_name, tablespace_clause(table_space_index));
238+
m_db_connection->exec("CREATE INDEX ON {} USING BTREE (osm_id) {}",
239+
qual_name,
240+
tablespace_clause(table_space_index));
238241
if (m_srid != "4326") {
239-
create_geom_check_trigger(*m_sql_conn, m_target->schema(),
242+
create_geom_check_trigger(*m_db_connection, m_target->schema(),
240243
m_target->name(),
241244
"ST_IsValid(NEW.way)");
242245
}
@@ -247,18 +250,18 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
247250
log_info("Creating hstore indexes on table '{}'...",
248251
m_target->name());
249252
if (m_hstore_mode != hstore_column::none) {
250-
m_sql_conn->exec("CREATE INDEX ON {} USING GIN (tags) {}",
251-
qual_name,
252-
tablespace_clause(table_space_index));
253+
m_db_connection->exec("CREATE INDEX ON {} USING GIN (tags) {}",
254+
qual_name,
255+
tablespace_clause(table_space_index));
253256
}
254257
for (auto const &hcolumn : m_hstore_columns) {
255-
m_sql_conn->exec(R"(CREATE INDEX ON {} USING GIN ("{}") {})",
256-
qual_name, hcolumn,
257-
tablespace_clause(table_space_index));
258+
m_db_connection->exec(
259+
R"(CREATE INDEX ON {} USING GIN ("{}") {})", qual_name,
260+
hcolumn, tablespace_clause(table_space_index));
258261
}
259262
}
260263
log_info("Analyzing table '{}'...", m_target->name());
261-
analyze_table(*m_sql_conn, m_target->schema(), m_target->name());
264+
analyze_table(*m_db_connection, m_target->schema(), m_target->name());
262265
}
263266
teardown();
264267
}
@@ -444,6 +447,6 @@ void table_t::escape_type(std::string const &value, ColumnType flags)
444447

445448
pg_result_t table_t::get_wkb(osmid_t id)
446449
{
447-
return m_sql_conn->exec_prepared_as_binary("get_wkb", id);
450+
return m_db_connection->exec_prepared_as_binary("get_wkb", id);
448451
}
449452

src/table.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class table_t
7373
connection_params_t m_connection_params;
7474
std::shared_ptr<db_target_descr_t> m_target;
7575
std::string m_type;
76-
std::unique_ptr<pg_conn_t> m_sql_conn;
76+
std::unique_ptr<pg_conn_t> m_db_connection;
7777
std::string m_srid;
7878
bool m_append;
7979
hstore_column m_hstore_mode;

0 commit comments

Comments
 (0)