Skip to content

Commit e677068

Browse files
committed
Use fmt for COPY command
1 parent cf75b79 commit e677068

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/db-copy.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,17 @@ void db_copy_thread_t::thread_t::start_copy(
176176
{
177177
assert(!m_inflight);
178178

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 += ')';
179+
fmt::memory_buffer sql;
180+
sql.reserve(target->name.size() + target->rows.size() + 14);
181+
if (target->rows.empty()) {
182+
fmt::format_to(sql, FMT_STRING("COPY {} FROM STDIN"), target->name);
183+
} else {
184+
fmt::format_to(sql, FMT_STRING("COPY {} ({}) FROM STDIN"), target->name,
185+
target->rows);
186186
}
187-
copystr += " FROM STDIN";
188-
m_conn->query(PGRES_COPY_IN, copystr);
187+
188+
sql.push_back('\0');
189+
m_conn->query(PGRES_COPY_IN, sql.data());
189190

190191
m_inflight = target;
191192
}

0 commit comments

Comments
 (0)