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

TQSqlField Class Reference
[sql module]

The TQSqlField class manipulates the fields in SQL database tables and views. More...

#include <tqsqlfield.h>

List of all member functions.

Public Members


Detailed Description

The TQSqlField class manipulates the fields in SQL database tables and views.

TQSqlField represents the characteristics of a single column in a database table or view, such as the data type and column name. A field also contains the value of the database column, which can be viewed or changed.

Field data values are stored as TQVariants. Using an incompatible type is not permitted. For example:

    TQSqlField f( "myfield", TQVariant::Int );
    f.setValue( TQPixmap() );  // will not work
    

However, the field will attempt to cast certain data types to the field data type where possible:

    TQSqlField f( "myfield", TQVariant::Int );
    f.setValue( TQString("123") ); // casts TQString to int
    

TQSqlField objects are rarely created explicitly in application code. They are usually accessed indirectly through TQSqlRecord or TQSqlCursor which already contain a list of fields. For example:

    TQSqlCursor cur( "Employee" );        // create cursor using the 'Employee' table
    TQSqlField* f = cur.field( "name" );  // use the 'name' field
    f->setValue( "Dave" );               // set field value
    ...
    

In practice we rarely need to extract a pointer to a field at all. The previous example would normally be written:

    TQSqlCursor cur( "Employee" );
    cur.setValue( "name", "Dave" );
    ...
    

See also Database Classes.


Member Function Documentation

TQSqlField::TQSqlField ( const TQString & fieldName = TQString::null, TQVariant::Type type = TQVariant::Invalid )

Constructs an empty field called fieldName of type type.

TQSqlField::TQSqlField ( const TQSqlField & other )

Constructs a copy of other.

TQSqlField::~TQSqlField () [virtual]

Destroys the object and frees any allocated resources.

void TQSqlField::clear ( bool nullify = TRUE )

Clears the value of the field. If the field is read-only, nothing happens. If nullify is TRUE (the default), the field is set to NULL.

bool TQSqlField::isNull () const

Returns TRUE if the field is currently NULL; otherwise returns FALSE.

bool TQSqlField::isReadOnly () const

Returns TRUE if the field's value is read only; otherwise returns FALSE.

TQString TQSqlField::name () const

Returns the name of the field.

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

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

Sets the field equal to other.

bool TQSqlField::operator== ( const TQSqlField & other ) const

Returns TRUE if the field is equal to other; otherwise returns FALSE. Fields are considered equal when the following field properties are the same:

void TQSqlField::setName ( const TQString & name ) [virtual]

Sets the name of the field to name.

void TQSqlField::setNull () [virtual]

Sets the field to NULL and clears the value using clear(). If the field is read-only, nothing happens.

See also isReadOnly() and clear().

void TQSqlField::setReadOnly ( bool readOnly ) [virtual]

Sets the read only flag of the field's value to readOnly.

See also setValue().

void TQSqlField::setValue ( const TQVariant & value ) [virtual]

Sets the value of the field to value. If the field is read-only (isReadOnly() returns TRUE), nothing happens. If the data type of value differs from the field's current data type, an attempt is made to cast it to the proper type. This preserves the data type of the field in the case of assignment, e.g. a TQString to an integer data type. For example:

    TQSqlCursor cur( "Employee" );                 // 'Employee' table
    TQSqlField* f = cur.field( "student_count" );  // an integer field
    ...
    f->setValue( myLineEdit->text() );            // cast the line edit text to an integer
    

See also isReadOnly().

TQVariant::Type TQSqlField::type () const

Returns the field's type as stored in the database. Note that the actual value might have a different type, Numerical values that are too large to store in a long int or double are usually stored as strings to prevent precision loss.

TQVariant TQSqlField::value () const [virtual]

Returns the value of the field as a TQVariant.

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


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


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8