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