Skip to content

Commit 9e6deff

Browse files
committed
Consistently use db_connection as param/var name
for database connections. Also use it as const ref instead of ptr.
1 parent 73c622b commit 9e6deff

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

src/db-copy.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
#include "pgsql.hpp"
1616

1717
void db_deleter_by_id_t::delete_rows(std::string const &table,
18-
std::string const &column, pg_conn_t *conn)
18+
std::string const &column,
19+
pg_conn_t const &db_connection)
1920
{
2021
fmt::memory_buffer sql;
2122
// Each deletable contributes an OSM ID and a comma. The highest node ID
@@ -32,12 +33,12 @@ void db_deleter_by_id_t::delete_rows(std::string const &table,
3233
sql[sql.size() - 1] = ')';
3334

3435
sql.push_back('\0');
35-
conn->exec(sql.data());
36+
db_connection.exec(sql.data());
3637
}
3738

3839
void db_deleter_by_type_and_id_t::delete_rows(std::string const &table,
3940
std::string const &column,
40-
pg_conn_t *conn)
41+
pg_conn_t const &db_connection)
4142
{
4243
assert(!m_deletables.empty());
4344

@@ -78,7 +79,7 @@ void db_deleter_by_type_and_id_t::delete_rows(std::string const &table,
7879
}
7980

8081
sql.push_back('\0');
81-
conn->exec(sql.data());
82+
db_connection.exec(sql.data());
8283
}
8384

8485
db_copy_thread_t::db_copy_thread_t(connection_params_t const &connection_params)
@@ -182,7 +183,7 @@ void db_copy_thread_t::thread_t::write_to_db(db_cmd_copy_t *buffer)
182183
finish_copy();
183184
}
184185

185-
buffer->delete_data(m_db_connection.get());
186+
buffer->delete_data(*m_db_connection);
186187

187188
if (!m_inflight) {
188189
start_copy(buffer->target);

src/db-copy.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class db_deleter_by_id_t
8585
void add(osmid_t osm_id) { m_deletables.push_back(osm_id); }
8686

8787
void delete_rows(std::string const &table, std::string const &column,
88-
pg_conn_t *conn);
88+
pg_conn_t const &db_connection);
8989

9090
bool is_full() const noexcept { return m_deletables.size() > Max_entries; }
9191

@@ -126,7 +126,7 @@ class db_deleter_by_type_and_id_t
126126
}
127127

128128
void delete_rows(std::string const &table, std::string const &column,
129-
pg_conn_t *conn);
129+
pg_conn_t const &db_connection);
130130

131131
bool is_full() const noexcept { return m_deletables.size() > Max_entries; }
132132

@@ -183,7 +183,7 @@ struct db_cmd_copy_t : public db_cmd_t
183183
std::string buffer;
184184

185185
virtual bool has_deletables() const noexcept = 0;
186-
virtual void delete_data(pg_conn_t *conn) = 0;
186+
virtual void delete_data(pg_conn_t const &db_connection) = 0;
187187

188188
explicit db_cmd_copy_t(std::shared_ptr<db_target_descr_t> t)
189189
: db_cmd_t(db_cmd_t::Cmd_copy), target(std::move(t))
@@ -209,12 +209,12 @@ class db_cmd_copy_delete_t : public db_cmd_copy_t
209209
return m_deleter.has_data();
210210
}
211211

212-
void delete_data(pg_conn_t *conn) override
212+
void delete_data(pg_conn_t const &db_connection) override
213213
{
214214
if (m_deleter.has_data()) {
215215
m_deleter.delete_rows(
216216
qualified_name(target->schema(), target->name()), target->id(),
217-
conn);
217+
db_connection);
218218
}
219219
}
220220

src/expire-output.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,38 +58,38 @@ std::size_t expire_output_t::output_tiles_to_table(
5858
{
5959
auto const qn = qualified_name(m_schema, m_table);
6060

61-
pg_conn_t connection{connection_params, "expire"};
61+
pg_conn_t const db_connection{connection_params, "expire"};
6262

63-
auto const result = connection.exec("SELECT * FROM {} LIMIT 1", qn);
63+
auto const result = db_connection.exec("SELECT * FROM {} LIMIT 1", qn);
6464

6565
if (result.num_fields() == 3) {
6666
// old format with fields: zoom, x, y
67-
connection.exec("PREPARE insert_tiles(int4, int4, int4) AS"
68-
" INSERT INTO {} (zoom, x, y) VALUES ($1, $2, $3)"
69-
" ON CONFLICT DO NOTHING",
70-
qn);
67+
db_connection.exec("PREPARE insert_tiles(int4, int4, int4) AS"
68+
" INSERT INTO {} (zoom, x, y) VALUES ($1, $2, $3)"
69+
" ON CONFLICT DO NOTHING",
70+
qn);
7171
} else {
7272
// new format with fields: zoom, x, y, first, last
73-
connection.exec("PREPARE insert_tiles(int4, int4, int4) AS"
74-
" INSERT INTO {} (zoom, x, y) VALUES ($1, $2, $3)"
75-
" ON CONFLICT (zoom, x, y)"
76-
" DO UPDATE SET last = CURRENT_TIMESTAMP(0)",
77-
qn);
73+
db_connection.exec("PREPARE insert_tiles(int4, int4, int4) AS"
74+
" INSERT INTO {} (zoom, x, y) VALUES ($1, $2, $3)"
75+
" ON CONFLICT (zoom, x, y)"
76+
" DO UPDATE SET last = CURRENT_TIMESTAMP(0)",
77+
qn);
7878
}
7979

8080
auto const count = for_each_tile(
8181
tiles_at_maxzoom, m_minzoom, m_maxzoom, [&](tile_t const &tile) {
82-
connection.exec_prepared("insert_tiles", tile.zoom(), tile.x(),
83-
tile.y());
82+
db_connection.exec_prepared("insert_tiles", tile.zoom(), tile.x(),
83+
tile.y());
8484
});
8585

8686
return count;
8787
}
8888

89-
void expire_output_t::create_output_table(pg_conn_t const &connection) const
89+
void expire_output_t::create_output_table(pg_conn_t const &db_connection) const
9090
{
9191
auto const qn = qualified_name(m_schema, m_table);
92-
connection.exec(
92+
db_connection.exec(
9393
"CREATE TABLE IF NOT EXISTS {} ("
9494
" zoom int4 NOT NULL,"
9595
" x int4 NOT NULL,"

src/expire-output.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class expire_output_t
7676
/**
7777
* Create table for tiles.
7878
*/
79-
void create_output_table(pg_conn_t const &connection) const;
79+
void create_output_table(pg_conn_t const &db_connection) const;
8080

8181
private:
8282
/// The filename (if any) for output

0 commit comments

Comments
 (0)