Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Fonctions  · 

QSqlField Class Reference
[sql module]

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

#include <qsqlfield.h>

List of all member functions.

Public Members

  • QSqlField ( const QString & fieldName = QString::null, QVariant::Type type = QVariant::Invalid )
  • QSqlField ( const QSqlField & other )
  • QSqlField & operator= ( const QSqlField & other )
  • bool operator== ( const QSqlField & other ) const
  • virtual ~QSqlField ()
  • virtual void setValue ( const QVariant & value )
  • virtual QVariant value () const
  • virtual void setName ( const QString & name )
  • QString name () const
  • virtual void setNull ()
  • bool isNull () const
  • virtual void setReadOnly ( bool readOnly )
  • bool isReadOnly () const
  • void clear ( bool nullify = TRUE )
  • QVariant::Type type () const

Detailed Description

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

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.

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

    QSqlField f( "myfield", QVariant::Int );
    f.setValue( QPixmap() );  // will not work
    

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

    QSqlField f( "myfield", QVariant::Int );
    f.setValue( QString("123") ); // casts QString to int
    

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:

    QSqlCursor cur( "Employee" );        // create cursor using the 'Employee' table
    QSqlField* 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:

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

See also Database Classes.


Member Function Documentation

QSqlField::QSqlField ( const QString & fieldName = QString::null, QVariant::Type type = QVariant::Invalid )

Constructs an empty field called fieldName of type type.

QSqlField::QSqlField ( const QSqlField & other )

Constructs a copy of other.

QSqlField::~QSqlField () [virtual]

Destroys the object and frees any allocated resources.

void QSqlField::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 QSqlField::isNull () const

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

bool QSqlField::isReadOnly () const

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

QString QSqlField::name () const

Returns the name of the field.

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

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

Sets the field equal to other.

bool QSqlField::operator== ( const QSqlField & 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 QSqlField::setName ( const QString & name ) [virtual]

Sets the name of the field to name.

void QSqlField::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 QSqlField::setReadOnly ( bool readOnly ) [virtual]

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

See also setValue().

void QSqlField::setValue ( const QVariant & 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 QString to an integer data type. For example:

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

See also isReadOnly().

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.

QVariant QSqlField::value () const [virtual]

Returns the value of the field as a QVariant.

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


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

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 64
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Developer Network au hasard

Logo

Extension de Qt WebKit

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 3.3
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web