-
Notifications
You must be signed in to change notification settings - Fork 1
/
mysqlquery.cpp
48 lines (36 loc) · 1.06 KB
/
mysqlquery.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "mysqlquery.h"
using namespace SqlUtil4;
MySqlQuery::MySqlQuery():SqlQuery( )
{
}
QString MySqlQuery::toString()
{
QString query;
if (!selectFields.isEmpty()) {
query += QStringLiteral("SELECT %1 FROM %2").arg(selectFields, fromTable);
} else if (!deleteFromTable.isEmpty()) {
query+= QStringLiteral("DELETE FROM %1").arg(deleteFromTable);
}
for(int i=0;i<joinTables.size();i++) {
query+=joinTables.at(i);
}
if (!conditions.empty()) {
query+= QStringLiteral(" WHERE ");
for(const QString &cond: conditions) {
query += cond;
}
}
if(!orderByExpression.isEmpty()) {
query += QStringLiteral(" ORDER BY %1").arg(orderByExpression);
}
if (group.size()>0) {
query += QStringLiteral(" GROUP BY %1").arg(group.at(0));
for(int i=1;i<group.size();i++) {
query += QStringLiteral(", %1").arg(group.at(i));
}
}
if (limitResults>0) {
query += QStringLiteral("LIMIT %1").arg( limitResults);
}
return query;
}