98 lines
2.0 KiB
C++
98 lines
2.0 KiB
C++
#include "matador/query/column.hpp"
|
|
|
|
#include "matador/query/table.hpp"
|
|
|
|
#include <stdexcept>
|
|
#include <utility>
|
|
|
|
namespace matador::query {
|
|
|
|
column operator ""_col(const char *name, const 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{new 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)
|
|
: name_(std::move(name))
|
|
, alias_(std::move(as)) {}
|
|
|
|
column::column(const sql::sql_function_t func, std::string name)
|
|
: name_(std::move(name))
|
|
, function_(func) {}
|
|
|
|
column::column(const class table* tab, std::string name, std::string as)
|
|
: table_(tab)
|
|
, 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::name() const {
|
|
return name_;
|
|
}
|
|
|
|
const std::string& column::alias() const {
|
|
return alias_;
|
|
}
|
|
|
|
utils::basic_type column::type() const {
|
|
return type_;
|
|
}
|
|
|
|
utils::field_attributes column::attributes() const {
|
|
return attributes_;
|
|
}
|
|
|
|
bool column::is_function() const {
|
|
return function_ != sql::sql_function_t::None;
|
|
}
|
|
|
|
bool column::is_nullable() const {
|
|
return !utils::is_constraint_set(attributes_.options(), utils::constraints::NotNull);
|
|
}
|
|
|
|
sql::sql_function_t column::function() const {
|
|
return function_;
|
|
}
|
|
|
|
bool column::has_alias() const {
|
|
return !alias_.empty();
|
|
}
|
|
|
|
const class table* column::table() const {
|
|
return table_;
|
|
}
|
|
|
|
void column::table(const query::table* tab) {
|
|
table_ = tab;
|
|
}
|
|
|
|
column::operator const std::string&() const {
|
|
return name_;
|
|
}
|
|
|
|
} |