queryschemaparameter.cpp
Go to the documentation of this file.00001 /* This file is part of the KDE project 00002 Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "queryschemaparameter.h" 00021 #include "driver.h" 00022 00023 #include <kdebug.h> 00024 #include <qguardedptr.h> 00025 00026 using namespace KexiDB; 00027 00028 QuerySchemaParameter::QuerySchemaParameter() 00029 : type(Field::InvalidType) 00030 { 00031 } 00032 00033 QuerySchemaParameter::~QuerySchemaParameter() 00034 { 00035 } 00036 00037 QString QuerySchemaParameter::debugString() const 00038 { 00039 return QString("msg=\"%1\" type=\"%2\"").arg(Field::typeName(type)).arg(message); 00040 } 00041 00042 void KexiDB::debug(const QuerySchemaParameterList& list) 00043 { 00044 KexiDBDbg << QString("Query parameters (%1):").arg(list.count()) << endl; 00045 foreach(QuerySchemaParameterListConstIterator, it, list) 00046 KexiDBDbg << " - " << (*it).debugString() << endl; 00047 } 00048 00049 //================================================ 00050 00051 class QuerySchemaParameterValueListIterator::Private 00052 { 00053 public: 00054 Private(const Driver& aDriver, const QValueList<QVariant>& aParams) 00055 : driver(&aDriver) 00056 , params(aParams) 00057 { 00058 //move to last item, as the order is reversed due to parser's internals 00059 paramsIt = params.fromLast(); //constBegin(); 00060 paramsItPosition = params.count(); 00061 } 00062 QGuardedPtr<const Driver> driver; 00063 const QValueList<QVariant> params; 00064 QValueList<QVariant>::ConstIterator paramsIt; 00065 uint paramsItPosition; 00066 }; 00067 00068 QuerySchemaParameterValueListIterator::QuerySchemaParameterValueListIterator( 00069 const Driver& driver, const QValueList<QVariant>& params) 00070 : d( new Private(driver, params) ) 00071 { 00072 } 00073 00074 QuerySchemaParameterValueListIterator::~QuerySchemaParameterValueListIterator() 00075 { 00076 delete d; 00077 } 00078 00079 QVariant QuerySchemaParameterValueListIterator::getPreviousValue() 00080 { 00081 if (d->paramsItPosition == 0) { //d->params.constEnd()) { 00082 KexiDBWarn << "QuerySchemaParameterValues::getPreviousValue() no prev value" << endl; 00083 return QVariant(); 00084 } 00085 QVariant res( *d->paramsIt ); 00086 --d->paramsItPosition; 00087 --d->paramsIt; 00088 // ++d->paramsIt; 00089 return res; 00090 } 00091 00092 QString QuerySchemaParameterValueListIterator::getPreviousValueAsString(Field::Type type) 00093 { 00094 if (d->paramsItPosition == 0) { //d->params.constEnd()) { 00095 KexiDBWarn << "QuerySchemaParameterValues::getPreviousValueAsString() no prev value" << endl; 00096 return d->driver->valueToSQL(type, QVariant()); //"NULL" 00097 } 00098 QString res( d->driver->valueToSQL(type, *d->paramsIt) ); 00099 --d->paramsItPosition; 00100 --d->paramsIt; 00101 // ++d->paramsIt; 00102 return res; 00103 }
