-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathQueryModel.cpp
More file actions
30 lines (25 loc) · 766 Bytes
/
Copy pathQueryModel.cpp
File metadata and controls
30 lines (25 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "QueryModel.h"
QString QueryModel::toSql() const
{
if (isEmpty()) {
return QString();
}
QString sql = "SELECT *\nFROM " + m_fromTable;
for (const auto& join : m_joins) {
sql += "\nJOIN " + join.table
+ "\n ON " + join.onRelation.fromTable + "." + join.onRelation.fromColumn
+ " = " + join.onRelation.toTable + "." + join.onRelation.toColumn;
}
if (!m_conditions.isEmpty()) {
sql += "\nWHERE ";
for (int i = 0; i < m_conditions.size(); ++i) {
if (i > 0) {
sql += "\n AND ";
}
const auto& c = m_conditions[i];
sql += c.column + " " + c.op + " " + c.value;
}
}
sql += ";";
return sql;
}