Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
4#include "qsqlindex.h"
5
6#include "qsqlfield.h"
7
9
10using namespace Qt::StringLiterals;
11
30QSqlIndex::QSqlIndex(const QString& cursorname, const QString& name)
31 : cursor(cursorname), nm(name)
32{
33}
34
40 : QSqlRecord(other), cursor(other.cursor), nm(other.nm), sorts(other.sorts)
41{
42}
43
68{
69 cursor = other.cursor;
70 nm = other.nm;
71 sorts = other.sorts;
73 return *this;
74}
75
76
82{
83
84}
85
91{
92 nm = name;
93}
94
106void QSqlIndex::append(const QSqlField& field)
107{
108 append(field, false);
109}
110
119void QSqlIndex::append(const QSqlField& field, bool desc)
120{
121 sorts.append(desc);
123}
124
125
132{
133 if (i >= 0 && i < sorts.size())
134 return sorts[i];
135 return false;
136}
137
145{
146 if (i >= 0 && i < sorts.size())
147 sorts[i] = desc;
148}
149
157QString QSqlIndex::createField(int i, const QString& prefix, bool verbose) const
158{
159 QString f;
160 if (!prefix.isEmpty())
161 f += prefix + u'.';
162 f += field(i).name();
163 if (verbose)
164 f += u' ' + QString((isDescending(i) ? "DESC"_L1 : "ASC"_L1));
165 return f;
166}
167
179void QSqlIndex::setCursorName(const QString& cursorName)
180{
181 cursor = cursorName;
182}
183
qsizetype size() const noexcept
Definition qlist.h:386
void append(parameter_type t)
Definition qlist.h:441
The QSqlField class manipulates the fields in SQL database tables and views.
Definition qsqlfield.h:19
QString name() const
Returns the name of the field.
The QSqlIndex class provides functions to manipulate and describe database indexes.
Definition qsqlindex.h:16
QString name() const
Returns the name of the index.
Definition qsqlindex.h:28
void setName(const QString &name)
Sets the name of the index to name.
Definition qsqlindex.cpp:90
bool isDescending(int i) const
Returns true if field i in the index is sorted in descending order; otherwise returns false.
void setDescending(int i, bool desc)
If desc is true, field i is sorted in descending order.
QSqlIndex(const QString &cursorName=QString(), const QString &name=QString())
Constructs an empty index using the cursor name cursorname and index name name.
Definition qsqlindex.cpp:30
~QSqlIndex()
Destroys the object and frees any allocated resources.
Definition qsqlindex.cpp:81
QString cursorName() const
Returns the name of the cursor which the index is associated with.
Definition qsqlindex.h:26
void setCursorName(const QString &cursorName)
Sets the name of the cursor that the index is associated with to cursorName.
void append(const QSqlField &field)
Appends the field field to the list of indexed fields.
QSqlIndex & operator=(const QSqlIndex &other)
Sets the index equal to other.
Definition qsqlindex.cpp:67
The QSqlRecord class encapsulates a database record.
Definition qsqlrecord.h:20
QSqlField field(int i) const
Returns the field at position index.
void append(const QSqlField &field)
Append a copy of field field to the end of the record.
QSqlRecord & operator=(const QSqlRecord &other)
Sets the record equal to other.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
QCursor cursor
Combined button and popup list for selecting options.
GLfloat GLfloat f
GLuint name
@ desc
QSharedPointer< T > other(t)
[5]