Qt 4.8
Public Functions | Private Functions | Properties | List of all members
QSqlIndex Class Reference

The QSqlIndex class provides functions to manipulate and describe database indexes. More...

#include <qsqlindex.h>

Inheritance diagram for QSqlIndex:
QSqlRecord

Public Functions

void append (const QSqlField &field)
 Appends the field field to the list of indexed fields. More...
 
void append (const QSqlField &field, bool desc)
 Appends the field field to the list of indexed fields. More...
 
QString cursorName () const
 Returns the name of the cursor which the index is associated with. More...
 
bool isDescending (int i) const
 Returns true if field i in the index is sorted in descending order; otherwise returns false. More...
 
QString name () const
 Returns the name of the index. More...
 
QSqlIndexoperator= (const QSqlIndex &other)
 Sets the index equal to other. More...
 
 QSqlIndex (const QString &cursorName=QString(), const QString &name=QString())
 Constructs an empty index using the cursor name cursorname and index name name. More...
 
 QSqlIndex (const QSqlIndex &other)
 Constructs a copy of other. More...
 
void setCursorName (const QString &cursorName)
 Sets the name of the cursor that the index is associated with to cursorName. More...
 
void setDescending (int i, bool desc)
 If desc is true, field i is sorted in descending order. More...
 
void setName (const QString &name)
 Sets the name of the index to name. More...
 
 ~QSqlIndex ()
 Destroys the object and frees any allocated resources. More...
 
- Public Functions inherited from QSqlRecord
void append (const QSqlField &field)
 Append a copy of field field to the end of the record. More...
 
void clear ()
 Removes all the record's fields. More...
 
void clearValues ()
 Clears the value of all fields in the record and sets each field to null. More...
 
bool contains (const QString &name) const
 Returns true if there is a field in the record called name; otherwise returns false. More...
 
int count () const
 Returns the number of fields in the record. More...
 
QSqlField field (int i) const
 Returns the field at position index. More...
 
QSqlField field (const QString &name) const
 Returns the field called name. More...
 
QString fieldName (int i) const
 Returns the name of the field at position index. More...
 
int indexOf (const QString &name) const
 Returns the position of the field called name within the record, or -1 if it cannot be found. More...
 
void insert (int pos, const QSqlField &field)
 Inserts the field field at position pos in the record. More...
 
bool isEmpty () const
 Returns true if there are no fields in the record; otherwise returns false. More...
 
bool isGenerated (int i) const
 Returns true if the record has a field at position index and this field is to be generated (the default); otherwise returns false. More...
 
bool isGenerated (const QString &name) const
 Returns true if the record has a field called name and this field is to be generated (the default); otherwise returns false. More...
 
bool isNull (int i) const
 Returns true if the field index is null or if there is no field at position index; otherwise returns false. More...
 
bool isNull (const QString &name) const
 Returns true if the field called name is null or if there is no field called name; otherwise returns false. More...
 
bool operator!= (const QSqlRecord &other) const
 Returns true if this object is not identical to other; otherwise returns false. More...
 
QSqlRecordoperator= (const QSqlRecord &other)
 Sets the record equal to other. More...
 
bool operator== (const QSqlRecord &other) const
 Returns true if this object is identical to other (i.e., has the same fields in the same order); otherwise returns false. More...
 
 QSqlRecord ()
 Constructs an empty record. More...
 
 QSqlRecord (const QSqlRecord &other)
 Constructs a copy of other. More...
 
void remove (int pos)
 Removes the field at position pos. More...
 
void replace (int pos, const QSqlField &field)
 Replaces the field at position pos with the given field. More...
 
void setGenerated (const QString &name, bool generated)
 Sets the generated flag for the field called name to generated. More...
 
void setGenerated (int i, bool generated)
 Sets the generated flag for the field index to generated. More...
 
void setNull (int i)
 Sets the value of field index to null. More...
 
void setNull (const QString &name)
 Sets the value of the field called name to null. More...
 
void setValue (int i, const QVariant &val)
 Sets the value of the field at position index to val. More...
 
void setValue (const QString &name, const QVariant &val)
 Sets the value of the field called name to val. More...
 
QVariant value (int i) const
 Returns the value of the field located at position index in the record. More...
 
QVariant value (const QString &name) const
 Returns the value of the field called name in the record. More...
 
 ~QSqlRecord ()
 Destroys the object and frees any allocated resources. More...
 

Private Functions

QString createField (int i, const QString &prefix, bool verbose) const
 Creates a string representing the field number i using prefix prefix. More...
 

Properties

QString cursor
 
QString nm
 
QList< bool > sorts
 

Detailed Description

The QSqlIndex class provides functions to manipulate and describe database indexes.

Attention
Module: QtSql

An index refers to a single table or view in a database. Information about the fields that comprise the index can be used to generate SQL statements.

Definition at line 55 of file qsqlindex.h.

Constructors and Destructors

◆ QSqlIndex() [1/2]

QSqlIndex::QSqlIndex ( const QString cursorName = QString(),
const QString name = QString() 
)

Constructs an empty index using the cursor name cursorname and index name name.

Definition at line 70 of file qsqlindex.cpp.

71  : cursor(cursorname), nm(name)
72 {
73 }
QString cursor
Definition: qsqlindex.h:83
QString nm
Definition: qsqlindex.h:84

◆ QSqlIndex() [2/2]

QSqlIndex::QSqlIndex ( const QSqlIndex other)

Constructs a copy of other.

Definition at line 79 of file qsqlindex.cpp.

80  : QSqlRecord(other), cursor(other.cursor), nm(other.nm), sorts(other.sorts)
81 {
82 }
QString cursor
Definition: qsqlindex.h:83
QString nm
Definition: qsqlindex.h:84
QList< bool > sorts
Definition: qsqlindex.h:85
QSqlRecord()
Constructs an empty record.
Definition: qsqlrecord.cpp:131

◆ ~QSqlIndex()

QSqlIndex::~QSqlIndex ( )

Destroys the object and frees any allocated resources.

Definition at line 101 of file qsqlindex.cpp.

102 {
103 
104 }

Functions

◆ append() [1/2]

void QSqlIndex::append ( const QSqlField field)

Appends the field field to the list of indexed fields.

The field is appended with an ascending sort order.

Definition at line 129 of file qsqlindex.cpp.

Referenced by QDB2Driver::primaryIndex(), QIBaseDriver::primaryIndex(), QOCIDriver::primaryIndex(), QSQLite2Driver::primaryIndex(), QTDSDriver::primaryIndex(), QMYSQLDriver::primaryIndex(), QODBCDriver::primaryIndex(), QPSQLDriver::primaryIndex(), qExtractSecurityPolicyFromString(), and qGetTableInfo().

130 {
131  append(field, false);
132 }
void append(const QSqlField &field)
Appends the field field to the list of indexed fields.
Definition: qsqlindex.cpp:129

◆ append() [2/2]

void QSqlIndex::append ( const QSqlField field,
bool  desc 
)

Appends the field field to the list of indexed fields.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The field is appended with an ascending sort order, unless desc is true.

Definition at line 145 of file qsqlindex.cpp.

146 {
147  sorts.append(desc);
148  QSqlRecord::append(field);
149 }
QList< bool > sorts
Definition: qsqlindex.h:85
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void append(const QSqlField &field)
Append a copy of field field to the end of the record.
Definition: qsqlrecord.cpp:312

◆ createField()

QString QSqlIndex::createField ( int  i,
const QString prefix,
bool  verbose 
) const
private

Creates a string representing the field number i using prefix prefix.

Warning
This function is not part of the public interface.

If verbose is true, ASC or DESC is included in the field description if the field is sorted in ASCending or DESCending order.

Definition at line 240 of file qsqlindex.cpp.

Referenced by setDescending().

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 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString name() const
Returns the name of the field.
Definition: qsqlfield.cpp:380
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QSqlField field(int i) const
Returns the field at position index.
Definition: qsqlrecord.cpp:289
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 QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ cursorName()

QString QSqlIndex::cursorName ( ) const
inline

Returns the name of the cursor which the index is associated with.

Definition at line 63 of file qsqlindex.h.

Referenced by setCursorName().

63 { return cursor; }
QString cursor
Definition: qsqlindex.h:83

◆ isDescending()

bool QSqlIndex::isDescending ( int  i) const

Returns true if field i in the index is sorted in descending order; otherwise returns false.

Definition at line 157 of file qsqlindex.cpp.

Referenced by createField().

158 {
159  if (i >= 0 && i < sorts.size())
160  return sorts[i];
161  return false;
162 }
QList< bool > sorts
Definition: qsqlindex.h:85
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ name()

QString QSqlIndex::name ( ) const
inline

Returns the name of the index.

Definition at line 65 of file qsqlindex.h.

Referenced by setName().

65 { return nm; }
QString nm
Definition: qsqlindex.h:84

◆ operator=()

QSqlIndex & QSqlIndex::operator= ( const QSqlIndex other)

Sets the index equal to other.

Definition at line 88 of file qsqlindex.cpp.

89 {
90  cursor = other.cursor;
91  nm = other.nm;
92  sorts = other.sorts;
93  QSqlRecord::operator=(other);
94  return *this;
95 }
QString cursor
Definition: qsqlindex.h:83
QString nm
Definition: qsqlindex.h:84
QList< bool > sorts
Definition: qsqlindex.h:85
QSqlRecord & operator=(const QSqlRecord &other)
Sets the record equal to other.
Definition: qsqlrecord.cpp:156

◆ setCursorName()

void QSqlIndex::setCursorName ( const QString cursorName)

Sets the name of the cursor that the index is associated with to cursorName.

Definition at line 266 of file qsqlindex.cpp.

Referenced by QMYSQLDriver::primaryIndex().

267 {
268  cursor = cursorName;
269 }
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

◆ setDescending()

void QSqlIndex::setDescending ( int  i,
bool  desc 
)

If desc is true, field i is sorted in descending order.

Otherwise, field i is sorted in ascending order (the default). If the field does not exist, nothing happens.

Definition at line 170 of file qsqlindex.cpp.

171 {
172  if (i >= 0 && i < sorts.size())
173  sorts[i] = desc;
174 }
QList< bool > sorts
Definition: qsqlindex.h:85
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ setName()

void QSqlIndex::setName ( const QString name)

Sets the name of the index to name.

Definition at line 110 of file qsqlindex.cpp.

Referenced by QDB2Driver::primaryIndex(), QIBaseDriver::primaryIndex(), QOCIDriver::primaryIndex(), QTDSDriver::primaryIndex(), QMYSQLDriver::primaryIndex(), QODBCDriver::primaryIndex(), and QPSQLDriver::primaryIndex().

111 {
112  nm = name;
113 }
QString nm
Definition: qsqlindex.h:84
QString name() const
Returns the name of the index.
Definition: qsqlindex.h:65

Properties

◆ cursor

QString QSqlIndex::cursor
private

Definition at line 83 of file qsqlindex.h.

Referenced by operator=(), and setCursorName().

◆ nm

QString QSqlIndex::nm
private

Definition at line 84 of file qsqlindex.h.

Referenced by operator=(), and setName().

◆ sorts

QList<bool> QSqlIndex::sorts
private

Definition at line 85 of file qsqlindex.h.

Referenced by append(), isDescending(), operator=(), and setDescending().


The documentation for this class was generated from the following files: