some sql classes refactorings like column and table structs to classes
This commit is contained in:
+217
-12
@@ -16,37 +16,47 @@ const std::string &dialect::data_type_at(const utils::basic_type type) const
|
||||
return data_types_.at(type);
|
||||
}
|
||||
|
||||
std::string dialect::prepare_identifier(const column &col) const
|
||||
std::string dialect::prepare_identifier(const sql::column &col) const
|
||||
{
|
||||
std::string result;
|
||||
if (!col.is_function()) {
|
||||
if (!col.table_->name.empty()) {
|
||||
result = prepare_identifier_string(col.table_->has_alias() ? col.table_->alias : col.table_->name) + ".";
|
||||
if (!col.table()->name().empty()) {
|
||||
result = prepare_identifier_string(col.table()->has_alias() ? col.table()->alias() : col.table()->name()) + ".";
|
||||
}
|
||||
result += prepare_identifier_string(col.name);
|
||||
result += prepare_identifier_string(col.column_name());
|
||||
} else {
|
||||
result = sql_func_map_.at(col.function_) + "(" + col.name + ")";
|
||||
result = sql_func_map_.at(col.function()) + "(" + col.column_name() + ")";
|
||||
}
|
||||
if (!col.alias.empty()) {
|
||||
result += " AS " + col.alias;
|
||||
if (!col.alias().empty()) {
|
||||
result += " AS " + col.alias();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string dialect::prepare_condition(const column& col) const
|
||||
std::string dialect::table_name( const std::string& table, const std::string& schema_name ) const {
|
||||
if ( schema_name.empty() && default_schema_name_.empty()) {
|
||||
return prepare_identifier_string( table );
|
||||
}
|
||||
if ( schema_name.empty() ) {
|
||||
return prepare_identifier_string( default_schema_name_ ) + "." + prepare_identifier_string( table );
|
||||
}
|
||||
return prepare_identifier_string( schema_name ) + "." + prepare_identifier_string( table );
|
||||
}
|
||||
|
||||
std::string dialect::prepare_condition(const sql::column& col) const
|
||||
{
|
||||
std::string result;
|
||||
if (!col.is_function()) {
|
||||
// if (!col.alias.empty()) {
|
||||
// result = col.alias;
|
||||
// } else {
|
||||
if (!col.table_->name.empty()) {
|
||||
result = prepare_identifier_string(col.table_->has_alias() ? col.table_->alias : col.table_->name) + ".";
|
||||
if (!col.table()->name().empty()) {
|
||||
result = prepare_identifier_string(col.table()->has_alias() ? col.table()->alias() : col.table()->name()) + ".";
|
||||
}
|
||||
result += prepare_identifier_string(col.name);
|
||||
result += prepare_identifier_string(col.column_name());
|
||||
// }
|
||||
} else {
|
||||
result = sql_func_map_.at(col.function_) + "(" + col.name + ")";
|
||||
result = sql_func_map_.at(col.function()) + "(" + col.column_name() + ")";
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -143,4 +153,199 @@ std::string dialect::default_schema_name() const
|
||||
return default_schema_name_;
|
||||
}
|
||||
|
||||
const std::string& dialect::add_constraint() const {
|
||||
return token_at(dialect_token::AddConstraint);
|
||||
}
|
||||
|
||||
const std::string& dialect::alter() const {
|
||||
return token_at(dialect_token::Alter);
|
||||
}
|
||||
|
||||
const std::string& dialect::and_() const {
|
||||
return token_at(dialect_token::And);
|
||||
}
|
||||
|
||||
const std::string& dialect::as() const {
|
||||
return token_at(dialect_token::As);
|
||||
}
|
||||
|
||||
const std::string& dialect::asc() const {
|
||||
return token_at(dialect_token::Asc);
|
||||
}
|
||||
|
||||
const std::string& dialect::begin() const {
|
||||
return token_at(dialect_token::Begin);
|
||||
}
|
||||
|
||||
const std::string& dialect::asterisk() const {
|
||||
return token_at(dialect_token::Asterisk);
|
||||
}
|
||||
|
||||
const std::string& dialect::begin_binary_data() const {
|
||||
return token_at(dialect_token::BeginBinaryData);
|
||||
}
|
||||
|
||||
const std::string& dialect::begin_string_data() const {
|
||||
return token_at(dialect_token::BeginStringData);
|
||||
}
|
||||
|
||||
const std::string& dialect::between() const {
|
||||
return token_at(dialect_token::Between);
|
||||
}
|
||||
|
||||
const std::string& dialect::column() const {
|
||||
return token_at(dialect_token::Column);
|
||||
}
|
||||
|
||||
const std::string& dialect::columns() const {
|
||||
return token_at(dialect_token::Columns);
|
||||
}
|
||||
|
||||
const std::string& dialect::commit() const {
|
||||
return token_at(dialect_token::Commit);
|
||||
}
|
||||
|
||||
const std::string& dialect::create() const {
|
||||
return token_at(dialect_token::Create);
|
||||
}
|
||||
|
||||
const std::string& dialect::drop() const {
|
||||
return token_at(dialect_token::Drop);
|
||||
}
|
||||
|
||||
const std::string& dialect::end_binary_data() const {
|
||||
return token_at(dialect_token::EndBinaryData);
|
||||
}
|
||||
|
||||
const std::string& dialect::end_string_data() const {
|
||||
return token_at(dialect_token::EndStringData);
|
||||
}
|
||||
|
||||
const std::string& dialect::from() const {
|
||||
return token_at(dialect_token::From);
|
||||
}
|
||||
|
||||
const std::string& dialect::in() const {
|
||||
return token_at(dialect_token::In);
|
||||
}
|
||||
|
||||
const std::string& dialect::desc() const {
|
||||
return token_at(dialect_token::Desc);
|
||||
}
|
||||
|
||||
const std::string& dialect::distinct() const {
|
||||
return token_at(dialect_token::Distinct);
|
||||
}
|
||||
|
||||
const std::string& dialect::drop_constraint() const {
|
||||
return token_at(dialect_token::DropConstraint);
|
||||
}
|
||||
|
||||
const std::string& dialect::end_quote() const {
|
||||
return token_at(dialect_token::EndQuote);
|
||||
}
|
||||
|
||||
const std::string& dialect::foreign_key() const {
|
||||
return token_at(dialect_token::ForeignKey);
|
||||
}
|
||||
|
||||
const std::string& dialect::group_by() const {
|
||||
return token_at(dialect_token::GroupBy);
|
||||
}
|
||||
|
||||
const std::string& dialect::insert() const {
|
||||
return token_at(dialect_token::Insert);
|
||||
}
|
||||
|
||||
const std::string& dialect::into() const {
|
||||
return token_at(dialect_token::Into);
|
||||
}
|
||||
|
||||
const std::string& dialect::join() const {
|
||||
return token_at(dialect_token::Join);
|
||||
}
|
||||
|
||||
const std::string& dialect::like() const {
|
||||
return token_at(dialect_token::Like);
|
||||
}
|
||||
|
||||
const std::string& dialect::limit() const {
|
||||
return token_at(dialect_token::Limit);
|
||||
}
|
||||
|
||||
const std::string& dialect::not_() const {
|
||||
return token_at(dialect_token::Not);
|
||||
}
|
||||
|
||||
const std::string& dialect::not_null() const {
|
||||
return token_at(dialect_token::NotNull);
|
||||
}
|
||||
|
||||
const std::string& dialect::offset() const {
|
||||
return token_at(dialect_token::Offset);
|
||||
}
|
||||
|
||||
const std::string& dialect::on() const {
|
||||
return token_at(dialect_token::On);
|
||||
}
|
||||
|
||||
const std::string& dialect::or_() const {
|
||||
return token_at(dialect_token::Or);
|
||||
}
|
||||
|
||||
const std::string& dialect::order_by() const {
|
||||
return token_at(dialect_token::OrderBy);
|
||||
}
|
||||
|
||||
const std::string& dialect::primary_key() const {
|
||||
return token_at(dialect_token::PrimaryKey);
|
||||
}
|
||||
|
||||
const std::string& dialect::references() const {
|
||||
return token_at(dialect_token::References);
|
||||
}
|
||||
|
||||
const std::string& dialect::remove() const {
|
||||
return token_at(dialect_token::Remove);
|
||||
}
|
||||
|
||||
const std::string& dialect::rollback() const {
|
||||
return token_at(dialect_token::Rollback);
|
||||
}
|
||||
|
||||
const std::string& dialect::schema() const {
|
||||
return token_at(dialect_token::Schema);
|
||||
}
|
||||
|
||||
const std::string& dialect::select() const {
|
||||
return token_at(dialect_token::Select);
|
||||
}
|
||||
|
||||
const std::string& dialect::set() const {
|
||||
return token_at(dialect_token::Set);
|
||||
}
|
||||
|
||||
const std::string& dialect::start_quote() const {
|
||||
return token_at(dialect_token::StartQuote);
|
||||
}
|
||||
|
||||
const std::string& dialect::string_quote() const {
|
||||
return token_at(dialect_token::StringQuote);
|
||||
}
|
||||
|
||||
const std::string& dialect::table() const {
|
||||
return token_at(dialect_token::Table);
|
||||
}
|
||||
|
||||
const std::string& dialect::update() const {
|
||||
return token_at(dialect_token::Update);
|
||||
}
|
||||
|
||||
const std::string& dialect::values() const {
|
||||
return token_at(dialect_token::Values);
|
||||
}
|
||||
|
||||
const std::string& dialect::where() const {
|
||||
return token_at(dialect_token::Where);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user