#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 sql::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; } const std::string& column::column_name() const { return name; } std::string column::full_name() const { if (table_ && !table_->name().empty()) { return table_->name() + "." + name; } return name; } const std::string& column::alias_name() const { return alias_; } bool column::is_function() const { return function_ != sql_function_t::None; } sql_function_t column::function() const { return function_; } bool column::has_alias() const { return !alias_.empty(); } std::string column::alias() const { return alias_; } std::shared_ptr column::table() const { return table_; } void column::table( const std::shared_ptr& t ) { table_ = t; } }