Skip to content

Commit 440579e

Browse files
committed
Remove check for empty command from pg_conn_t::exec()
It is almost never needed there and is better done outside that function in the few places where it is needed.
1 parent c8f7de5 commit 440579e

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

src/middle-pgsql.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,9 @@ void middle_pgsql_t::start()
670670
auto const qual_name = qualified_name(table.schema(), table.name());
671671
m_db_connection.exec(
672672
"DROP TABLE IF EXISTS {} CASCADE"_format(qual_name));
673-
m_db_connection.exec(table.m_create_table);
673+
if (!table.m_create_table.empty()) {
674+
m_db_connection.exec(table.m_create_table);
675+
}
674676
}
675677
}
676678
}
@@ -873,7 +875,9 @@ middle_pgsql_t::get_query_instance()
873875

874876
// We use a connection per table to enable the use of COPY
875877
for (auto &table : m_tables) {
876-
mid->exec_sql(table.m_prepare_query);
878+
if (!table.m_prepare_query.empty()) {
879+
mid->exec_sql(table.m_prepare_query);
880+
}
877881
}
878882

879883
return std::shared_ptr<middle_query_t>(mid.release());

src/pgsql.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,11 @@ void pg_conn_t::set_config(char const *setting, char const *value) const
6666
query(PGRES_TUPLES_OK, sql);
6767
}
6868

69-
void pg_conn_t::exec(char const *sql) const
70-
{
71-
if (sql && sql[0] != '\0') {
72-
query(PGRES_COMMAND_OK, sql);
73-
}
74-
}
69+
void pg_conn_t::exec(char const *sql) const { query(PGRES_COMMAND_OK, sql); }
7570

7671
void pg_conn_t::exec(std::string const &sql) const
7772
{
78-
if (!sql.empty()) {
79-
query(PGRES_COMMAND_OK, sql.c_str());
80-
}
73+
query(PGRES_COMMAND_OK, sql.c_str());
8174
}
8275

8376
void pg_conn_t::copy_start(char const *sql) const

0 commit comments

Comments
 (0)