-
Notifications
You must be signed in to change notification settings - Fork 16
/
SqlDeleteQueryBuilder.cpp
73 lines (60 loc) · 2.53 KB
/
SqlDeleteQueryBuilder.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
/*
Copyright (C) 2011-2013 Klarälvdalens Datakonsult AB,
a KDAB Group company, [email protected],
author Andras Mantia <[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 "SqlDeleteQueryBuilder.h"
#include "SqlExceptions.h"
#include "Sql.h"
#include <QUuid>
SqlDeleteQueryBuilder::SqlDeleteQueryBuilder(const QSqlDatabase& db) :
SqlConditionalQueryBuilderBase( db ),
m_includeSubTables( true )
{
}
void SqlDeleteQueryBuilder::setIncludeSubTables(bool includeSubTables)
{
m_includeSubTables = includeSubTables;
}
SqlQuery& SqlDeleteQueryBuilder::query()
{
if ( !m_assembled ) {
QStringList cols;
m_queryString = QLatin1String( "DELETE FROM " );
if ( !m_includeSubTables ) {
m_queryString += QLatin1String( "ONLY " );
}
m_queryString += m_table;
m_bindValues.clear();
if ( m_whereCondition.hasSubConditions() ) {
m_queryString += QLatin1String( " WHERE " );
m_queryString += conditionToString( m_whereCondition );
}
m_queryString = m_queryString.trimmed();
m_assembled = true;
#ifndef QUERYBUILDER_UNITTEST
m_query = prepareQuery( m_queryString );
for ( int i = 0; i < m_bindValues.size(); ++i ) {
const QVariant value = m_bindValues.at( i );
// FIXME: similar code in the other query builders, we probably want that in the base class
if ( qstrcmp( value.typeName(), QMetaType::typeName( qMetaTypeId<QUuid>() ) ) == 0 )
m_query.bindValue( QLatin1Char( ':' ) + QString::number( i ), value.value<QUuid>().toString() ); // Qt SQL drivers don't handle QUuid
else
m_query.bindValue( QLatin1Char( ':' ) + QString::number( i ), value );
}
#endif
}
return m_query;
}