sql select join progress
This commit is contained in:
+14
-4
@@ -17,12 +17,11 @@ const std::string &dialect::data_type_at(data_type_t type) const
|
||||
|
||||
std::string dialect::prepare_identifier(const column &col) const
|
||||
{
|
||||
std::string result(col.name());
|
||||
std::string result;
|
||||
if (!col.is_function()) {
|
||||
escape_quotes_in_identifier(result);
|
||||
quote_identifier(result);
|
||||
result = prepare_identifier_string(col.name());
|
||||
} else {
|
||||
result = sql_func_map_.at(col.function()) + "(" + result + ")";
|
||||
result = sql_func_map_.at(col.function()) + "(" + col.name() + ")";
|
||||
}
|
||||
if (!col.alias().empty()) {
|
||||
result += " AS " + col.alias();
|
||||
@@ -30,6 +29,17 @@ std::string dialect::prepare_identifier(const column &col) const
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string dialect::prepare_identifier_string(const std::string &col) const
|
||||
{
|
||||
auto parts = utils::split(col, '.');
|
||||
|
||||
for (auto &part : parts) {
|
||||
escape_quotes_in_identifier(part);
|
||||
quote_identifier(part);
|
||||
}
|
||||
return utils::join(parts, ".");
|
||||
}
|
||||
|
||||
std::string dialect::prepare_literal(const std::string &str) const
|
||||
{
|
||||
std::string result(str);
|
||||
|
||||
@@ -76,9 +76,34 @@ query_order_by_intermediate query_where_intermediate::order_by(const std::string
|
||||
return {connection_, builder_.order_by(name)};
|
||||
}
|
||||
|
||||
query_join_intermediate query_on_intermediate::join(const std::string &join_table_name, const std::string &as)
|
||||
{
|
||||
return {connection_, builder_.join(join_table_name, join_type_t::INNER, as)};
|
||||
}
|
||||
|
||||
query_where_intermediate query_on_intermediate::where(const basic_condition &cond)
|
||||
{
|
||||
return {connection_, builder_.where(cond)};
|
||||
}
|
||||
|
||||
query_group_by_intermediate query_on_intermediate::group_by(const std::string &name)
|
||||
{
|
||||
return {connection_, builder_.group_by(name)};
|
||||
}
|
||||
|
||||
query_order_by_intermediate query_on_intermediate::order_by(const std::string &name)
|
||||
{
|
||||
return {connection_, builder_.order_by(name)};
|
||||
}
|
||||
|
||||
query_on_intermediate query_join_intermediate::on(const std::string &column, const std::string &join_column)
|
||||
{
|
||||
return {connection_, builder_.on(column, join_column)};
|
||||
}
|
||||
|
||||
query_join_intermediate query_from_intermediate::join(const std::string &join_table_name, const std::string &as)
|
||||
{
|
||||
return query_join_intermediate();
|
||||
return {connection_, builder_.join(join_table_name, join_type_t::INNER, as)};
|
||||
}
|
||||
|
||||
query_where_intermediate query_from_intermediate::where(const basic_condition &cond)
|
||||
|
||||
@@ -39,8 +39,8 @@ logger::logger(const std::string &path, std::string source)
|
||||
filename = (last + 1);
|
||||
}
|
||||
// extract base path and extension
|
||||
std::vector<std::string> result;
|
||||
if (utils::split(filename, '.', result) != 2) {
|
||||
const auto result = utils::split(filename, '.');
|
||||
if (result.size() != 2) {
|
||||
throw std::logic_error("split path must consists of two elements");
|
||||
}
|
||||
// get current path
|
||||
|
||||
@@ -36,14 +36,15 @@ std::string to_string(const blob &data)
|
||||
return str;
|
||||
}
|
||||
|
||||
size_t split(const std::string &str, char delim, std::vector<std::string> &values)
|
||||
std::vector<std::string> split(const std::string &str, char delim)
|
||||
{
|
||||
std::stringstream ss(str);
|
||||
std::string item;
|
||||
std::vector<std::string> result;
|
||||
while (std::getline(ss, item, delim)) {
|
||||
values.push_back(item);
|
||||
result.push_back(item);
|
||||
}
|
||||
return values.size();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user