/****************************************************************************
**
** Copyright (C) 1992-2004 Trolltech AS. All rights reserved.
**
** This file is part of the sql module of the Qt Toolkit.
**
** Licensees holding valid Qt Preview licenses may use this file in
** accordance with the Qt Preview License Agreement provided with the
** Software.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#ifndef QSQLFIELD_H
#define QSQLFIELD_H

#include "qcorevariant.h"
#include "qstring.h"

#if defined(QT_LICENSE_PROFESSIONAL)
#define QM_EXPORT_SQL
#else
#define QM_EXPORT_SQL Q_SQL_EXPORT
#endif

#ifndef QT_NO_SQL

class QSqlFieldPrivate;

class QM_EXPORT_SQL QSqlField
{
public:
    enum State { Unknown = -1, No = 0, Yes = 1 };

    QSqlField(const QString& fieldName = QString(),
              QCoreVariant::Type type = QCoreVariant::Invalid);

    QSqlField(const QSqlField& other);
    QSqlField& operator=(const QSqlField& other);
    bool operator==(const QSqlField& other) const;
    ~QSqlField();

    void setValue(const QCoreVariant& value);
    inline QCoreVariant value() const
    { return val; }
    void setName(const QString& name);
    QString name() const;
    bool isNull() const;
    void setReadOnly(bool readOnly);
    bool isReadOnly() const;
    void clear();
    QCoreVariant::Type type() const;
    void setType(QCoreVariant::Type type);

    void setRequired(State required);
    inline void setRequired(bool required) { setRequired(required ? Yes : No); }
    void setLength(int fieldLength);
    void setPrecision(int precision);
    void setDefaultValue(const QCoreVariant &value);
    void setSqlType(int type);
    void setAutoGenerated(State autogen);
    inline void setAutoGenerated(bool autogen) { setAutoGenerated(autogen ? Yes : No); }

    State isRequired() const;
    int length() const;
    int precision() const;
    QCoreVariant defaultValue() const;
    int typeID() const;
    State isAutoGenerated() const;
    bool isValid() const;

#ifdef QT_COMPAT
    inline QT_COMPAT void setNull() { clear(); }
#endif

private:
    void detach();
    QCoreVariant val;
    QSqlFieldPrivate* d;
};

#ifndef QT_NO_DEBUG
QM_EXPORT_SQL QDebug operator<<(QDebug, const QSqlField &);
#endif

#endif        // QT_NO_SQL
#endif
