File indexing completed on 2024-11-03 13:04:19

0001 /* This file is part of the KDE project
0002    Copyright (C) 2006-2010 Jarosław Staniek <staniek@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "KDbQuerySchemaParameter.h"
0021 #include "KDbDriver.h"
0022 #include "KDbDriverManager_p.h"
0023 #include "kdb_debug.h"
0024 
0025 #include <QWeakPointer>
0026 
0027 KDbQuerySchemaParameter::~KDbQuerySchemaParameter()
0028 {
0029 }
0030 
0031 QDebug operator<<(QDebug dbg, const KDbQuerySchemaParameter& parameter)
0032 {
0033     dbg.nospace() << "MESSAGE=" << parameter.message() << "TYPE=" << KDbField::typeName(parameter.type());
0034     return dbg.space();
0035 }
0036 
0037 QDebug operator<<(QDebug dbg, const QList<KDbQuerySchemaParameter>& list)
0038 {
0039     dbg.nospace() << QString::fromLatin1("QUERY PARAMETERS (%1):").arg(list.count());
0040     foreach(const KDbQuerySchemaParameter& parameter, list) {
0041         dbg.nospace() << " - " << parameter;
0042     }
0043     return dbg.space();
0044 }
0045 
0046 //================================================
0047 
0048 class Q_DECL_HIDDEN KDbQuerySchemaParameterValueListIterator::Private
0049 {
0050 public:
0051     Private(/*const KDbDriver &driver, */const QList<QVariant>& aParams)
0052             : //driverWeakPointer(DriverManagerInternal::self()->driverWeakPointer(driver))
0053             params(aParams)
0054     {
0055         //move to last item, as the order is reversed due to parser's internals
0056         paramsIt = params.constEnd();
0057         --paramsIt;
0058         paramsItPosition = params.count();
0059     }
0060     //! @todo ?? QWeakPointer<const KDbDriver> driverWeakPointer;
0061     const QList<QVariant> params;
0062     QList<QVariant>::ConstIterator paramsIt;
0063     int paramsItPosition;
0064 private:
0065     Q_DISABLE_COPY(Private)
0066 };
0067 
0068 KDbQuerySchemaParameterValueListIterator::KDbQuerySchemaParameterValueListIterator(
0069     const QList<QVariant>& params)
0070         : d(new Private(params))
0071 {
0072 }
0073 
0074 KDbQuerySchemaParameterValueListIterator::~KDbQuerySchemaParameterValueListIterator()
0075 {
0076     delete d;
0077 }
0078 
0079 QVariant KDbQuerySchemaParameterValueListIterator::previousValue() const
0080 {
0081     if (d->paramsItPosition == 0) { //d->params.constEnd()) {
0082         kdbWarning() << "no prev value";
0083         return QVariant();
0084     }
0085     QVariant res(*d->paramsIt);
0086     --d->paramsItPosition;
0087     --d->paramsIt;
0088     return res;
0089 }