kexi

kexiqueryparameters.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 "kexiqueryparameters.h"
21
22#include <kdebug.h>
23#include <tdelocale.h>
24#include <kinputdialog.h>
25#include <knumvalidator.h>
26
27#include <kexidb/queryschemaparameter.h>
28#include <kexidb/utils.h>
29#include "utils/kexidatetimeformatter.h"
30
31//static
32TQValueList<TQVariant> KexiQueryParameters::getParameters(TQWidget *parent,
33 const KexiDB::Driver &driver, KexiDB::QuerySchema& querySchema, bool &ok)
34{
35 Q_UNUSED(driver);
36 ok = false;
37 const KexiDB::QuerySchemaParameterList params( querySchema.parameters() );
38 TQValueList<TQVariant> values;
39 const TQString caption( i18n("Enter Query Parameter Value", "Enter Parameter Value") );
40 foreach(KexiDB::QuerySchemaParameterListConstIterator, it, params) {
41 switch ((*it).type) {
47 int minValue, maxValue;
49 KexiDB::getLimitsForType((*it).type, minValue, maxValue);
50 const int result = KInputDialog::getInteger(
51 caption, (*it).message, 0, minValue, maxValue, 1/*step*/, 10/*base*/, &ok, parent);
52 if (!ok)
53 return TQValueList<TQVariant>(); //cancelled
54 values.append(result);
55 break;
56 }
58 TQStringList list;
59 list << i18n("Boolean True - Yes", "Yes") << i18n("Boolean False - No", "No");
60 const TQString result = KInputDialog::getItem(
61 caption, (*it).message, list, 0/*current*/, false , &ok, parent);
62 if (!ok || result.isEmpty())
63 return TQValueList<TQVariant>(); //cancelled
64 values.append( TQVariant( result==list.first() ) );
65 break;
66 }
67 case KexiDB::Field::Date: {
69 const TQString result = KInputDialog::getText(
70 caption, (*it).message, TQString(), &ok, parent, 0/*name*/,
72 0/*validator*/, df.inputMask() );
73 if (!ok)
74 return TQValueList<TQVariant>(); //cancelled
75 values.append( df.stringToDate(result) );
76 break;
77 }
78 case KexiDB::Field::DateTime: {
81 const TQString result = KInputDialog::getText(
82 caption, (*it).message, TQString(), &ok, parent, 0/*name*/,
84 0/*validator*/, dateTimeInputMask(df, tf) );
85 if (!ok)
86 return TQValueList<TQVariant>(); //cancelled
87 values.append( stringToDateTime(df, tf, result) );
88 break;
89 }
90 case KexiDB::Field::Time: {
92 const TQString result = KInputDialog::getText(
93 caption, (*it).message, TQString(), &ok, parent, 0/*name*/,
95 0/*validator*/, tf.inputMask() );
96 if (!ok)
97 return TQValueList<TQVariant>(); //cancelled
98 values.append( tf.stringToTime(result) );
99 break;
100 }
103 // KInputDialog::getDouble() does not work well, use getText and double validator
104 KDoubleValidator validator(0);
105 const TQString textResult = KInputDialog::getText( caption, (*it).message, TQString(), &ok,
106 parent, 0, &validator);
107 if (!ok || textResult.isEmpty())
108 return TQValueList<TQVariant>(); //cancelled
111 const double result = textResult.toDouble(&ok); //this is also good for float (to avoid rounding)
112 if (!ok)
113 return TQValueList<TQVariant>();
114 values.append( result );
115 break;
116 }
119 const TQString result = KInputDialog::getText(
120 caption, (*it).message, TQString(), &ok, parent);
121 if (!ok)
122 return TQValueList<TQVariant>(); //cancelled
123 values.append( result );
124 break;
125 }
126 case KexiDB::Field::BLOB: {
128 values.append( TQByteArray() );
129 }
130 default:
131 kexiwarn << "KexiQueryParameters::getParameters() unsupported type " << KexiDB::Field::typeName((*it).type)
132 << " for parameter \"" << (*it).message << "\" - aborting query execution!" << endl;
133 return TQValueList<TQVariant>();
134 }
135 }
136 ok = true;
137 return values;
138}
139
Generic database abstraction.
Definition driver.h:67
TQString typeName() const
Definition field.h:298
@ ShortInteger
Definition field.h:86
KexiDB::QuerySchema provides information about database query.
QuerySchemaParameterList parameters()
Date formatter used by KexiDateTableEdit and KexiDateTimeTableEdit.
TQDate stringToDate(const TQString &str) const
Converts string str to date using predefined settings.
TQString inputMask() const
static TQValueList< TQVariant > getParameters(TQWidget *parent, const KexiDB::Driver &driver, KexiDB::QuerySchema &querySchema, bool &ok)
Time formatter used by KexiTimeTableEdit and KexiDateTimeTableEdit Following time formats are allowed...
TQTime stringToTime(const TQString &str) const
converts string str to time using predefined settings
TQString inputMask() const
KEXI_DB_EXPORT void getLimitsForType(Field::Type type, int &minValue, int &maxValue)