You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
200 lines
6.6 KiB
200 lines
6.6 KiB
'\" t
|
|
.TH QSqlField 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
|
|
.\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
|
|
.\" license file included in the distribution for a complete license
|
|
.\" statement.
|
|
.\"
|
|
.ad l
|
|
.nh
|
|
.SH NAME
|
|
QSqlField \- Manipulates the fields in SQL database tables and views
|
|
.SH SYNOPSIS
|
|
\fC#include <ntqsqlfield.h>\fR
|
|
.PP
|
|
.SS "Public Members"
|
|
.in +1c
|
|
.ti -1c
|
|
.BI "\fBQSqlField\fR ( const QString & fieldName = QString::null, QVariant::Type type = QVariant::Invalid )"
|
|
.br
|
|
.ti -1c
|
|
.BI "\fBQSqlField\fR ( const QSqlField & other )"
|
|
.br
|
|
.ti -1c
|
|
.BI "QSqlField & \fBoperator=\fR ( const QSqlField & other )"
|
|
.br
|
|
.ti -1c
|
|
.BI "bool \fBoperator==\fR ( const QSqlField & other ) const"
|
|
.br
|
|
.ti -1c
|
|
.BI "virtual \fB~QSqlField\fR ()"
|
|
.br
|
|
.ti -1c
|
|
.BI "virtual void \fBsetValue\fR ( const QVariant & value )"
|
|
.br
|
|
.ti -1c
|
|
.BI "virtual QVariant \fBvalue\fR () const"
|
|
.br
|
|
.ti -1c
|
|
.BI "virtual void \fBsetName\fR ( const QString & name )"
|
|
.br
|
|
.ti -1c
|
|
.BI "QString \fBname\fR () const"
|
|
.br
|
|
.ti -1c
|
|
.BI "virtual void \fBsetNull\fR ()"
|
|
.br
|
|
.ti -1c
|
|
.BI "bool \fBisNull\fR () const"
|
|
.br
|
|
.ti -1c
|
|
.BI "virtual void \fBsetReadOnly\fR ( bool readOnly )"
|
|
.br
|
|
.ti -1c
|
|
.BI "bool \fBisReadOnly\fR () const"
|
|
.br
|
|
.ti -1c
|
|
.BI "void \fBclear\fR ( bool nullify = TRUE )"
|
|
.br
|
|
.ti -1c
|
|
.BI "QVariant::Type \fBtype\fR () const"
|
|
.br
|
|
.in -1c
|
|
.SH DESCRIPTION
|
|
The QSqlField class manipulates the fields in SQL database tables and views.
|
|
.PP
|
|
QSqlField 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.
|
|
.PP
|
|
Field data values are stored as QVariants. Using an incompatible type is not permitted. For example:
|
|
.PP
|
|
.nf
|
|
.br
|
|
QSqlField f( "myfield", QVariant::Int );
|
|
.br
|
|
f.setValue( QPixmap() ); // will not work
|
|
.br
|
|
.fi
|
|
.PP
|
|
However, the field will attempt to cast certain data types to the field data type where possible:
|
|
.PP
|
|
.nf
|
|
.br
|
|
QSqlField f( "myfield", QVariant::Int );
|
|
.br
|
|
f.setValue( QString("123") ); // casts QString to int
|
|
.br
|
|
.fi
|
|
.PP
|
|
QSqlField objects are rarely created explicitly in application code. They are usually accessed indirectly through QSqlRecord or QSqlCursor which already contain a list of fields. For example:
|
|
.PP
|
|
.nf
|
|
.br
|
|
QSqlCursor cur( "Employee" ); // create cursor using the 'Employee' table
|
|
.br
|
|
QSqlField* f = cur.field( "name" ); // use the 'name' field
|
|
.br
|
|
f->setValue( "Dave" ); // set field value
|
|
.br
|
|
...
|
|
.br
|
|
.fi
|
|
.PP
|
|
In practice we rarely need to extract a pointer to a field at all. The previous example would normally be written:
|
|
.PP
|
|
.nf
|
|
.br
|
|
QSqlCursor cur( "Employee" );
|
|
.br
|
|
cur.setValue( "name", "Dave" );
|
|
.br
|
|
...
|
|
.br
|
|
.fi
|
|
.PP
|
|
See also Database Classes.
|
|
.SH MEMBER FUNCTION DOCUMENTATION
|
|
.SH "QSqlField::QSqlField ( const QString & fieldName = QString::null, QVariant::Type type = QVariant::Invalid )"
|
|
Constructs an empty field called \fIfieldName\fR of type \fItype\fR.
|
|
.SH "QSqlField::QSqlField ( const QSqlField & other )"
|
|
Constructs a copy of \fIother\fR.
|
|
.SH "QSqlField::~QSqlField ()\fC [virtual]\fR"
|
|
Destroys the object and frees any allocated resources.
|
|
.SH "void QSqlField::clear ( bool nullify = TRUE )"
|
|
Clears the value of the field. If the field is read-only, nothing happens. If \fInullify\fR is TRUE (the default), the field is set to NULL.
|
|
.SH "bool QSqlField::isNull () const"
|
|
Returns TRUE if the field is currently NULL; otherwise returns FALSE.
|
|
.SH "bool QSqlField::isReadOnly () const"
|
|
Returns TRUE if the field's value is read only; otherwise returns FALSE.
|
|
.SH "QString QSqlField::name () const"
|
|
Returns the name of the field.
|
|
.PP
|
|
Example: sql/overview/table4/main.cpp.
|
|
.SH "QSqlField & QSqlField::operator= ( const QSqlField & other )"
|
|
Sets the field equal to \fIother\fR.
|
|
.SH "bool QSqlField::operator== ( const QSqlField & other ) const"
|
|
Returns TRUE if the field is equal to \fIother\fR; otherwise returns FALSE. Fields are considered equal when the following field properties are the same:
|
|
.TP
|
|
name()
|
|
.TP
|
|
isNull()
|
|
.TP
|
|
value()
|
|
.TP
|
|
isReadOnly()
|
|
.SH "void QSqlField::setName ( const QString & name )\fC [virtual]\fR"
|
|
Sets the name of the field to \fIname\fR.
|
|
.SH "void QSqlField::setNull ()\fC [virtual]\fR"
|
|
Sets the field to NULL and clears the value using clear(). If the field is read-only, nothing happens.
|
|
.PP
|
|
See also isReadOnly() and clear().
|
|
.SH "void QSqlField::setReadOnly ( bool readOnly )\fC [virtual]\fR"
|
|
Sets the read only flag of the field's value to \fIreadOnly\fR.
|
|
.PP
|
|
See also setValue().
|
|
.SH "void QSqlField::setValue ( const QVariant & value )\fC [virtual]\fR"
|
|
Sets the value of the field to \fIvalue\fR. If the field is read-only (isReadOnly() returns TRUE), nothing happens. If the data type of \fIvalue\fR 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 QString to an integer data type. For example:
|
|
.PP
|
|
.nf
|
|
.br
|
|
QSqlCursor cur( "Employee" ); // 'Employee' table
|
|
.br
|
|
QSqlField* f = cur.field( "student_count" ); // an integer field
|
|
.br
|
|
...
|
|
.br
|
|
f->setValue( myLineEdit->text() ); // cast the line edit text to an integer
|
|
.br
|
|
.fi
|
|
.PP
|
|
See also isReadOnly().
|
|
.SH "QVariant::Type QSqlField::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.
|
|
.SH "QVariant QSqlField::value () const\fC [virtual]\fR"
|
|
Returns the value of the field as a QVariant.
|
|
.PP
|
|
Example: sql/overview/table4/main.cpp.
|
|
|
|
.SH "SEE ALSO"
|
|
.BR http://doc.trolltech.com/ntqsqlfield.html
|
|
.BR http://www.trolltech.com/faq/tech.html
|
|
.SH COPYRIGHT
|
|
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
|
|
license file included in the distribution for a complete license
|
|
statement.
|
|
.SH AUTHOR
|
|
Generated automatically from the source code.
|
|
.SH BUGS
|
|
If you find a bug in Qt, please report it as described in
|
|
.BR http://doc.trolltech.com/bughowto.html .
|
|
Good bug reports help us to help you. Thank you.
|
|
.P
|
|
The definitive Qt documentation is provided in HTML format; it is
|
|
located at $QTDIR/doc/html and can be read using Qt Assistant or with
|
|
a web browser. This man page is provided as a convenience for those
|
|
users who prefer man pages, although this format is not officially
|
|
supported by Trolltech.
|
|
.P
|
|
If you find errors in this manual page, please report them to
|
|
.BR qt-bugs@trolltech.com .
|
|
Please include the name of the manual page (qsqlfield.3qt) and the Qt
|
|
version (3.3.8).
|