43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
#include "matador/query/query_utils.hpp"
|
|
|
|
#include "matador/query/table.hpp"
|
|
|
|
namespace matador::query {
|
|
std::string prepare_identifier( const sql::dialect& d, const column& col ) {
|
|
return prepare_identifier(d, *col.table(), col);
|
|
}
|
|
|
|
std::string prepare_identifier( const sql::dialect& d, const table& tab, const column& col ) {
|
|
std::string result;
|
|
if (!col.is_function()) {
|
|
if (!tab.name().empty()) {
|
|
result = d.prepare_identifier_string(tab.has_alias() ? tab.alias() : tab.name()) + ".";
|
|
}
|
|
result += d.prepare_identifier_string(col.name());
|
|
} else {
|
|
result = d.sql_function_at(col.function()) + "(" + col.name() + ")";
|
|
}
|
|
if (!col.alias().empty()) {
|
|
result += " AS " + col.alias();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
std::string prepare_criteria(const sql::dialect& d, const column& col) {
|
|
std::string result;
|
|
if (!col.is_function()) {
|
|
// if (!col.alias.empty()) {
|
|
// result = col.alias;
|
|
// } else {
|
|
if (!col.table()->name().empty()) {
|
|
result = d.prepare_identifier_string(col.table()->has_alias() ? col.table()->alias() : col.table()->name()) + ".";
|
|
}
|
|
result += d.prepare_identifier_string(col.name());
|
|
// }
|
|
} else {
|
|
result = d.sql_function_at(col.function()) + "(" + col.name() + ")";
|
|
}
|
|
|
|
return result;
|
|
}
|
|
} |