QSqlRecord Class

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

# QSqlRecord Class Reference
[sql module]

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

`#include <qsqlrecord.h>`

Inherited by QSqlCursor and QSqlIndex.

List of all member functions.

## Public Members

- QSqlRecord ()
- QSqlRecord ( const QSqlRecord & other )
- QSqlRecord & operator= ( const QSqlRecord & other )
- virtual ~QSqlRecord ()
- virtual QVariant value ( int i ) const
- virtual QVariant value ( const QString & name ) const
- virtual void setValue ( int i, const QVariant & val )
- virtual void setValue ( const QString & name, const QVariant & val )
- bool isGenerated ( int i ) const
- bool isGenerated ( const QString & name ) const
- virtual void setGenerated ( const QString & name, bool generated )
- virtual void setGenerated ( int i, bool generated )
- virtual void setNull ( int i )
- virtual void setNull ( const QString & name )
- bool isNull ( int i ) const
- bool isNull ( const QString & name ) const
- int position ( const QString & name ) const
- QString fieldName ( int i ) const
- QSqlField * field ( int i )
- QSqlField * field ( const QString & name )
- const QSqlField * field ( int i ) const
- const QSqlField * field ( const QString & name ) const
- virtual void append ( const QSqlField & field )
- virtual void insert ( int pos, const QSqlField & field )
- virtual void remove ( int pos )
- bool isEmpty () const
- bool contains ( const QString & name ) const
- virtual void clear ()
- virtual void clearValues ( bool nullify = FALSE )
- uint count () const
- virtual QString toString ( const QString & prefix = QString::null, const QString & sep = "," ) const
- virtual QStringList toStringList ( const QString & prefix = QString::null ) const

## 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 the record in time O(1). 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.

See also QSqlRecordInfo and Database Classes.

## Member Function Documentation

### QSqlRecord::QSqlRecord ()

Constructs an empty record.

### QSqlRecord::QSqlRecord ( const QSqlRecord & other )

Constructs a copy of other.

### QSqlRecord::~QSqlRecord ()`[virtual]`

Destroys the object and frees any allocated resources.

### void QSqlRecord::append ( const QSqlField & field )`[virtual]`

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

Reimplemented in QSqlIndex.

### void QSqlRecord::clear ()`[virtual]`

Removes all the record's fields.

See also clearValues().

Reimplemented in QSqlCursor.

### void QSqlRecord::clearValues ( bool nullify = FALSE )`[virtual]`

Clears the value of all fields in the record. If nullify is TRUE, (the default is FALSE), each field is set to NULL.

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

Returns TRUE if there is a field in the record called name; otherwise returns FALSE.

### uint QSqlRecord::count () const

Returns the number of fields in the record.

### QSqlField * QSqlRecord::field ( int i )

Returns the field at position i within the record, or 0 if it cannot be found.

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

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

Returns the field called name within the record, or 0 if it cannot be found. Field names are not case-sensitive.

### const QSqlField * QSqlRecord::field ( int i ) const

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

### const 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 within the record, or 0 if it cannot be found. Field names are not case-sensitive.

### QString QSqlRecord::fieldName ( int i ) const

Returns the name of the field at position i. If the field does not exist, QString::null is returned.

### void QSqlRecord::insert ( int pos, const QSqlField & field )`[virtual]`

Insert a copy of field at position pos. If a field already exists at pos, it is removed.

### bool QSqlRecord::isEmpty () const

Returns TRUE if there are no fields in the record; otherwise returns FALSE.

### 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::isGenerated ( int i ) const

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

Returns TRUE if the record has a field at position i 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 position().

### 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.

See also fieldName().

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

Sets the record equal to other.

### int QSqlRecord::position ( 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.

### void QSqlRecord::remove ( int pos )`[virtual]`

Removes the field at pos. If pos does not exist, nothing happens.

Reimplemented in QSqlCursor.

### void QSqlRecord::setGenerated ( const QString & name, bool generated )`[virtual]`

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().

Reimplemented in QSqlCursor.

### void QSqlRecord::setGenerated ( int i, bool generated )`[virtual]`

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().

Reimplemented in QSqlCursor.

### void QSqlRecord::setNull ( int i )`[virtual]`

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

### void QSqlRecord::setNull ( const QString & name )`[virtual]`

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 QVariant & val )`[virtual]`

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

Examples: sql/overview/insert/main.cpp, sql/overview/insert2/main.cpp, sql/overview/subclass5/main.cpp, sql/overview/update/main.cpp, and sql/sqltable/main.cpp.

### void QSqlRecord::setValue ( const QString & name, const QVariant & val )`[virtual]`

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.

### QString QSqlRecord::toString ( const QString & prefix = QString::null, const QString & sep = "," ) const`[virtual]`

Returns a list of all the record's field names as a string separated by sep.

Note that fields which are not generated are not included (see isGenerated()). The returned string is suitable, for example, for generating SQL SELECT statements. If a prefix is specified, e.g. a table name, all fields are prefixed in the form:

"prefix.<fieldname>"

### QStringList QSqlRecord::toStringList ( const QString & prefix = QString::null ) const`[virtual]`

Returns a list of all the record's field names, each having the prefix prefix.

Note that fields which have generated set to FALSE are not included. (See isGenerated()). If prefix is supplied, e.g. a table name, all fields are prefixed in the form:

"prefix.<fieldname>"

### QVariant QSqlRecord::value ( int i ) const`[virtual]`

Returns the value of the field located at position i in the record. If field i does not exist the resultant behaviour is undefined.

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

Example: sql/overview/update/main.cpp.

### QVariant QSqlRecord::value ( const QString & name ) const`[virtual]`

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 the resultant behaviour is undefined.

This file is part of the Qt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.