@@ -54,25 +54,26 @@ table_t::table_t(table_t const &other,
54
54
// if the other table has already started, then we want to execute
55
55
// the same stuff to get into the same state. but if it hasn't, then
56
56
// this would be premature.
57
- if (other.m_sql_conn ) {
57
+ if (other.m_db_connection ) {
58
58
connect ();
59
59
prepare ();
60
60
}
61
61
}
62
62
63
- void table_t::teardown () { m_sql_conn .reset (); }
63
+ void table_t::teardown () { m_db_connection .reset (); }
64
64
65
65
void table_t::sync () { m_copy.sync (); }
66
66
67
67
void table_t::connect ()
68
68
{
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" );
70
71
}
71
72
72
73
void table_t::start (connection_params_t const &connection_params,
73
74
std::string const &table_space)
74
75
{
75
- if (m_sql_conn ) {
76
+ if (m_db_connection ) {
76
77
throw fmt_error (" {} cannot start, its already started." ,
77
78
m_target->name ());
78
79
}
@@ -88,11 +89,11 @@ void table_t::start(connection_params_t const &connection_params,
88
89
89
90
// we are making a new table
90
91
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);
92
93
}
93
94
94
95
// 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);
96
97
97
98
// making a new table
98
99
if (!m_append) {
@@ -128,10 +129,10 @@ void table_t::start(connection_params_t const &connection_params,
128
129
sql += m_table_space;
129
130
130
131
// create the table
131
- m_sql_conn ->exec (sql);
132
+ m_db_connection ->exec (sql);
132
133
133
134
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 (),
135
136
m_target->name (), " ST_IsValid(NEW.way)" );
136
137
}
137
138
}
@@ -143,9 +144,9 @@ void table_t::prepare()
143
144
{
144
145
// let postgres cache this query as it will presumably happen a lot
145
146
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);
149
150
}
150
151
151
152
void table_t::generate_copy_column_list ()
@@ -187,7 +188,7 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
187
188
188
189
if (!m_append) {
189
190
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 (),
191
192
m_target->name ());
192
193
}
193
194
@@ -216,27 +217,29 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
216
217
sql += " way" ;
217
218
}
218
219
219
- m_sql_conn ->exec (sql);
220
+ m_db_connection ->exec (sql);
220
221
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 ());
224
225
225
226
log_info (" Creating geometry index on table '{}'..." , m_target->name ());
226
227
227
228
// 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));
231
233
232
234
/* slim mode needs this to be able to apply diffs */
233
235
if (updateable) {
234
236
log_info (" Creating osm_id index on table '{}'..." ,
235
237
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));
238
241
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 (),
240
243
m_target->name (),
241
244
" ST_IsValid(NEW.way)" );
242
245
}
@@ -247,18 +250,18 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
247
250
log_info (" Creating hstore indexes on table '{}'..." ,
248
251
m_target->name ());
249
252
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));
253
256
}
254
257
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));
258
261
}
259
262
}
260
263
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 ());
262
265
}
263
266
teardown ();
264
267
}
@@ -444,6 +447,6 @@ void table_t::escape_type(std::string const &value, ColumnType flags)
444
447
445
448
pg_result_t table_t::get_wkb (osmid_t id)
446
449
{
447
- return m_sql_conn ->exec_prepared_as_binary (" get_wkb" , id);
450
+ return m_db_connection ->exec_prepared_as_binary (" get_wkb" , id);
448
451
}
449
452
0 commit comments