@@ -73,10 +73,9 @@ pg_result_t middle_query_pgsql_t::exec_prepared(char const *stmt,
7373pg_result_t middle_pgsql_t::exec_prepared (char const *stmt,
7474 osmid_t osm_id) const
7575{
76- assert (m_query_conn);
7776 util::integer_to_buffer buffer{osm_id};
7877 char const *const bptr = buffer.c_str ();
79- return m_query_conn-> exec_prepared (stmt, 1 , &bptr);
78+ return m_db_connection. exec_prepared (stmt, 1 , &bptr);
8079}
8180
8281void middle_query_pgsql_t::exec_sql (std::string const &sql_cmd) const
@@ -587,9 +586,8 @@ idlist_t middle_query_pgsql_t::relations_using_way(osmid_t way_id) const
587586
588587void middle_pgsql_t::analyze ()
589588{
590- assert (m_query_conn);
591589 for (auto const &table : m_tables) {
592- m_query_conn-> exec (" ANALYZE {}" _format (table.name ()));
590+ m_db_connection. exec (" ANALYZE {}" _format (table.name ()));
593591 }
594592}
595593
@@ -615,28 +613,25 @@ void middle_pgsql_t::start()
615613 m_mark_pending = false ;
616614 }
617615
618- m_query_conn.reset (
619- new pg_conn_t {m_out_options->database_options .conninfo ()});
620-
621616 if (m_append) {
622617 // Prepare queries for updating dependent objects
623618 for (auto &table : m_tables) {
624619 if (!table.m_prepare_intarray .empty ()) {
625- m_query_conn-> exec (table.m_prepare_intarray );
620+ m_db_connection. exec (table.m_prepare_intarray );
626621 }
627622 }
628623 } else {
629624 // (Re)create tables.
630- m_query_conn-> exec (" SET client_min_messages = WARNING" );
625+ m_db_connection. exec (" SET client_min_messages = WARNING" );
631626 for (auto &table : m_tables) {
632627 fmt::print (stderr, " Setting up table: {}\n " , table.name ());
633- m_query_conn-> exec (
628+ m_db_connection. exec (
634629 " DROP TABLE IF EXISTS {} CASCADE" _format (table.name ()));
635- m_query_conn-> exec (table.m_create );
630+ m_db_connection. exec (table.m_create );
636631 }
637632
638633 // The extra query connection is only needed in append mode, so close.
639- m_query_conn. reset ();
634+ m_db_connection. close ();
640635 }
641636}
642637
@@ -646,7 +641,7 @@ void middle_pgsql_t::commit()
646641 // release the copy thread and its query connection
647642 m_copy_thread->finish ();
648643
649- m_query_conn. reset ();
644+ m_db_connection. close ();
650645}
651646
652647void middle_pgsql_t::flush () { m_db_copy.sync (); }
@@ -775,6 +770,7 @@ middle_pgsql_t::middle_pgsql_t(options_t const *options)
775770: m_append(options->append), m_mark_pending(true ), m_out_options(options),
776771 m_cache (new node_ram_cache{options->alloc_chunkwise | ALLOC_LOSSY,
777772 options->cache }),
773+ m_db_connection(m_out_options->database_options.conninfo()),
778774 m_copy_thread(
779775 std::make_shared<db_copy_thread_t >(options->database_options.conninfo())),
780776 m_db_copy(m_copy_thread)
0 commit comments