KDb

KDbToken.cpp
1/****************************************************************************
2 * Created by generate_parser_code.sh
3 * WARNING! All changes made in this file will be lost!
4 ****************************************************************************/
5/* This file is part of the KDE project
6 Copyright (C) 2015-2018 Jarosław Staniek <staniek@kde.org>
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#include "KDbToken.h"
25#include "KDbDriver.h"
26#include "KDbDriver_p.h"
27#include "KDbDriverBehavior.h"
28#include "sqlparser.h"
29#include "parser/KDbParser_p.h"
30
31#include <QGlobalStatic>
32
33KDbToken::KDbToken(char charToken)
34 : v(g_tokenName(charToken) == nullptr ? 0 : charToken)
35{
36}
37
39{
40 if (!isValid()) {
41 return QLatin1String("<INVALID_TOKEN>");
42 }
43 if (v > maxCharTokenValue) {
44 return QLatin1String(g_tokenName(v));
45 }
46 if (isprint(v)) {
47 return QString(QLatin1Char(char(v)));
48 }
49 else {
51 }
52}
53
55{
56 if (toChar() > 0) {
57 return name();
58 }
59 // other arithmetic operations: << >>
60 // NOTE: only include cases that have toString() != name() or are dependent on driver
61 switch (v) {
62 case ::BITWISE_SHIFT_RIGHT: return QLatin1String(">>");
63 case ::BITWISE_SHIFT_LEFT: return QLatin1String("<<");
64 // other relational operations: <= >= <> (or !=) LIKE IN
65 case ::NOT_EQUAL: return QLatin1String("<>");
66 case ::NOT_EQUAL2: return QLatin1String("!=");
67 case ::LESS_OR_EQUAL: return QLatin1String("<=");
68 case ::GREATER_OR_EQUAL: return QLatin1String(">=");
69 case ::LIKE: return driver ? KDbDriverPrivate::behavior(driver)->LIKE_OPERATOR : QLatin1String("LIKE");
70 case ::NOT_LIKE:
71 return driver
72 ? (QString::fromLatin1("NOT ") + KDbDriverPrivate::behavior(driver)->LIKE_OPERATOR)
73 : QString::fromLatin1("NOT LIKE");
74 case ::SQL_IN: return QLatin1String("IN");
75 // other logical operations: OR (or ||) AND (or &&) XOR
76 case ::SIMILAR_TO: return QLatin1String("SIMILAR TO");
77 case ::NOT_SIMILAR_TO: return QLatin1String("NOT SIMILAR TO");
78 // other string operations: || (as CONCATENATION)
79 case ::CONCATENATION: return QLatin1String("||");
80 // SpecialBinary "pseudo operators":
81 /* not handled here */
82 default:;
83 }
84 const QString s = name();
85 if (!s.isEmpty()) {
86 return s;
87 }
88 return QString::fromLatin1("<INVALID_TOKEN#%1> ").arg(v);
89}
90
91//static
93{
94 return token.toString(driver);
95}
96
97KDB_EXPORT QDebug operator<<(QDebug dbg, KDbToken token)
98{
99 QDebugStateSaver saver(dbg);
100 dbg.nospace().noquote() << token.name();
101 return dbg.maybeSpace();
102}
103
104//! @internal
105class KDbToken::List
106{
107public:
108 List()
109 {
110 for (int i = 0; i < KDbToken::maxTokenValue; ++i) {
111 if (g_tokenName(i)) {
112 data.append(KDbToken(i));
113 }
114 }
115 }
116 QList<KDbToken> data;
117};
118
119Q_GLOBAL_STATIC(KDbToken::List, g_allTokens)
120
121//static
122QList<KDbToken> KDbToken::allTokens()
123{
124 return g_allTokens->data;
125}
126
127const KDbToken KDbToken::SQL_TYPE(::SQL_TYPE);
128const KDbToken KDbToken::AS(::AS);
129const KDbToken KDbToken::AS_EMPTY(::AS_EMPTY);
130const KDbToken KDbToken::ASC(::ASC);
131const KDbToken KDbToken::AUTO_INCREMENT(::AUTO_INCREMENT);
132const KDbToken KDbToken::BIT(::BIT);
133const KDbToken KDbToken::BITWISE_SHIFT_LEFT(::BITWISE_SHIFT_LEFT);
134const KDbToken KDbToken::BITWISE_SHIFT_RIGHT(::BITWISE_SHIFT_RIGHT);
135const KDbToken KDbToken::BY(::BY);
136const KDbToken KDbToken::CHARACTER_STRING_LITERAL(::CHARACTER_STRING_LITERAL);
137const KDbToken KDbToken::CONCATENATION(::CONCATENATION);
138const KDbToken KDbToken::CREATE(::CREATE);
139const KDbToken KDbToken::DESC(::DESC);
140const KDbToken KDbToken::DISTINCT(::DISTINCT);
141const KDbToken KDbToken::DOUBLE_QUOTED_STRING(::DOUBLE_QUOTED_STRING);
142const KDbToken KDbToken::FROM(::FROM);
143const KDbToken KDbToken::JOIN(::JOIN);
144const KDbToken KDbToken::KEY(::KEY);
145const KDbToken KDbToken::LEFT(::LEFT);
146const KDbToken KDbToken::LESS_OR_EQUAL(::LESS_OR_EQUAL);
147const KDbToken KDbToken::GREATER_OR_EQUAL(::GREATER_OR_EQUAL);
148const KDbToken KDbToken::SQL_NULL(::SQL_NULL);
149const KDbToken KDbToken::SQL_IS(::SQL_IS);
150const KDbToken KDbToken::SQL_IS_NULL(::SQL_IS_NULL);
151const KDbToken KDbToken::SQL_IS_NOT_NULL(::SQL_IS_NOT_NULL);
152const KDbToken KDbToken::ORDER(::ORDER);
153const KDbToken KDbToken::PRIMARY(::PRIMARY);
154const KDbToken KDbToken::SELECT(::SELECT);
155const KDbToken KDbToken::INTEGER_CONST(::INTEGER_CONST);
156const KDbToken KDbToken::REAL_CONST(::REAL_CONST);
157const KDbToken KDbToken::RIGHT(::RIGHT);
158const KDbToken KDbToken::SQL_ON(::SQL_ON);
159const KDbToken KDbToken::DATE_CONST(::DATE_CONST);
160const KDbToken KDbToken::DATETIME_CONST(::DATETIME_CONST);
161const KDbToken KDbToken::TIME_CONST(::TIME_CONST);
162const KDbToken KDbToken::TABLE(::TABLE);
163const KDbToken KDbToken::IDENTIFIER(::IDENTIFIER);
164const KDbToken KDbToken::IDENTIFIER_DOT_ASTERISK(::IDENTIFIER_DOT_ASTERISK);
165const KDbToken KDbToken::QUERY_PARAMETER(::QUERY_PARAMETER);
166const KDbToken KDbToken::VARCHAR(::VARCHAR);
167const KDbToken KDbToken::WHERE(::WHERE);
168const KDbToken KDbToken::SQL(::SQL);
169const KDbToken KDbToken::SQL_TRUE(::SQL_TRUE);
170const KDbToken KDbToken::SQL_FALSE(::SQL_FALSE);
171const KDbToken KDbToken::UNION(::UNION);
172const KDbToken KDbToken::SCAN_ERROR(::SCAN_ERROR);
173const KDbToken KDbToken::AND(::AND);
174const KDbToken KDbToken::BETWEEN(::BETWEEN);
175const KDbToken KDbToken::NOT_BETWEEN(::NOT_BETWEEN);
176const KDbToken KDbToken::EXCEPT(::EXCEPT);
177const KDbToken KDbToken::SQL_IN(::SQL_IN);
178const KDbToken KDbToken::INTERSECT(::INTERSECT);
179const KDbToken KDbToken::LIKE(::LIKE);
180const KDbToken KDbToken::ILIKE(::ILIKE);
181const KDbToken KDbToken::NOT_LIKE(::NOT_LIKE);
182const KDbToken KDbToken::NOT(::NOT);
183const KDbToken KDbToken::NOT_EQUAL(::NOT_EQUAL);
184const KDbToken KDbToken::NOT_EQUAL2(::NOT_EQUAL2);
185const KDbToken KDbToken::OR(::OR);
186const KDbToken KDbToken::SIMILAR_TO(::SIMILAR_TO);
187const KDbToken KDbToken::NOT_SIMILAR_TO(::NOT_SIMILAR_TO);
188const KDbToken KDbToken::XOR(::XOR);
189const KDbToken KDbToken::UMINUS(::UMINUS);
190const KDbToken KDbToken::TABS_OR_SPACES(::TABS_OR_SPACES);
191const KDbToken KDbToken::DATE_TIME_INTEGER(::DATE_TIME_INTEGER);
192const KDbToken KDbToken::TIME_AM(::TIME_AM);
193const KDbToken KDbToken::TIME_PM(::TIME_PM);
194const KDbToken KDbToken::BETWEEN_AND(0x1001);
195const KDbToken KDbToken::NOT_BETWEEN_AND(0x1002);
Database driver's abstraction.
Definition KDbDriver.h:50
A type-safe KDbSQL token It can be used in KDb expressions.
Definition KDbToken.h:37
QString toString(const KDbDriver *driver=nullptr) const
Definition KDbToken.cpp:54
static const KDbToken BETWEEN_AND
Custom tokens are not used in parser but used as an extension in expression classes.
Definition KDbToken.h:173
bool isValid() const
Definition KDbToken.h:53
char toChar() const
Definition KDbToken.h:82
KDbToken()
Creates an invalid token.
Definition KDbToken.h:42
static const int maxCharTokenValue
Maximum character token value (253)
Definition KDbToken.h:74
QString name() const
Definition KDbToken.cpp:38
static const int maxTokenValue
Maximum character token value.
Definition KDbToken.h:77
QByteArray number(double n, char format, int precision)
QDebug & maybeSpace()
QDebug & noquote()
QDebug & nospace()
void append(QList< T > &&value)
pointer data()
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:11:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.