Refactored namespaces

This commit is contained in:
emeric
2024-03-12 08:32:08 +01:00
parent 487960b413
commit 4b7c4295ec
501 changed files with 12605 additions and 12631 deletions
+127 -138
View File
@@ -23,177 +23,166 @@
#include <cassert>
#include <sstream>
WhereClause&
WhereClause::And(const WhereClause& otherClause)
namespace lms::db
{
if (!otherClause._clause.empty()) {
if (!_clause.empty())
_clause += " AND ";
_clause += "(" + otherClause._clause + ")";
WhereClause& WhereClause::And(const WhereClause& otherClause)
{
if (!otherClause._clause.empty()) {
if (!_clause.empty())
_clause += " AND ";
_clause += "(" + otherClause._clause + ")";
// Add associated bind args
for (const std::string& otherBindArg : otherClause._bindArgs)
{
_bindArgs.push_back(otherBindArg);
}
}
return *this;
}
// Add associated bind args
for (const std::string& otherBindArg : otherClause._bindArgs)
{
_bindArgs.push_back(otherBindArg);
}
}
return *this;
}
WhereClause&
WhereClause::Or(const WhereClause& otherClause)
{
if (!otherClause._clause.empty()) {
if (!_clause.empty())
_clause += " OR ";
_clause += "(" + otherClause._clause + ")";
WhereClause& WhereClause::Or(const WhereClause& otherClause)
{
if (!otherClause._clause.empty()) {
if (!_clause.empty())
_clause += " OR ";
_clause += "(" + otherClause._clause + ")";
// Add associated bind args
for (const std::string& otherBindArg : otherClause._bindArgs)
{
_bindArgs.push_back(otherBindArg);
}
}
return *this;
}
// Add associated bind args
for (const std::string& otherBindArg : otherClause._bindArgs)
{
_bindArgs.push_back(otherBindArg);
}
}
return *this;
}
std::string
WhereClause::get() const
{
if (!_clause.empty())
return "WHERE " + _clause;
else
return "";
}
std::string WhereClause::get() const
{
if (!_clause.empty())
return "WHERE " + _clause;
else
return "";
}
WhereClause&
WhereClause::bind(std::string_view bindArg)
{
assert(_bindArgs.size() < static_cast<std::size_t>(std::count(_clause.begin(), _clause.end(), '?')));
WhereClause& WhereClause::bind(std::string_view bindArg)
{
assert(_bindArgs.size() < static_cast<std::size_t>(std::count(_clause.begin(), _clause.end(), '?')));
_bindArgs.push_back(std::string{ bindArg });
_bindArgs.push_back(std::string{ bindArg });
return *this;
}
return *this;
}
InnerJoinClause::InnerJoinClause(const std::string& clause)
:_clause(clause)
{
}
InnerJoinClause::InnerJoinClause(const std::string& clause)
:_clause(clause)
{
}
InnerJoinClause&
InnerJoinClause::And(const InnerJoinClause& clause)
{
if (!_clause.empty())
_clause += " ";
InnerJoinClause& InnerJoinClause::And(const InnerJoinClause& clause)
{
if (!_clause.empty())
_clause += " ";
_clause += "INNER JOIN " + clause._clause;
_clause += "INNER JOIN " + clause._clause;
return *this;
}
return *this;
}
SelectStatement::SelectStatement(const std::string& statement)
{
And(statement);
}
SelectStatement::SelectStatement(const std::string& statement)
{
And(statement);
}
SelectStatement&
SelectStatement::And(const std::string& statement)
{
_statement.push_back(statement);
SelectStatement& SelectStatement::And(const std::string& statement)
{
_statement.push_back(statement);
std::sort(_statement.begin(), _statement.end());
_statement.erase(std::unique(_statement.begin(), _statement.end()), _statement.end());
std::sort(_statement.begin(), _statement.end());
_statement.erase(std::unique(_statement.begin(), _statement.end()), _statement.end());
return *this;
}
return *this;
}
std::string
SelectStatement::get() const
{
std::string res = "SELECT ";
std::string SelectStatement::get() const
{
std::string res = "SELECT ";
for (auto it = _statement.begin(); it != _statement.end(); ++it)
{
if (it != _statement.begin())
res += ",";
res += *it;
}
for (auto it = _statement.begin(); it != _statement.end(); ++it)
{
if (it != _statement.begin())
res += ",";
res += *it;
}
return res;
}
return res;
}
GroupByStatement& GroupByStatement::And(const GroupByStatement& statement)
{
if (_statement.empty() && !statement._statement.empty())
_statement = "GROUP BY ";
else if (!_statement.empty() && !statement._statement.empty())
_statement += ",";
_statement += statement._statement;
return *this;
}
GroupByStatement&
GroupByStatement::And(const GroupByStatement& statement)
{
if( _statement.empty() && !statement._statement.empty())
_statement = "GROUP BY ";
else if (!_statement.empty() && !statement._statement.empty())
_statement += ",";
FromClause::FromClause(const std::string& clause)
{
_clause.push_back(clause);
}
_statement += statement._statement;
return *this;
}
FromClause& FromClause::And(const FromClause& clause)
{
for (const std::string& fromClause : clause._clause)
{
_clause.push_back(fromClause);
}
FromClause::FromClause(const std::string& clause)
{
_clause.push_back(clause);
}
std::sort(_clause.begin(), _clause.end());
_clause.erase(std::unique(_clause.begin(), _clause.end()), _clause.end());
FromClause&
FromClause::And(const FromClause& clause)
{
for (const std::string& fromClause : clause._clause)
{
_clause.push_back(fromClause);
}
return *this;
}
std::sort(_clause.begin(), _clause.end());
_clause.erase(std::unique(_clause.begin(), _clause.end()), _clause.end());
std::string FromClause::get() const
{
std::ostringstream oss;
return *this;
}
if (!_clause.empty())
{
oss << "FROM ";
for (auto it = _clause.begin(); it != _clause.end(); ++it) {
if (it != _clause.begin())
oss << ",";
std::string
FromClause::get() const
{
std::ostringstream oss;
oss << *it;
}
}
if (!_clause.empty())
{
oss << "FROM ";
for (auto it = _clause.begin(); it != _clause.end(); ++it) {
if (it != _clause.begin())
oss << ",";
return oss.str();
}
oss << *it;
}
}
std::string SqlQuery::get() const
{
std::ostringstream oss;
return oss.str();
}
oss << _selectStatement.get();
std::string
SqlQuery::get() const
{
std::ostringstream oss;
if (!_fromClause.get().empty())
oss << " " << _fromClause.get();
oss << _selectStatement.get();
if (!_innerJoinClause.get().empty())
oss << " " << _innerJoinClause.get();
if (!_fromClause.get().empty())
oss << " " << _fromClause.get();
if (!_whereClause.get().empty())
oss << " " << _whereClause.get();
if (!_innerJoinClause.get().empty())
oss << " " << _innerJoinClause.get();
if (!_whereClause.get().empty())
oss << " " << _whereClause.get();
if (!_groupByStatement.get().empty())
oss << " " << _groupByStatement.get();
return oss.str();
}
if (!_groupByStatement.get().empty())
oss << " " << _groupByStatement.get();
return oss.str();
}
}