File indexing completed on 2024-12-08 12:44:47
0001 /**************************************************************************** 0002 * Created by generate_parser_code.sh 0003 * WARNING! All changes made in this file will be lost! 0004 ****************************************************************************/ 0005 /* This file is part of the KDE project 0006 Copyright (C) 2015-2018 Jarosław Staniek <staniek@kde.org> 0007 0008 This library is free software; you can redistribute it and/or 0009 modify it under the terms of the GNU Library General Public 0010 License as published by the Free Software Foundation; either 0011 version 2 of the License, or (at your option) any later version. 0012 0013 This library is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 Library General Public License for more details. 0017 0018 You should have received a copy of the GNU Library General Public License 0019 along with this library; see the file COPYING.LIB. If not, write to 0020 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 * Boston, MA 02110-1301, USA. 0022 */ 0023 0024 #include "KDbToken.h" 0025 #include "KDbDriver.h" 0026 #include "KDbDriver_p.h" 0027 #include "KDbDriverBehavior.h" 0028 #include "sqlparser.h" 0029 #include "parser/KDbParser_p.h" 0030 0031 #include <QGlobalStatic> 0032 0033 KDbToken::KDbToken(char charToken) 0034 : v(g_tokenName(charToken) == nullptr ? 0 : charToken) 0035 { 0036 } 0037 0038 QString KDbToken::name() const 0039 { 0040 if (!isValid()) { 0041 return QLatin1String("<INVALID_TOKEN>"); 0042 } 0043 if (v > maxCharTokenValue) { 0044 return QLatin1String(g_tokenName(v)); 0045 } 0046 if (isprint(v)) { 0047 return QString(QLatin1Char(char(v))); 0048 } 0049 else { 0050 return QLatin1String(QByteArray::number(v)); 0051 } 0052 } 0053 0054 QString KDbToken::toString(const KDbDriver *driver) const 0055 { 0056 if (toChar() > 0) { 0057 return name(); 0058 } 0059 // other arithmetic operations: << >> 0060 // NOTE: only include cases that have toString() != name() or are dependent on driver 0061 switch (v) { 0062 case ::BITWISE_SHIFT_RIGHT: return QLatin1String(">>"); 0063 case ::BITWISE_SHIFT_LEFT: return QLatin1String("<<"); 0064 // other relational operations: <= >= <> (or !=) LIKE IN 0065 case ::NOT_EQUAL: return QLatin1String("<>"); 0066 case ::NOT_EQUAL2: return QLatin1String("!="); 0067 case ::LESS_OR_EQUAL: return QLatin1String("<="); 0068 case ::GREATER_OR_EQUAL: return QLatin1String(">="); 0069 case ::LIKE: return driver ? KDbDriverPrivate::behavior(driver)->LIKE_OPERATOR : QLatin1String("LIKE"); 0070 case ::NOT_LIKE: 0071 return driver 0072 ? (QString::fromLatin1("NOT ") + KDbDriverPrivate::behavior(driver)->LIKE_OPERATOR) 0073 : QString::fromLatin1("NOT LIKE"); 0074 case ::SQL_IN: return QLatin1String("IN"); 0075 // other logical operations: OR (or ||) AND (or &&) XOR 0076 case ::SIMILAR_TO: return QLatin1String("SIMILAR TO"); 0077 case ::NOT_SIMILAR_TO: return QLatin1String("NOT SIMILAR TO"); 0078 // other string operations: || (as CONCATENATION) 0079 case ::CONCATENATION: return QLatin1String("||"); 0080 // SpecialBinary "pseudo operators": 0081 /* not handled here */ 0082 default:; 0083 } 0084 const QString s = name(); 0085 if (!s.isEmpty()) { 0086 return s; 0087 } 0088 return QString::fromLatin1("<INVALID_TOKEN#%1> ").arg(v); 0089 } 0090 0091 //static 0092 QString KDbToken::toString(KDbToken token, const KDbDriver *driver) 0093 { 0094 return token.toString(driver); 0095 } 0096 0097 KDB_EXPORT QDebug operator<<(QDebug dbg, KDbToken token) 0098 { 0099 QDebugStateSaver saver(dbg); 0100 dbg.nospace().noquote() << token.name(); 0101 return dbg.maybeSpace(); 0102 } 0103 0104 //! @internal 0105 class KDbToken::List 0106 { 0107 public: 0108 List() 0109 { 0110 for (int i = 0; i < KDbToken::maxTokenValue; ++i) { 0111 if (g_tokenName(i)) { 0112 data.append(KDbToken(i)); 0113 } 0114 } 0115 } 0116 QList<KDbToken> data; 0117 }; 0118 0119 Q_GLOBAL_STATIC(KDbToken::List, g_allTokens) 0120 0121 //static 0122 QList<KDbToken> KDbToken::allTokens() 0123 { 0124 return g_allTokens->data; 0125 } 0126 0127 const KDbToken KDbToken::SQL_TYPE(::SQL_TYPE); 0128 const KDbToken KDbToken::AS(::AS); 0129 const KDbToken KDbToken::AS_EMPTY(::AS_EMPTY); 0130 const KDbToken KDbToken::ASC(::ASC); 0131 const KDbToken KDbToken::AUTO_INCREMENT(::AUTO_INCREMENT); 0132 const KDbToken KDbToken::BIT(::BIT); 0133 const KDbToken KDbToken::BITWISE_SHIFT_LEFT(::BITWISE_SHIFT_LEFT); 0134 const KDbToken KDbToken::BITWISE_SHIFT_RIGHT(::BITWISE_SHIFT_RIGHT); 0135 const KDbToken KDbToken::BY(::BY); 0136 const KDbToken KDbToken::CHARACTER_STRING_LITERAL(::CHARACTER_STRING_LITERAL); 0137 const KDbToken KDbToken::CONCATENATION(::CONCATENATION); 0138 const KDbToken KDbToken::CREATE(::CREATE); 0139 const KDbToken KDbToken::DESC(::DESC); 0140 const KDbToken KDbToken::DISTINCT(::DISTINCT); 0141 const KDbToken KDbToken::DOUBLE_QUOTED_STRING(::DOUBLE_QUOTED_STRING); 0142 const KDbToken KDbToken::FROM(::FROM); 0143 const KDbToken KDbToken::JOIN(::JOIN); 0144 const KDbToken KDbToken::KEY(::KEY); 0145 const KDbToken KDbToken::LEFT(::LEFT); 0146 const KDbToken KDbToken::LESS_OR_EQUAL(::LESS_OR_EQUAL); 0147 const KDbToken KDbToken::GREATER_OR_EQUAL(::GREATER_OR_EQUAL); 0148 const KDbToken KDbToken::SQL_NULL(::SQL_NULL); 0149 const KDbToken KDbToken::SQL_IS(::SQL_IS); 0150 const KDbToken KDbToken::SQL_IS_NULL(::SQL_IS_NULL); 0151 const KDbToken KDbToken::SQL_IS_NOT_NULL(::SQL_IS_NOT_NULL); 0152 const KDbToken KDbToken::ORDER(::ORDER); 0153 const KDbToken KDbToken::PRIMARY(::PRIMARY); 0154 const KDbToken KDbToken::SELECT(::SELECT); 0155 const KDbToken KDbToken::INTEGER_CONST(::INTEGER_CONST); 0156 const KDbToken KDbToken::REAL_CONST(::REAL_CONST); 0157 const KDbToken KDbToken::RIGHT(::RIGHT); 0158 const KDbToken KDbToken::SQL_ON(::SQL_ON); 0159 const KDbToken KDbToken::DATE_CONST(::DATE_CONST); 0160 const KDbToken KDbToken::DATETIME_CONST(::DATETIME_CONST); 0161 const KDbToken KDbToken::TIME_CONST(::TIME_CONST); 0162 const KDbToken KDbToken::TABLE(::TABLE); 0163 const KDbToken KDbToken::IDENTIFIER(::IDENTIFIER); 0164 const KDbToken KDbToken::IDENTIFIER_DOT_ASTERISK(::IDENTIFIER_DOT_ASTERISK); 0165 const KDbToken KDbToken::QUERY_PARAMETER(::QUERY_PARAMETER); 0166 const KDbToken KDbToken::VARCHAR(::VARCHAR); 0167 const KDbToken KDbToken::WHERE(::WHERE); 0168 const KDbToken KDbToken::SQL(::SQL); 0169 const KDbToken KDbToken::SQL_TRUE(::SQL_TRUE); 0170 const KDbToken KDbToken::SQL_FALSE(::SQL_FALSE); 0171 const KDbToken KDbToken::UNION(::UNION); 0172 const KDbToken KDbToken::SCAN_ERROR(::SCAN_ERROR); 0173 const KDbToken KDbToken::AND(::AND); 0174 const KDbToken KDbToken::BETWEEN(::BETWEEN); 0175 const KDbToken KDbToken::NOT_BETWEEN(::NOT_BETWEEN); 0176 const KDbToken KDbToken::EXCEPT(::EXCEPT); 0177 const KDbToken KDbToken::SQL_IN(::SQL_IN); 0178 const KDbToken KDbToken::INTERSECT(::INTERSECT); 0179 const KDbToken KDbToken::LIKE(::LIKE); 0180 const KDbToken KDbToken::ILIKE(::ILIKE); 0181 const KDbToken KDbToken::NOT_LIKE(::NOT_LIKE); 0182 const KDbToken KDbToken::NOT(::NOT); 0183 const KDbToken KDbToken::NOT_EQUAL(::NOT_EQUAL); 0184 const KDbToken KDbToken::NOT_EQUAL2(::NOT_EQUAL2); 0185 const KDbToken KDbToken::OR(::OR); 0186 const KDbToken KDbToken::SIMILAR_TO(::SIMILAR_TO); 0187 const KDbToken KDbToken::NOT_SIMILAR_TO(::NOT_SIMILAR_TO); 0188 const KDbToken KDbToken::XOR(::XOR); 0189 const KDbToken KDbToken::UMINUS(::UMINUS); 0190 const KDbToken KDbToken::TABS_OR_SPACES(::TABS_OR_SPACES); 0191 const KDbToken KDbToken::DATE_TIME_INTEGER(::DATE_TIME_INTEGER); 0192 const KDbToken KDbToken::TIME_AM(::TIME_AM); 0193 const KDbToken KDbToken::TIME_PM(::TIME_PM); 0194 const KDbToken KDbToken::BETWEEN_AND(0x1001); 0195 const KDbToken KDbToken::NOT_BETWEEN_AND(0x1002);