diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 8a6911bc..bb0dd740 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -70,6 +70,13 @@ namespace sqlpp column_t& operator=(column_t&&) = default; ~column_t() = default; + template + auto table() const -> _table + { + static_assert(is_table_t::value, "cannot call get_table for columns of a sub-selects or cte"); + return _table{}; + } + template expression_alias_t as(const alias_provider&) const { diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index b804aee1..86ad502f 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -36,11 +36,23 @@ MockDb db = {}; MockDb::_serializer_context_t printer; +template +int64_t getColumn(const Column& column) +{ + auto result = db(select(column.as(sqlpp::a)).from(column.table()).where(true)); + if (not result.empty()) + return result.front().a; + else + return 0; +} + int main() { test::TabFoo f; test::TabBar t; + getColumn(t.alpha); + for (const auto& row : db(select(all_of(t)).from(t).where(true))) { int64_t a = row.alpha;