Skip to content

Commit 049546f

Browse files
committed
Refactor: Use util::string_joiner_t to assemble columns for SQL
1 parent 71a47d0 commit 049546f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/flex-table-column.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,5 @@ std::string flex_table_column_t::sql_modifiers() const
181181

182182
std::string flex_table_column_t::sql_create() const
183183
{
184-
return R"("{}" {} {},)"_format(m_name, sql_type_name(), sql_modifiers());
184+
return R"("{}" {} {})"_format(m_name, sql_type_name(), sql_modifiers());
185185
}

src/flex-table.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,17 @@ flex_table_t::build_sql_create_table(table_type ttype,
178178
std::string sql = "CREATE {} TABLE IF NOT EXISTS {} ("_format(
179179
ttype == table_type::interim ? "UNLOGGED" : "", table_name);
180180

181+
util::string_joiner_t joiner{','};
181182
for (auto const &column : m_columns) {
182183
// create_only columns are only created in permanent, not in the
183184
// interim tables
184185
if (ttype == table_type::permanent || !column.create_only()) {
185-
sql += column.sql_create();
186+
joiner.add(column.sql_create());
186187
}
187188
}
188189

189-
assert(sql.back() == ',');
190-
sql.back() = ')';
190+
sql += joiner();
191+
sql += ')';
191192

192193
if (ttype == table_type::interim) {
193194
sql += " WITH (autovacuum_enabled = off)";

0 commit comments

Comments
 (0)