Qt 4.8
qsqlindex.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 
48 
70 QSqlIndex::QSqlIndex(const QString& cursorname, const QString& name)
71  : cursor(cursorname), nm(name)
72 {
73 }
74 
80  : QSqlRecord(other), cursor(other.cursor), nm(other.nm), sorts(other.sorts)
81 {
82 }
83 
89 {
90  cursor = other.cursor;
91  nm = other.nm;
92  sorts = other.sorts;
93  QSqlRecord::operator=(other);
94  return *this;
95 }
96 
102 {
103 
104 }
105 
111 {
112  nm = name;
113 }
114 
130 {
131  append(field, false);
132 }
133 
145 void QSqlIndex::append(const QSqlField& field, bool desc)
146 {
147  sorts.append(desc);
148  QSqlRecord::append(field);
149 }
150 
151 
157 bool QSqlIndex::isDescending(int i) const
158 {
159  if (i >= 0 && i < sorts.size())
160  return sorts[i];
161  return false;
162 }
163 
170 void QSqlIndex::setDescending(int i, bool desc)
171 {
172  if (i >= 0 && i < sorts.size())
173  sorts[i] = desc;
174 }
175 
176 #ifdef QT3_SUPPORT
177 
192 QString QSqlIndex::toString(const QString& prefix, const QString& sep, bool verbose) const
193 {
194  QString s;
195  bool comma = false;
196  for (int i = 0; i < count(); ++i) {
197  if(comma)
198  s += sep + QLatin1Char(' ');
199  s += createField(i, prefix, verbose);
200  comma = true;
201  }
202  return s;
203 }
204 
221 QStringList QSqlIndex::toStringList(const QString& prefix, bool verbose) const
222 {
223  QStringList s;
224  for (int i = 0; i < count(); ++i)
225  s += createField(i, prefix, verbose);
226  return s;
227 }
228 #endif
229 
240 QString QSqlIndex::createField(int i, const QString& prefix, bool verbose) const
241 {
242  QString f;
243  if (!prefix.isEmpty())
244  f += prefix + QLatin1Char('.');
245  f += field(i).name();
246  if (verbose)
247  f += QLatin1Char(' ') + QString((isDescending(i)
248  ? QLatin1String("DESC") : QLatin1String("ASC")));
249  return f;
250 }
251 
267 {
268  cursor = cursorName;
269 }
270 
The QSqlIndex class provides functions to manipulate and describe database indexes.
Definition: qsqlindex.h:55
QString cursorName() const
Returns the name of the cursor which the index is associated with.
Definition: qsqlindex.h:63
QString cursor
Definition: qsqlindex.h:83
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
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:70
QString createField(int i, const QString &prefix, bool verbose) const
Creates a string representing the field number i using prefix prefix.
Definition: qsqlindex.cpp:240
void append(const QSqlField &field)
Appends the field field to the list of indexed fields.
Definition: qsqlindex.cpp:129
QString nm
Definition: qsqlindex.h:84
QSqlIndex & operator=(const QSqlIndex &other)
Sets the index equal to other.
Definition: qsqlindex.cpp:88
QList< bool > sorts
Definition: qsqlindex.h:85
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QSqlRecord class encapsulates a database record.
Definition: qsqlrecord.h:58
The QString class provides a Unicode character string.
Definition: qstring.h:83
QSqlRecord & operator=(const QSqlRecord &other)
Sets the record equal to other.
Definition: qsqlrecord.cpp:156
~QSqlIndex()
Destroys the object and frees any allocated resources.
Definition: qsqlindex.cpp:101
QString name() const
Returns the name of the field.
Definition: qsqlfield.cpp:380
static QString toString(Register *reg, int type, bool *ok=0)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * name
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void setName(const QString &name)
Sets the name of the index to name.
Definition: qsqlindex.cpp:110
void setCursorName(const QString &cursorName)
Sets the name of the cursor that the index is associated with to cursorName.
Definition: qsqlindex.cpp:266
void setDescending(int i, bool desc)
If desc is true, field i is sorted in descending order.
Definition: qsqlindex.cpp:170
QSqlField field(int i) const
Returns the field at position index.
Definition: qsqlrecord.cpp:289
int count() const
Returns the number of fields in the record.
Definition: qsqlrecord.cpp:573
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void append(const QSqlField &field)
Append a copy of field field to the end of the record.
Definition: qsqlrecord.cpp:312
bool isDescending(int i) const
Returns true if field i in the index is sorted in descending order; otherwise returns false...
Definition: qsqlindex.cpp:157
The QSqlField class manipulates the fields in SQL database tables and views.
Definition: qsqlfield.h:56
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QString name() const
Returns the name of the index.
Definition: qsqlindex.h:65