Skip to content

Commit 1fcef0c

Browse files
committed
Remove somewhat magical way of iterating over table columns
Use accessor function flex_table_t::columns() to get to a vector of columns instead of having begin()/end() functions on flex_table_t.
1 parent f92d491 commit 1fcef0c

File tree

5 files changed

+8
-13
lines changed

5 files changed

+8
-13
lines changed

src/debug-output.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void write_table_list_to_debug_log(std::vector<flex_table_t> const &tables)
4848
for (auto const &table : tables) {
4949
log_debug("- Table {}", qualified_name(table.schema(), table.name()));
5050
log_debug(" - columns:");
51-
for (auto const &column : table) {
51+
for (auto const &column : table.columns()) {
5252
log_debug(R"( - "{}" {} ({}) not_null={} create_only={})",
5353
column.name(), column.type_name(), column.sql_type_name(),
5454
column.not_null(), column.create_only());

src/flex-lua-index.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static void check_and_add_column(flex_table_t const &table,
2020
std::vector<std::string> *columns,
2121
char const *column_name)
2222
{
23-
auto const *column = util::find_by_name(table, column_name);
23+
auto const *column = util::find_by_name(table.columns(), column_name);
2424
if (!column) {
2525
throw fmt_error("Unknown column '{}' in table '{}'.", column_name,
2626
table.name());

src/flex-table.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ static void enable_check_trigger(pg_conn_t const &db_connection,
260260
{
261261
std::string checks;
262262

263-
for (auto const &column : table) {
263+
for (auto const &column : table.columns()) {
264264
if (column.is_geometry_column() && column.needs_isvalid()) {
265265
checks.append(fmt::format(
266266
R"((NEW."{0}" IS NULL OR ST_IsValid(NEW."{0}")) AND )",

src/flex-table.hpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,9 @@ class flex_table_t
111111

112112
std::size_t num_columns() const noexcept { return m_columns.size(); }
113113

114-
std::vector<flex_table_column_t>::const_iterator begin() const noexcept
114+
std::vector<flex_table_column_t> const &columns() const noexcept
115115
{
116-
return m_columns.begin();
117-
}
118-
119-
std::vector<flex_table_column_t>::const_iterator end() const noexcept
120-
{
121-
return m_columns.end();
116+
return m_columns;
122117
}
123118

124119
flex_table_column_t *find_column_by_name(std::string const &name)

src/output-flex.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ int output_flex_t::table_insert()
643643
auto *copy_mgr = table_connection.copy_mgr();
644644

645645
try {
646-
for (auto const &column : table_connection.table()) {
646+
for (auto const &column : table_connection.table().columns()) {
647647
if (column.create_only()) {
648648
continue;
649649
}
@@ -681,7 +681,7 @@ int output_flex_t::table_columns()
681681
lua_createtable(lua_state(), (int)table.num_columns(), 0);
682682

683683
int n = 0;
684-
for (auto const &column : table) {
684+
for (auto const &column : table.columns()) {
685685
lua_pushinteger(lua_state(), ++n);
686686
lua_newtable(lua_state());
687687

@@ -1039,7 +1039,7 @@ void output_flex_t::delete_from_table(table_connection_t *table_connection,
10391039
auto const num_tuples = result.num_tuples();
10401040
if (num_tuples > 0) {
10411041
int col = 0;
1042-
for (auto const &column : table_connection->table()) {
1042+
for (auto const &column : table_connection->table().columns()) {
10431043
if (column.has_expire()) {
10441044
for (int i = 0; i < num_tuples; ++i) {
10451045
auto const geom = ewkb_to_geom(result.get(i, col));

0 commit comments

Comments
 (0)