summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/tqsqlfield.3qt
blob: d50016d2d6615252569c5ea1cdde66c9f666e493 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
'\" 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 [email protected] .
Please include the name of the manual page (tqsqlfield.3qt) and the Qt
version (3.3.8).