qsqlindex.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/sql/kernel/qsqlindex.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtSql module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qsqlindex.h"-
35-
36#include "qsqlfield.h"-
37#include "qstringlist.h"-
38-
39QT_BEGIN_NAMESPACE-
40-
41// ### Qt 6: remove the static assertion, the 'sorts' field was changed from QList to QVector in Qt 5.6-
42Q_STATIC_ASSERT((sizeof(QList<bool>) == sizeof(QVector<bool>)));-
43-
44/*!-
45 \class QSqlIndex-
46 \brief The QSqlIndex class provides functions to manipulate and-
47 describe database indexes.-
48-
49 \ingroup database-
50 \inmodule QtSql-
51-
52 An \e index refers to a single table or view in a database.-
53 Information about the fields that comprise the index can be used-
54 to generate SQL statements.-
55*/-
56-
57/*!-
58 Constructs an empty index using the cursor name \a cursorname and-
59 index name \a name.-
60*/-
61-
62QSqlIndex::QSqlIndex(const QString& cursorname, const QString& name)-
63 : cursor(cursorname), nm(name)-
64{-
65}
executed 695 times by 6 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
695
66-
67/*!-
68 Constructs a copy of \a other.-
69*/-
70-
71QSqlIndex::QSqlIndex(const QSqlIndex& other)-
72 : QSqlRecord(other), cursor(other.cursor), nm(other.nm), sorts(other.sorts)-
73{-
74}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QSqlTableModel
1
75-
76/*!-
77 Sets the index equal to \a other.-
78*/-
79-
80QSqlIndex& QSqlIndex::operator=(const QSqlIndex& other)-
81{-
82 cursor = other.cursor;-
83 nm = other.nm;-
84 sorts = other.sorts;-
85 QSqlRecord::operator=(other);-
86 return *this;
executed 187 times by 4 tests: return *this;
Executed by:
  • tst_QItemModel
  • tst_QSqlDriver
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
187
87}-
88-
89/*!-
90 Destroys the object and frees any allocated resources.-
91*/-
92-
93QSqlIndex::~QSqlIndex()-
94{-
95-
96}-
97-
98/*!-
99 Sets the name of the index to \a name.-
100*/-
101-
102void QSqlIndex::setName(const QString& name)-
103{-
104 nm = name;-
105}
never executed: end of block
0
106-
107/*!-
108 \fn QString QSqlIndex::name() const-
109-
110 Returns the name of the index.-
111*/-
112-
113/*!-
114 Appends the field \a field to the list of indexed fields. The-
115 field is appended with an ascending sort order.-
116*/-
117-
118void QSqlIndex::append(const QSqlField& field)-
119{-
120 append(field, false);-
121}
executed 967 times by 6 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
967
122-
123/*!-
124 \overload-
125-
126 Appends the field \a field to the list of indexed fields. The-
127 field is appended with an ascending sort order, unless \a desc is-
128 true.-
129*/-
130-
131void QSqlIndex::append(const QSqlField& field, bool desc)-
132{-
133 sorts.append(desc);-
134 QSqlRecord::append(field);-
135}
executed 967 times by 6 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
967
136-
137-
138/*!-
139 Returns \c true if field \a i in the index is sorted in descending-
140 order; otherwise returns \c false.-
141*/-
142-
143bool QSqlIndex::isDescending(int i) const-
144{-
145 if (i >= 0 && i < sorts.size())
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
i < sorts.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
146 return sorts[i];
never executed: return sorts[i];
0
147 return false;
never executed: return false;
0
148}-
149-
150/*!-
151 If \a desc is true, field \a i is sorted in descending order.-
152 Otherwise, field \a i is sorted in ascending order (the default).-
153 If the field does not exist, nothing happens.-
154*/-
155-
156void QSqlIndex::setDescending(int i, bool desc)-
157{-
158 if (i >= 0 && i < sorts.size())
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
i < sorts.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
159 sorts[i] = desc;
never executed: sorts[i] = desc;
0
160}
never executed: end of block
0
161-
162/*! \internal-
163-
164 Creates a string representing the field number \a i using prefix \a-
165 prefix. If \a verbose is true, ASC or DESC is included in the field-
166 description if the field is sorted in ASCending or DESCending order.-
167*/-
168-
169QString QSqlIndex::createField(int i, const QString& prefix, bool verbose) const-
170{-
171 QString f;-
172 if (!prefix.isEmpty())
!prefix.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
173 f += prefix + QLatin1Char('.');
never executed: f += prefix + QLatin1Char('.');
0
174 f += field(i).name();-
175 if (verbose)
verboseDescription
TRUEnever evaluated
FALSEnever evaluated
0
176 f += QLatin1Char(' ') + QString((isDescending(i)
never executed: f += QLatin1Char(' ') + QString((isDescending(i) ? QLatin1String("DESC") : QLatin1String("ASC")));
0
177 ? QLatin1String("DESC") : QLatin1String("ASC")));
never executed: f += QLatin1Char(' ') + QString((isDescending(i) ? QLatin1String("DESC") : QLatin1String("ASC")));
0
178 return f;
never executed: return f;
0
179}-
180-
181/*!-
182 \fn QString QSqlIndex::cursorName() const-
183-
184 Returns the name of the cursor which the index is associated with.-
185*/-
186-
187-
188/*!-
189 Sets the name of the cursor that the index is associated with to-
190 \a cursorName.-
191*/-
192void QSqlIndex::setCursorName(const QString& cursorName)-
193{-
194 cursor = cursorName;-
195}
never executed: end of block
0
196-
197QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9