@@ -21,7 +21,8 @@ void db_deleter_by_id_t::delete_rows(std::string const &table,
2121 }
2222 sql[sql.size () - 1 ] = ' )' ;
2323
24- conn->exec (fmt::to_string (sql));
24+ sql.push_back (' \0 ' );
25+ conn->exec (sql.data ());
2526}
2627
2728void db_deleter_by_type_and_id_t::delete_rows (std::string const &table,
@@ -54,8 +55,6 @@ void db_deleter_by_type_and_id_t::delete_rows(std::string const &table,
5455 " ) AS t (osm_type, osm_id) WHERE"
5556 " p.{} = t.osm_type AND p.{} = t.osm_id" ,
5657 type, column.c_str () + pos + 1 );
57-
58- conn->exec (fmt::to_string (sql));
5958 } else {
6059 fmt::format_to (sql, FMT_STRING (" DELETE FROM {} WHERE {} IN (" ), table,
6160 column);
@@ -64,8 +63,10 @@ void db_deleter_by_type_and_id_t::delete_rows(std::string const &table,
6463 format_to (sql, FMT_STRING (" {}," ), item.osm_id );
6564 }
6665 sql[sql.size () - 1 ] = ' )' ;
67- conn->exec (fmt::to_string (sql));
6866 }
67+
68+ sql.push_back (' \0 ' );
69+ conn->exec (sql.data ());
6970}
7071
7172db_copy_thread_t ::db_copy_thread_t (std::string const &conninfo)
@@ -176,16 +177,17 @@ void db_copy_thread_t::thread_t::start_copy(
176177{
177178 assert (!m_inflight);
178179
179- std::string copystr = " COPY " ;
180- copystr .reserve (target->name .size () + target->rows .size () + 14 );
181- copystr += target->name ;
182- if (! target->rows . empty ()) {
183- copystr += ' ( ' ;
184- copystr += target->rows ;
185- copystr += ' ) ' ;
180+ fmt::memory_buffer sql ;
181+ sql .reserve (target->name .size () + target->rows .size () + 14 );
182+ if ( target->rows . empty ()) {
183+ fmt::format_to (sql, FMT_STRING ( " COPY {} FROM STDIN " ), target->name );
184+ } else {
185+ fmt::format_to (sql, FMT_STRING ( " COPY {} ({}) FROM STDIN " ), target->name ,
186+ target-> rows ) ;
186187 }
187- copystr += " FROM STDIN" ;
188- m_conn->query (PGRES_COPY_IN, copystr);
188+
189+ sql.push_back (' \0 ' );
190+ m_conn->query (PGRES_COPY_IN, sql.data ());
189191
190192 m_inflight = target;
191193}
0 commit comments