| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Definition of the QSqlExtension class
|
|---|
| 4 | **
|
|---|
| 5 | ** Created : 2002-06-03
|
|---|
| 6 | **
|
|---|
| 7 | ** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved.
|
|---|
| 8 | **
|
|---|
| 9 | ** This file is part of the sql module of the Qt GUI Toolkit.
|
|---|
| 10 | **
|
|---|
| 11 | ** This file may be distributed under the terms of the Q Public License
|
|---|
| 12 | ** as defined by Trolltech ASA of Norway and appearing in the file
|
|---|
| 13 | ** LICENSE.QPL included in the packaging of this file.
|
|---|
| 14 | **
|
|---|
| 15 | ** This file may be distributed and/or modified under the terms of the
|
|---|
| 16 | ** GNU General Public License version 2 as published by the Free Software
|
|---|
| 17 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 18 | ** packaging of this file.
|
|---|
| 19 | **
|
|---|
| 20 | ** Licensees holding valid Qt Enterprise Edition licenses may use this
|
|---|
| 21 | ** file in accordance with the Qt Commercial License Agreement provided
|
|---|
| 22 | ** with the Software.
|
|---|
| 23 | **
|
|---|
| 24 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|---|
| 25 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 26 | **
|
|---|
| 27 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
|---|
| 28 | ** information about Qt Commercial License Agreements.
|
|---|
| 29 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
|---|
| 30 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
|---|
| 31 | **
|
|---|
| 32 | ** Contact info@trolltech.com if any conditions of this licensing are
|
|---|
| 33 | ** not clear to you.
|
|---|
| 34 | **
|
|---|
| 35 | **********************************************************************/
|
|---|
| 36 |
|
|---|
| 37 | #ifndef QSQLEXTENSION_P_H
|
|---|
| 38 | #define QSQLEXTENSION_P_H
|
|---|
| 39 |
|
|---|
| 40 | //
|
|---|
| 41 | // W A R N I N G
|
|---|
| 42 | // -------------
|
|---|
| 43 | //
|
|---|
| 44 | // This file is not part of the Qt API. It exists for the convenience
|
|---|
| 45 | // of other Qt classes. This header file may change from version to
|
|---|
| 46 | // version without notice, or even be removed.
|
|---|
| 47 | //
|
|---|
| 48 | // We mean it.
|
|---|
| 49 | //
|
|---|
| 50 | //
|
|---|
| 51 |
|
|---|
| 52 | #ifndef QT_H
|
|---|
| 53 | #include "qmap.h"
|
|---|
| 54 | #include "qvaluevector.h"
|
|---|
| 55 | #include "qstring.h"
|
|---|
| 56 | #include "qvariant.h"
|
|---|
| 57 | #include "qsql.h"
|
|---|
| 58 | #endif // QT_H
|
|---|
| 59 |
|
|---|
| 60 | #ifndef QT_NO_SQL
|
|---|
| 61 |
|
|---|
| 62 | #if !defined( QT_MODULE_SQL ) || defined( QT_LICENSE_PROFESSIONAL )
|
|---|
| 63 | #define QM_EXPORT_SQL
|
|---|
| 64 | #define QM_TEMPLATE_EXTERN_SQL
|
|---|
| 65 | #else
|
|---|
| 66 | #define QM_EXPORT_SQL Q_EXPORT
|
|---|
| 67 | #define QM_TEMPLATE_EXTERN_SQL Q_TEMPLATE_EXTERN
|
|---|
| 68 | #endif
|
|---|
| 69 |
|
|---|
| 70 | struct Param {
|
|---|
| 71 | Param( const QVariant& v = QVariant(), QSql::ParameterType t = QSql::In ): value( v ), typ( t ) {}
|
|---|
| 72 | QVariant value;
|
|---|
| 73 | QSql::ParameterType typ;
|
|---|
| 74 | Q_DUMMY_COMPARISON_OPERATOR(Param)
|
|---|
| 75 | };
|
|---|
| 76 |
|
|---|
| 77 | struct Holder {
|
|---|
| 78 | Holder( const QString& hldr = QString::null, int pos = -1 ): holderName( hldr ), holderPos( pos ) {}
|
|---|
| 79 | bool operator==( const Holder& h ) const { return h.holderPos == holderPos && h.holderName == holderName; }
|
|---|
| 80 | bool operator!=( const Holder& h ) const { return h.holderPos != holderPos || h.holderName != holderName; }
|
|---|
| 81 | QString holderName;
|
|---|
| 82 | int holderPos;
|
|---|
| 83 | };
|
|---|
| 84 |
|
|---|
| 85 | #define Q_DEFINED_QSQLEXTENSION
|
|---|
| 86 | #include "qwinexport.h"
|
|---|
| 87 |
|
|---|
| 88 | class QM_EXPORT_SQL QSqlExtension {
|
|---|
| 89 | public:
|
|---|
| 90 | QSqlExtension();
|
|---|
| 91 | virtual ~QSqlExtension();
|
|---|
| 92 | virtual bool prepare( const QString& query );
|
|---|
| 93 | virtual bool exec();
|
|---|
| 94 | virtual void bindValue( const QString& holder, const QVariant& value, QSql::ParameterType = QSql::In );
|
|---|
| 95 | virtual void bindValue( int pos, const QVariant& value, QSql::ParameterType = QSql::In );
|
|---|
| 96 | virtual void addBindValue( const QVariant& value, QSql::ParameterType = QSql::In );
|
|---|
| 97 | virtual QVariant parameterValue( const QString& holder );
|
|---|
| 98 | virtual QVariant parameterValue( int pos );
|
|---|
| 99 | QVariant boundValue( const QString& holder ) const;
|
|---|
| 100 | QVariant boundValue( int pos ) const;
|
|---|
| 101 | QMap<QString, QVariant> boundValues() const;
|
|---|
| 102 | void clear();
|
|---|
| 103 | void clearValues();
|
|---|
| 104 | void clearIndex();
|
|---|
| 105 | void resetBindCount();
|
|---|
| 106 |
|
|---|
| 107 | enum BindMethod { BindByPosition, BindByName };
|
|---|
| 108 | BindMethod bindMethod(); // ### 4.0: make this const
|
|---|
| 109 | BindMethod bindm;
|
|---|
| 110 | int bindCount;
|
|---|
| 111 |
|
|---|
| 112 | QMap<int, QString> index;
|
|---|
| 113 | typedef QMap<QString, Param> ValueMap;
|
|---|
| 114 | ValueMap values;
|
|---|
| 115 |
|
|---|
| 116 | // convenience container for QSqlQuery
|
|---|
| 117 | // to map holders <-> positions
|
|---|
| 118 | typedef QValueVector<Holder> HolderVector;
|
|---|
| 119 | HolderVector holders;
|
|---|
| 120 | };
|
|---|
| 121 |
|
|---|
| 122 | class QM_EXPORT_SQL QSqlDriverExtension
|
|---|
| 123 | {
|
|---|
| 124 | public:
|
|---|
| 125 | QSqlDriverExtension();
|
|---|
| 126 | virtual ~QSqlDriverExtension();
|
|---|
| 127 | virtual bool isOpen() const = 0;
|
|---|
| 128 | };
|
|---|
| 129 |
|
|---|
| 130 | class QM_EXPORT_SQL QSqlOpenExtension
|
|---|
| 131 | {
|
|---|
| 132 | public:
|
|---|
| 133 | QSqlOpenExtension();
|
|---|
| 134 | virtual ~QSqlOpenExtension();
|
|---|
| 135 | virtual bool open( const QString& db,
|
|---|
| 136 | const QString& user,
|
|---|
| 137 | const QString& password,
|
|---|
| 138 | const QString& host,
|
|---|
| 139 | int port,
|
|---|
| 140 | const QString& connOpts ) = 0;
|
|---|
| 141 | };
|
|---|
| 142 | #endif
|
|---|
| 143 |
|
|---|
| 144 | #endif
|
|---|