kernel/qsqlindex.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtSql module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qsqlindex.h" -
43 -
44#include "qsqlfield.h" -
45#include "qstringlist.h" -
46 -
47QT_BEGIN_NAMESPACE -
48 -
49/*! -
50 \class QSqlIndex -
51 \brief The QSqlIndex class provides functions to manipulate and -
52 describe database indexes. -
53 -
54 \ingroup database -
55 \inmodule QtSql -
56 -
57 An \e index refers to a single table or view in a database. -
58 Information about the fields that comprise the index can be used -
59 to generate SQL statements. -
60*/ -
61 -
62/*! -
63 Constructs an empty index using the cursor name \a cursorname and -
64 index name \a name. -
65*/ -
66 -
67QSqlIndex::QSqlIndex(const QString& cursorname, const QString& name) -
68 : cursor(cursorname), nm(name) -
69{ -
70}
executed: }
Execution Count:695
695
71 -
72/*! -
73 Constructs a copy of \a other. -
74*/ -
75 -
76QSqlIndex::QSqlIndex(const QSqlIndex& other) -
77 : QSqlRecord(other), cursor(other.cursor), nm(other.nm), sorts(other.sorts) -
78{ -
79}
executed: }
Execution Count:1
1
80 -
81/*! -
82 Sets the index equal to \a other. -
83*/ -
84 -
85QSqlIndex& QSqlIndex::operator=(const QSqlIndex& other) -
86{ -
87 cursor = other.cursor;
executed (the execution status of this line is deduced): cursor = other.cursor;
-
88 nm = other.nm;
executed (the execution status of this line is deduced): nm = other.nm;
-
89 sorts = other.sorts;
executed (the execution status of this line is deduced): sorts = other.sorts;
-
90 QSqlRecord::operator=(other);
executed (the execution status of this line is deduced): QSqlRecord::operator=(other);
-
91 return *this;
executed: return *this;
Execution Count:187
187
92} -
93 -
94/*! -
95 Destroys the object and frees any allocated resources. -
96*/ -
97 -
98QSqlIndex::~QSqlIndex() -
99{ -
100 -
101} -
102 -
103/*! -
104 Sets the name of the index to \a name. -
105*/ -
106 -
107void QSqlIndex::setName(const QString& name) -
108{ -
109 nm = name;
never executed (the execution status of this line is deduced): nm = name;
-
110}
never executed: }
0
111 -
112/*! -
113 \fn QString QSqlIndex::name() const -
114 -
115 Returns the name of the index. -
116*/ -
117 -
118/*! -
119 Appends the field \a field to the list of indexed fields. The -
120 field is appended with an ascending sort order. -
121*/ -
122 -
123void QSqlIndex::append(const QSqlField& field) -
124{ -
125 append(field, false);
executed (the execution status of this line is deduced): append(field, false);
-
126}
executed: }
Execution Count:964
964
127 -
128/*! -
129 \overload -
130 -
131 Appends the field \a field to the list of indexed fields. The -
132 field is appended with an ascending sort order, unless \a desc is -
133 true. -
134*/ -
135 -
136void QSqlIndex::append(const QSqlField& field, bool desc) -
137{ -
138 sorts.append(desc);
executed (the execution status of this line is deduced): sorts.append(desc);
-
139 QSqlRecord::append(field);
executed (the execution status of this line is deduced): QSqlRecord::append(field);
-
140}
executed: }
Execution Count:964
964
141 -
142 -
143/*! -
144 Returns true if field \a i in the index is sorted in descending -
145 order; otherwise returns false. -
146*/ -
147 -
148bool QSqlIndex::isDescending(int i) const -
149{ -
150 if (i >= 0 && i < sorts.size())
never evaluated: i >= 0
never evaluated: i < sorts.size()
0
151 return sorts[i];
never executed: return sorts[i];
0
152 return false;
never executed: return false;
0
153} -
154 -
155/*! -
156 If \a desc is true, field \a i is sorted in descending order. -
157 Otherwise, field \a i is sorted in ascending order (the default). -
158 If the field does not exist, nothing happens. -
159*/ -
160 -
161void QSqlIndex::setDescending(int i, bool desc) -
162{ -
163 if (i >= 0 && i < sorts.size())
never evaluated: i >= 0
never evaluated: i < sorts.size()
0
164 sorts[i] = desc;
never executed: sorts[i] = desc;
0
165}
never executed: }
0
166 -
167/*! \internal -
168 -
169 Creates a string representing the field number \a i using prefix \a -
170 prefix. If \a verbose is true, ASC or DESC is included in the field -
171 description if the field is sorted in ASCending or DESCending order. -
172*/ -
173 -
174QString QSqlIndex::createField(int i, const QString& prefix, bool verbose) const -
175{ -
176 QString f;
never executed (the execution status of this line is deduced): QString f;
-
177 if (!prefix.isEmpty())
never evaluated: !prefix.isEmpty()
0
178 f += prefix + QLatin1Char('.');
never executed: f += prefix + QLatin1Char('.');
0
179 f += field(i).name();
never executed (the execution status of this line is deduced): f += field(i).name();
-
180 if (verbose)
never evaluated: verbose
0
181 f += QLatin1Char(' ') + QString((isDescending(i)
never executed: f += QLatin1Char(' ') + QString((isDescending(i) ? QLatin1String("DESC") : QLatin1String("ASC")));
0
182 ? QLatin1String("DESC") : QLatin1String("ASC")));
never executed: f += QLatin1Char(' ') + QString((isDescending(i) ? QLatin1String("DESC") : QLatin1String("ASC")));
0
183 return f;
never executed: return f;
0
184} -
185 -
186/*! -
187 \fn QString QSqlIndex::cursorName() const -
188 -
189 Returns the name of the cursor which the index is associated with. -
190*/ -
191 -
192 -
193/*! -
194 Sets the name of the cursor that the index is associated with to -
195 \a cursorName. -
196*/ -
197void QSqlIndex::setCursorName(const QString& cursorName) -
198{ -
199 cursor = cursorName;
never executed (the execution status of this line is deduced): cursor = cursorName;
-
200}
never executed: }
0
201 -
202QT_END_NAMESPACE -
203 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial