-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsqlrelation.cpp
38 lines (32 loc) · 996 Bytes
/
fsqlrelation.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
#include "fsqlrelation.h"
#include "sqlutil.h"
#include <QSqlTableModel>
#include <QDebug>
void FSqlRelation::populateModel()
{
if (!isValid())
return;
Q_ASSERT(m_parent != NULL);
if (!m_model)
{
QString query = Sql::concat(
Sql::concat(
Sql::concat(
Sql::select(Sql::comma(m_indexColumn, m_displayColumn)),
Sql::from(m_tableName)),
Sql::where(Sql::getGlobalFilter(m_tableName, m_parent->database()))),
Sql::orderBy(m_displayColumn));
qDebug() << query;
m_model = new QSqlQueryModel(m_parent);
m_model->setQuery(query, m_parent->database());
}
}
void FSqlRelation::clear()
{
m_model->deleteLater();
m_model = NULL;
}
bool FSqlRelation::isValid()
{
return (m_parent != NULL && !(m_tableName.isNull() || m_indexColumn.isNull() || m_displayColumn.isNull()));
}