Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsqlindex.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include "qsqlindex.h"
6
7#include "qsqlfield.h"
8
10
11using namespace Qt::StringLiterals;
12
13/*!
14 \class QSqlIndex
15 \brief The QSqlIndex class provides functions to manipulate and
16 describe database indexes.
17
18 \ingroup database
19 \inmodule QtSql
20
21 An \e index refers to a single table or view in a database.
22 Information about the fields that comprise the index can be used
23 to generate SQL statements.
24*/
25
26/*!
27 Constructs an empty index using the cursor name \a cursorname and
28 index name \a name.
29*/
30
31QSqlIndex::QSqlIndex(const QString& cursorname, const QString& name)
32 : cursor(cursorname), nm(name)
33{
34}
35
36/*!
37 Constructs a copy of \a other.
38*/
39
40QSqlIndex::QSqlIndex(const QSqlIndex& other)
41 : QSqlRecord(other), cursor(other.cursor), nm(other.nm), sorts(other.sorts)
42{
43}
44
45/*! \fn QSqlIndex::QSqlIndex(QSqlIndex &&other)
46 Move-constructs a new QSqlIndex from \a other.
47
48 \note The moved-from object \a other is placed in a
49 partially-formed state, in which the only valid operations are
50 destruction and assignment of a new value.
51
52 \since 6.6
53*/
54/*! \fn QSqlIndex& QSqlIndex::operator=(QSqlIndex &&other)
55 Move-assigns \a other to this QSqlIndex instance.
56
57 \note The moved-from object \a other is placed in a
58 partially-formed state, in which the only valid operations are
59 destruction and assignment of a new value.
60
61 \since 6.6
62*/
63
64/*!
65 Sets the index equal to \a other.
66*/
67
68QSqlIndex& QSqlIndex::operator=(const QSqlIndex& other)
69{
70 cursor = other.cursor;
71 nm = other.nm;
72 sorts = other.sorts;
73 QSqlRecord::operator=(other);
74 return *this;
75}
76
77
78/*!
79 Destroys the object and frees any allocated resources.
80*/
81
82QSqlIndex::~QSqlIndex()
83{
84
85}
86
87/*!
88 \property QSqlIndex::name
89 \since 6.8
90 This property holds the name of the index.
91*/
92/*!
93 \fn QString QSqlIndex::name() const
94 Returns the \l name.
95*/
96/*!
97 Sets \l name to \a name.
98*/
99void QSqlIndex::setName(const QString& name)
100{
101 nm = name;
102}
103
104/*!
105 Appends the field \a field to the list of indexed fields. The
106 field is appended with an ascending sort order.
107*/
108
109void QSqlIndex::append(const QSqlField& field)
110{
111 append(field, false);
112}
113
114/*!
115 \overload
116
117 Appends the field \a field to the list of indexed fields. The
118 field is appended with an ascending sort order, unless \a desc is
119 true.
120*/
121
122void QSqlIndex::append(const QSqlField& field, bool desc)
123{
124 sorts.append(desc);
125 QSqlRecord::append(field);
126}
127
128
129/*!
130 Returns \c true if field \a i in the index is sorted in descending
131 order; otherwise returns \c false.
132*/
133
134bool QSqlIndex::isDescending(int i) const
135{
136 if (i >= 0 && i < sorts.size())
137 return sorts[i];
138 return false;
139}
140
141/*!
142 If \a desc is true, field \a i is sorted in descending order.
143 Otherwise, field \a i is sorted in ascending order (the default).
144 If the field does not exist, nothing happens.
145*/
146
147void QSqlIndex::setDescending(int i, bool desc)
148{
149 if (i >= 0 && i < sorts.size())
150 sorts[i] = desc;
151}
152
153/*!
154 \property QSqlIndex::cursorName
155 \since 6.8
156 This property holds the name of the cursor which the index
157 is associated with.
158*/
159/*!
160 \fn QString QSqlIndex::cursorName() const
161 Returns the \l cursorName.
162*/
163/*!
164 Sets \l cursorName to \a cursorName.
165*/
166void QSqlIndex::setCursorName(const QString& cursorName)
167{
168 cursor = cursorName;
169}
170
171QT_END_NAMESPACE
172
173#include "moc_qsqlindex.cpp"