#include "matador/sql/column.hpp" #include "matador/sql/table.hpp" #include #include namespace matador::sql { column operator ""_col(const char *name, size_t len) { const std::string str(name, len); const auto pos = str.find('.'); if (pos == std::string::npos) { return column{str}; } if (str.find('.', pos + 1) != std::string::npos) { throw std::invalid_argument("Invalid column name: multiple dots found"); } return column{table{str.substr(0, pos)}, str.substr(pos + 1)}; } column::column(const char *name, const std::string& as) : column(std::string(name), as) {} column::column(std::string name, std::string as) : table_(std::make_shared()) , name(std::move(name)) , alias(std::move(as)) {} column::column(const sql_function_t func, std::string name) : table_(std::make_shared()) , name(std::move(name)) , function_(func) {} column::column(const table& tab, std::string name, std::string as) : table_(std::make_shared(tab)) , name(std::move(name)) , alias(std::move(as)) { table_->columns.push_back(*this); } column::column(const std::shared_ptr
& t, std::string name, std::string as) : table_(t) , name(std::move(name)) , alias(std::move(as)) { } bool column::equals(const column &x) const { return *table_ == *x.table_ && name == x.name && alias == x.alias && function_ == x.function_; } column &column::as(std::string a) { alias = std::move(a); return *this; } bool column::is_function() const { return function_ != sql_function_t::NONE; } bool column::has_alias() const { return !alias.empty(); } }