TQSqlRecord Class

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

# TQSqlRecord Class Reference
[sql module]

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

`#include <tqsqlrecord.h>`

Inherited by TQSqlCursor and TQSqlIndex.

List of all member functions.

## Public Members

- TQSqlRecord ()
- TQSqlRecord ( const TQSqlRecord & other )
- TQSqlRecord & operator= ( const TQSqlRecord & other )
- virtual ~TQSqlRecord ()
- virtual TQVariant value ( int i ) const
- virtual TQVariant value ( const TQString & name ) const
- virtual void setValue ( int i, const TQVariant & val )
- virtual void setValue ( const TQString & name, const TQVariant & val )
- bool isGenerated ( int i ) const
- bool isGenerated ( const TQString & name ) const
- virtual void setGenerated ( const TQString & name, bool generated )
- virtual void setGenerated ( int i, bool generated )
- virtual void setNull ( int i )
- virtual void setNull ( const TQString & name )
- bool isNull ( int i ) const
- bool isNull ( const TQString & name ) const
- int position ( const TQString & name ) const
- TQString fieldName ( int i ) const
- TQSqlField * field ( int i )
- TQSqlField * field ( const TQString & name )
- const TQSqlField * field ( int i ) const
- const TQSqlField * field ( const TQString & name ) const
- virtual void append ( const TQSqlField & field )
- virtual void insert ( int pos, const TQSqlField & field )
- virtual void remove ( int pos )
- bool isEmpty () const
- bool contains ( const TQString & name ) const
- virtual void clear ()
- virtual void clearValues ( bool nullify = false )
- uint count () const
- virtual TQString toString ( const TQString & prefix = TQString::null, const TQString & sep = "," ) const
- virtual TQStringList toStringList ( const TQString & prefix = TQString::null ) const

## Detailed Description

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

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

TQSqlRecord is implicitly shared. This means you can make copies of the record in time O(1). If multiple TQSqlRecord 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 TQSqlRecordInfo and Database Classes.

## Member Function Documentation

### TQSqlRecord::TQSqlRecord ()

Constructs an empty record.

### TQSqlRecord::TQSqlRecord ( const TQSqlRecord & other )

Constructs a copy of other.

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

Destroys the object and frees any allocated resources.

### void TQSqlRecord::append ( const TQSqlField & field )`[virtual]`

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

Reimplemented in TQSqlIndex.

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

Removes all the record's fields.

See also clearValues().

Reimplemented in TQSqlCursor.

### void TQSqlRecord::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 TQSqlRecord::contains ( const TQString & name ) const

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

### uint TQSqlRecord::count () const

Returns the number of fields in the record.

### TQSqlField * TQSqlRecord::field ( int i )

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

### TQSqlField * TQSqlRecord::field ( const TQString & 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 TQSqlField * TQSqlRecord::field ( int i ) const

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

### const TQSqlField * TQSqlRecord::field ( const TQString & 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.

### TQString TQSqlRecord::fieldName ( int i ) const

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

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

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

### bool TQSqlRecord::isEmpty () const

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

### bool TQSqlRecord::isGenerated ( const TQString & 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 TQSqlRecord::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 TQSqlRecord::isNull ( const TQString & 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 TQSqlRecord::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().

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

Sets the record equal to other.

### int TQSqlRecord::position ( const TQString & 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 TQSqlRecord::remove ( int pos )`[virtual]`

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

Reimplemented in TQSqlCursor.

### void TQSqlRecord::setGenerated ( const TQString & 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 TQSqlCursor.

See also isGenerated().

Reimplemented in TQSqlCursor.

### void TQSqlRecord::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 TQSqlCursor.

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

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

### void TQSqlRecord::setNull ( const TQString & 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 TQSqlRecord::setValue ( int i, const TQVariant & 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 TQSqlRecord::setValue ( const TQString & name, const TQVariant & 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.

### TQString TQSqlRecord::toString ( const TQString & prefix = TQString::null, const TQString & 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>"

### TQStringList TQSqlRecord::toStringList ( const TQString & prefix = TQString::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>"

### TQVariant TQSqlRecord::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 TQSqlQuerys. When working with a TQSqlCursor the value(const TQString&) overload which uses field names is more appropriate.

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

### TQVariant TQSqlRecord::value ( const TQString & 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 TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.