kexi

queryschemaparameter.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "queryschemaparameter.h"
21#include "driver.h"
22
23#include <kdebug.h>
24#include <tqguardedptr.h>
25
26using namespace KexiDB;
27
28QuerySchemaParameter::QuerySchemaParameter()
29 : type(Field::InvalidType)
30{
31}
32
33QuerySchemaParameter::~QuerySchemaParameter()
34{
35}
36
37TQString QuerySchemaParameter::debugString() const
38{
39 return TQString("msg=\"%1\" type=\"%2\"").arg(Field::typeName(type)).arg(message);
40}
41
42void KexiDB::debug(const QuerySchemaParameterList& list)
43{
44 KexiDBDbg << TQString("Query parameters (%1):").arg(list.count()) << endl;
45 foreach(QuerySchemaParameterListConstIterator, it, list)
46 KexiDBDbg << " - " << (*it).debugString() << endl;
47}
48
49//================================================
50
51class QuerySchemaParameterValueListIterator::Private
52{
53 public:
54 Private(const Driver& aDriver, const TQValueList<TQVariant>& aParams)
55 : driver(&aDriver)
56 , params(aParams)
57 {
58 //move to last item, as the order is reversed due to parser's internals
59 paramsIt = params.fromLast(); //constBegin();
60 paramsItPosition = params.count();
61 }
62 TQGuardedPtr<const Driver> driver;
63 const TQValueList<TQVariant> params;
64 TQValueList<TQVariant>::ConstIterator paramsIt;
65 uint paramsItPosition;
66};
67
68QuerySchemaParameterValueListIterator::QuerySchemaParameterValueListIterator(
69 const Driver& driver, const TQValueList<TQVariant>& params)
70 : d( new Private(driver, params) )
71{
72}
73
74QuerySchemaParameterValueListIterator::~QuerySchemaParameterValueListIterator()
75{
76 delete d;
77}
78
80{
81 if (d->paramsItPosition == 0) { //d->params.constEnd()) {
82 KexiDBWarn << "QuerySchemaParameterValues::getPreviousValue() no prev value" << endl;
83 return TQVariant();
84 }
85 TQVariant res( *d->paramsIt );
86 --d->paramsItPosition;
87 --d->paramsIt;
88// ++d->paramsIt;
89 return res;
90}
91
93{
94 if (d->paramsItPosition == 0) { //d->params.constEnd()) {
95 KexiDBWarn << "QuerySchemaParameterValues::getPreviousValueAsString() no prev value" << endl;
96 return d->driver->valueToSQL(type, TQVariant()); //"NULL"
97 }
98 TQString res( d->driver->valueToSQL(type, *d->paramsIt) );
99 --d->paramsItPosition;
100 --d->paramsIt;
101// ++d->paramsIt;
102 return res;
103}
Generic database abstraction.
Definition driver.h:67
Meta-data for a field.
Definition field.h:73
TQString typeName() const
Definition field.h:298
Field::Type type
A datatype of the parameter.
TQString message
A user-visible message that will be displayed to ask for value of the parameter.
High-level database connectivity library with database backend drivers.
KEXI_DB_EXPORT void debug(const QuerySchemaParameterList &list)
Shows debug information for list.