Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

QSqlRecord Class Reference

The QSqlRecord class encapsulates a database record, i.e. a set of database fields. More...

#include <QSqlRecord>

Inherited by QSqlCursor and QSqlIndex.

Public Functions


Detailed Description

The QSqlRecord class encapsulates a database record, i.e. a set of database fields.

The QSqlRecord class encapsulates the functionality and characteristics of a database record (usually a table or view within the database). QSqlRecords support adding and removing fields as well as setting and retrieving field values.

QSqlRecord is implicitly shared. This means you can make copies of a record in O(1) time. If multiple QSqlRecord instances share the same data and one is modifying the record's data then this modifying instance makes a copy and modifies its private copy - thus it does not affect other instances.

A record's field's can be set by name or position with setValue(); if you want to set a field to NULL use setNull(). To find the position of a field by name use indexOf(), and to find the name of a field at a particular position use fieldName(). Use field() to retrieve a QSqlField object for a given field. Use contains() to see if the record contains a particular field name.

When queries are generated to be executed on the database only those fields for which isGenerated() is true are included in the generated SQL.

A record can have fields added with append() or insert(), replaced with replace(), and removed with remove(). All the fields can be removed with clear(). The number of fields is given by count(); all their values can be cleared (to NULL) using clearValues(). The names of all the fields is returned by toString() and by toStringList().


Member Function Documentation

QSqlRecord::QSqlRecord ()

Constructs an empty record. isEmpty() will return true and count() will return 0.

See also append() and insert().

QSqlRecord::QSqlRecord ( const QSqlRecord & other )

Constructs a copy of other.

QSqlRecord::~QSqlRecord ()

Destroys the object and frees any allocated resources.

void QSqlRecord::append ( const QSqlField & field )

Append a copy of field field to the end of the record.

See also insert(), replace(), and remove().

void QSqlRecord::clear ()

Removes all the record's fields.

See also clearValues() and isEmpty().

void QSqlRecord::clearValues ()

Clears the value of all fields in the record and sets each field to NULL.

See also setValue().

bool QSqlRecord::contains ( const QString & name ) const

Returns true if there is a field in the record called name; otherwise returns false.

int QSqlRecord::count () const

Returns the number of fields in the record.

See also isEmpty().

QSqlField QSqlRecord::field ( int i ) const

Returns the field at position i. If the position is out of range, an empty field is returned.

QSqlField QSqlRecord::field ( const QString & name ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the field called name.

QString QSqlRecord::fieldName ( int i ) const

Returns the name of the field at position i. If the field does not exist, an empty string is returned.

See also indexOf().

int QSqlRecord::indexOf ( const QString & name ) const

Returns the position of the field called name within the record, or -1 if it cannot be found. Field names are not case-sensitive. If more than one field matches, the first one is returned.

See also fieldName().

void QSqlRecord::insert ( int pos, const QSqlField & field )

Inserts the field field at position pos in the record.

See also append(), replace(), and remove().

bool QSqlRecord::isEmpty () const

Returns true if there are no fields in the record; otherwise returns false.

See also append(), insert(), and clear().

bool QSqlRecord::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.

See also setGenerated().

bool QSqlRecord::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.

See also setNull().

bool QSqlRecord::isNull ( int i ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns true if the field i is NULL or if there is no field at position i; otherwise returns false.

void QSqlRecord::remove ( int pos )

Removes the field at position pos. If pos is out of range, nothing happens.

See also append(), insert(), and replace().

void QSqlRecord::replace ( int pos, const QSqlField & field )

Replaces the field at position pos with the given field. If pos is out of range, nothing happens.

See also append(), insert(), and remove().

void QSqlRecord::setGenerated ( const QString & name, bool generated )

Sets the generated flag for the field called name to generated. If the field does not exist, nothing happens. Only fields that have generated set to true are included in the SQL that is generated, e.g. by QSqlCursor.

See also isGenerated().

void QSqlRecord::setGenerated ( int i, bool generated )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the generated flag for the field i to generated.

See also isGenerated().

void QSqlRecord::setNull ( int i )

Sets the value of field i to NULL. If the field does not exist, nothing happens.

See also setValue().

void QSqlRecord::setNull ( const QString & name )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the value of the field called name to NULL. If the field does not exist, nothing happens.

void QSqlRecord::setValue ( int i, const QCoreVariant & val )

Sets the value of the field at position i to val. If the field does not exist, nothing happens.

See also setNull().

void QSqlRecord::setValue ( const QString & name, const QCoreVariant & val )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the value of the field called name to val. If the field does not exist, nothing happens.

QCoreVariant QSqlRecord::value ( int i ) const

Returns the value of the field located at position i in the record. If field i does not exist an invalid variant is returned.

This function should be used with QSqlQuerys. When working with a QSqlCursor the value(const QString&) overload which uses field names is more appropriate.

See also fieldName() and isNull().

QCoreVariant QSqlRecord::value ( const QString & name ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the value of the field called name in the record. If field name does not exist an invalid variant is returned.

See also indexOf().

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

Sets the record equal to other.


Copyright © 2004 Trolltech. Trademarks
Qt 4.0.0-tp2