Skip to content

Commit ee34d25

Browse files
committed
Refactor: Use std::string not std::string_view in copy_start()
Because std::string guarantees that there is a \0 at the end which we need for the C interface of the PostgreSQL library. Gets rid of clang-tidy warnings.
1 parent 3c7d0e2 commit ee34d25

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/db-copy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void db_copy_thread_t::thread_t::start_copy(
221221
}
222222

223223
sql.push_back('\0');
224-
m_db_connection.copy_start(sql.data());
224+
m_db_connection.copy_start(to_string(sql));
225225

226226
m_inflight = target;
227227
}

src/pgsql.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ pg_result_t pg_conn_t::exec(std::string const &sql) const
136136
return exec(sql.c_str());
137137
}
138138

139-
void pg_conn_t::copy_start(std::string_view sql) const
139+
void pg_conn_t::copy_start(std::string const &sql) const
140140
{
141141
assert(m_conn);
142142

143143
log_sql("(C{}) {}", m_connection_id, sql);
144-
pg_result_t const res{PQexec(m_conn.get(), sql.data())};
144+
pg_result_t const res{PQexec(m_conn.get(), sql.c_str())};
145145
if (res.status() != PGRES_COPY_IN) {
146146
throw fmt_error("Database error on COPY: {}", error_msg());
147147
}

src/pgsql.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class pg_conn_t
241241
*/
242242
void set_config(char const *setting, char const *value) const;
243243

244-
void copy_start(std::string_view sql) const;
244+
void copy_start(std::string const &sql) const;
245245
void copy_send(std::string_view data, std::string_view context) const;
246246
void copy_end(std::string_view context) const;
247247

0 commit comments

Comments
 (0)