-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathSqlCondition.cpp
108 lines (95 loc) · 3.11 KB
/
SqlCondition.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
Copyright (C) 2011-2013 Klarälvdalens Datakonsult AB,
a KDAB Group company, [email protected],
author Volker Krause <[email protected]>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "SqlCondition.h"
SqlCondition::SqlCondition(SqlCondition::LogicOperator op) :
m_compareOp( Equals ),
m_logicOp( op ),
m_isCaseSensitive( true )
{
}
void SqlCondition::addValueCondition(const QString& column, SqlCondition::CompareOperator op, const QVariant& value)
{
Q_ASSERT( !column.isEmpty() );
SqlCondition c;
c.m_compareOp = op;
if ( (!m_isCaseSensitive) && value.type() == QVariant::String )
{
c.m_comparedValue = value.toString().toLower();
c.m_column = QString::fromLatin1( "LOWER( %1 ) " ).arg( column );
}
else
{
c.m_comparedValue = value;
c.m_column = column;
}
m_subConditions.push_back( c );
}
void SqlCondition::addPlaceholderCondition(const QString& column, SqlCondition::CompareOperator op, const QString& placeholder)
{
Q_ASSERT( !column.isEmpty() );
Q_ASSERT( placeholder.size() >= 2 );
Q_ASSERT( placeholder.startsWith( QLatin1Char( ':' ) ) );
Q_ASSERT( !placeholder.at( 1 ).isDigit() );
SqlCondition c;
c.m_compareOp = op;
if ( m_isCaseSensitive )
{
c.m_placeholder = placeholder;
c.m_column = column;
}
else
{
c.m_placeholder = placeholder.toLower();
c.m_column = QString::fromLatin1( "LOWER( %1 ) " ).arg( column );
}
m_subConditions.push_back( c );
}
void SqlCondition::addColumnCondition(const QString& column, SqlCondition::CompareOperator op, const QString& column2)
{
Q_ASSERT( !column.isEmpty() );
Q_ASSERT( !column2.isEmpty() );
SqlCondition c;
c.m_column = column;
c.m_comparedColumn = column2;
c.m_compareOp = op;
m_subConditions.push_back( c );
}
void SqlCondition::addCondition(const SqlCondition& condition)
{
m_subConditions.push_back( condition );
}
void SqlCondition::setLogicOperator(SqlCondition::LogicOperator op)
{
m_logicOp = op;
}
QVector< SqlCondition > SqlCondition::subConditions() const
{
return m_subConditions;
}
bool SqlCondition::hasSubConditions() const
{
return !m_subConditions.isEmpty();
}
void SqlCondition::setCaseSensitive( const bool isCaseSensitive )
{
m_isCaseSensitive = isCaseSensitive;
}
bool SqlCondition::isCaseSensitive() const
{
return m_isCaseSensitive;
}