[196] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Implementation 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 | #include "qsqlextension_p.h"
|
---|
| 38 |
|
---|
| 39 | #ifndef QT_NO_SQL
|
---|
| 40 | QSqlExtension::QSqlExtension()
|
---|
| 41 | : bindm( BindByPosition ), bindCount( 0 )
|
---|
| 42 | {
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | QSqlExtension::~QSqlExtension()
|
---|
| 46 | {
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | bool QSqlExtension::prepare( const QString& /*query*/ )
|
---|
| 50 | {
|
---|
| 51 | return FALSE;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | bool QSqlExtension::exec()
|
---|
| 55 | {
|
---|
| 56 | return FALSE;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | void QSqlExtension::bindValue( const QString& placeholder, const QVariant& val, QSql::ParameterType tp )
|
---|
| 60 | {
|
---|
| 61 | bindm = BindByName;
|
---|
| 62 | // if the index has already been set when doing emulated named
|
---|
| 63 | // bindings - don't reset it
|
---|
| 64 | if ( index.contains( (int)values.count() ) ) {
|
---|
| 65 | index[ (int)values.count() ] = placeholder;
|
---|
| 66 | }
|
---|
| 67 | values[ placeholder ] = Param( val, tp );
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | void QSqlExtension::bindValue( int pos, const QVariant& val, QSql::ParameterType tp )
|
---|
| 71 | {
|
---|
| 72 | bindm = BindByPosition;
|
---|
| 73 | index[ pos ] = QString::number( pos );
|
---|
| 74 | QString nm = QString::number( pos );
|
---|
| 75 | values[ nm ] = Param( val, tp );
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | void QSqlExtension::addBindValue( const QVariant& val, QSql::ParameterType tp )
|
---|
| 79 | {
|
---|
| 80 | bindm = BindByPosition;
|
---|
| 81 | bindValue( bindCount++, val, tp );
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | void QSqlExtension::clearValues()
|
---|
| 85 | {
|
---|
| 86 | values.clear();
|
---|
| 87 | bindCount = 0;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | void QSqlExtension::resetBindCount()
|
---|
| 91 | {
|
---|
| 92 | bindCount = 0;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | void QSqlExtension::clearIndex()
|
---|
| 96 | {
|
---|
| 97 | index.clear();
|
---|
| 98 | holders.clear();
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | void QSqlExtension::clear()
|
---|
| 102 | {
|
---|
| 103 | clearValues();
|
---|
| 104 | clearIndex();
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | QVariant QSqlExtension::parameterValue( const QString& holder )
|
---|
| 108 | {
|
---|
| 109 | return values[ holder ].value;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | QVariant QSqlExtension::parameterValue( int pos )
|
---|
| 113 | {
|
---|
| 114 | return values[ index[ pos ] ].value;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | QVariant QSqlExtension::boundValue( const QString& holder ) const
|
---|
| 118 | {
|
---|
| 119 | return values[ holder ].value;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | QVariant QSqlExtension::boundValue( int pos ) const
|
---|
| 123 | {
|
---|
| 124 | return values[ index[ pos ] ].value;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | QMap<QString, QVariant> QSqlExtension::boundValues() const
|
---|
| 128 | {
|
---|
| 129 | QMap<QString, Param>::ConstIterator it;
|
---|
| 130 | QMap<QString, QVariant> m;
|
---|
| 131 | if ( bindm == BindByName ) {
|
---|
| 132 | for ( it = values.begin(); it != values.end(); ++it )
|
---|
| 133 | m.insert( it.key(), it.data().value );
|
---|
| 134 | } else {
|
---|
| 135 | QString key, tmp, fmt;
|
---|
| 136 | fmt.sprintf( "%%0%dd", QString::number( values.count()-1 ).length() );
|
---|
| 137 | for ( it = values.begin(); it != values.end(); ++it ) {
|
---|
| 138 | tmp.sprintf( fmt.ascii(), it.key().toInt() );
|
---|
| 139 | m.insert( tmp, it.data().value );
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 | return m;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | QSqlExtension::BindMethod QSqlExtension::bindMethod()
|
---|
| 146 | {
|
---|
| 147 | return bindm;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | QSqlDriverExtension::QSqlDriverExtension()
|
---|
| 151 | {
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | QSqlDriverExtension::~QSqlDriverExtension()
|
---|
| 155 | {
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | QSqlOpenExtension::QSqlOpenExtension()
|
---|
| 159 | {
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | QSqlOpenExtension::~QSqlOpenExtension()
|
---|
| 163 | {
|
---|
| 164 | }
|
---|
| 165 | #endif
|
---|