KDb

KDbQueryParameterExpression.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003-2011 Jarosław Staniek <staniek@kde.org>
3
4 Based on nexp.cpp : Parser module of Python-like language
5 (C) 2001 Jarosław Staniek, MIMUW (www.mimuw.edu.pl)
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#include "KDbExpression.h"
24#include "KDb.h"
25#include "KDbQuerySchema.h"
26#include "KDbQuerySchemaParameter.h"
27#include "KDbDriver.h"
28#include "kdb_debug.h"
29#include "generated/sqlparser.h"
30
31KDbQueryParameterExpressionData::KDbQueryParameterExpressionData()
33 , m_type(KDbField::InvalidType)
34{
35 ExpressionDebug << "QueryParameterExpressionData" << ref;
36}
37
38KDbQueryParameterExpressionData::KDbQueryParameterExpressionData(
39 KDbField::Type type, const QVariant& value)
41 , m_type(type)
42{
43 ExpressionDebug << "QueryParameterExpressionData" << ref;
44}
45
46KDbQueryParameterExpressionData::~KDbQueryParameterExpressionData()
47{
48 ExpressionDebug << "~QueryParameterExpressionData" << ref;
49}
50
51KDbQueryParameterExpressionData* KDbQueryParameterExpressionData::clone()
52{
53 ExpressionDebug << "QueryParameterExpressionData::clone" << *this;
54 return new KDbQueryParameterExpressionData(*this);
55}
56
58{
59 Q_UNUSED(callStack);
60 dbg.nospace() << qPrintable(QString::fromLatin1("QueryParExp([%1],type=%2)")
62}
63
64KDbEscapedString KDbQueryParameterExpressionData::toStringInternal(
65 const KDbDriver *driver,
67 KDb::ExpressionCallStack* callStack) const
68{
69 Q_UNUSED(callStack);
70 return params
71 // Enclose in () because for example if the parameter is -1 and parent expression
72 // unary '-' then the result would be "--1" (a comment in SQL!).
73 // With the () the result will be a valid expression "-(-1)".
74 ? KDbEscapedString("(%1)").arg(driver->valueToSql(type(), params->previousValue()))
75 : KDbEscapedString("[%1]").arg(KDbEscapedString(value.toString()));
76}
77
78void KDbQueryParameterExpressionData::getQueryParameters(QList<KDbQuerySchemaParameter>* params)
79{
80 Q_ASSERT(params);
82 param.setMessage(value.toString());
83 param.setType(type());
84 params->append(param);
85}
86
87bool KDbQueryParameterExpressionData::validateInternal(KDbParseInfo *parseInfo, KDb::ExpressionCallStack* callStack)
88{
89 Q_UNUSED(parseInfo);
90 return typeInternal(callStack) != KDbField::InvalidType;
91}
92
93KDbField::Type KDbQueryParameterExpressionData::typeInternal(KDb::ExpressionCallStack* callStack) const
94{
95 Q_UNUSED(callStack);
96 return m_type;
97}
98
99//=========================================
100
103{
104 ExpressionDebug << "KDbQueryParameterExpression() ctor" << *this;
105}
106
109 KDb::QueryParameterExpression, KDbToken::QUERY_PARAMETER)
110{
111}
112
117
119 : KDbConstExpression(data)
120{
121 ExpressionDebug << "KDbQueryParameterExpression ctor (KDbExpressionData*)" << *this;
122}
123
125 : KDbConstExpression(ptr)
126{
127}
128
129KDbQueryParameterExpression::~KDbQueryParameterExpression()
130{
131}
132
Internal data class used to implement implicitly shared class KDbConstExpression.
The KDbConstExpression class represents const expression.
Database driver's abstraction.
Definition KDbDriver.h:50
static QString defaultSqlTypeName(KDbField::Type type)
virtual KDbEscapedString valueToSql(KDbField::Type ftype, const QVariant &v) const
Specialized string for escaping.
Internal data class used to implement implicitly shared class KDbExpression.
KDbField::Type type() const
KDbField::Type type() const
ExplicitlySharedExpressionDataPointer d
Meta-data for a field.
Definition KDbField.h:72
@ InvalidType
Definition KDbField.h:86
Internal data class used to implement implicitly shared class KDbQueryParameterExpression.
void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override
Sends information about this expression to debug output dbg (internal).
The KDbQueryParameterExpression class represents query parameter expression.
An iterator for a list of values of query schema parameters Allows to iterate over parameters and ret...
A single parameter of a query schema.
A type-safe KDbSQL token It can be used in KDb expressions.
Definition KDbToken.h:37
Type type(const QSqlDatabase &db)
A database connectivity and creation framework.
QDebug & nospace()
void append(QList< T > &&value)
QString fromLatin1(QByteArrayView str)
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:07 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.