Changeset View
Changeset View
Standalone View
Standalone View
src/parser/KDbParser_p.cpp
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project | ||
---|---|---|---|---|---|
2 | Copyright (C) 2004-2016 Jarosław Staniek <staniek@kde.org> | 2 | Copyright (C) 2004-2017 Jarosław Staniek <staniek@kde.org> | ||
3 | 3 | | |||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. | ||
8 | 8 | | |||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | 12 | Library General Public License for more details. | ||
13 | 13 | | |||
14 | You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | * Boston, MA 02110-1301, USA. | 17 | * Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "KDbParser_p.h" | 20 | #include "KDbParser_p.h" | ||
21 | #include "KDb.h" | 21 | #include "KDb.h" | ||
22 | #include "KDbConnection.h" | 22 | #include "KDbConnection.h" | ||
23 | #include "KDbTableSchema.h" | 23 | #include "KDbTableSchema.h" | ||
24 | #include "KDbQuerySchema.h" | 24 | #include "KDbQuerySchema.h" | ||
25 | #include "KDbQuerySchema_p.h" | ||||
25 | #include "kdb_debug.h" | 26 | #include "kdb_debug.h" | ||
26 | #include "generated/sqlparser.h" | 27 | #include "generated/sqlparser.h" | ||
27 | 28 | | |||
28 | #include <QMutableListIterator> | 29 | #include <QMutableListIterator> | ||
29 | 30 | | |||
30 | #include <assert.h> | 31 | #include <assert.h> | ||
31 | 32 | | |||
32 | KDbParser *globalParser = 0; | 33 | KDbParser *globalParser = 0; | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
93 | 94 | | |||
94 | KDbParseInfo::~KDbParseInfo() | 95 | KDbParseInfo::~KDbParseInfo() | ||
95 | { | 96 | { | ||
96 | delete d; | 97 | delete d; | ||
97 | } | 98 | } | ||
98 | 99 | | |||
99 | QList<int> KDbParseInfo::tablesAndAliasesForName(const QString &tableOrAliasName) const | 100 | QList<int> KDbParseInfo::tablesAndAliasesForName(const QString &tableOrAliasName) const | ||
100 | { | 101 | { | ||
102 | QList<int> result; | ||||
101 | const QList<int> *list = d->repeatedTablesAndAliases.value(tableOrAliasName); | 103 | const QList<int> *list = d->repeatedTablesAndAliases.value(tableOrAliasName); | ||
102 | return list ? *list : QList<int>(); | 104 | if (list) { | ||
105 | result = *list; | ||||
106 | } | ||||
107 | if (result.isEmpty()) { | ||||
108 | int position = d->querySchema->tablePositionForAlias(tableOrAliasName); | ||||
109 | if (position == -1) { | ||||
110 | position = d->querySchema->tablePosition(tableOrAliasName); | ||||
111 | if (position != -1) { | ||||
112 | result.append(position); | ||||
113 | } | ||||
114 | } else { | ||||
115 | result.append(position); | ||||
116 | } | ||||
117 | } | ||||
118 | return result; | ||||
103 | } | 119 | } | ||
104 | 120 | | |||
105 | KDbQuerySchema* KDbParseInfo::querySchema() const | 121 | KDbQuerySchema* KDbParseInfo::querySchema() const | ||
106 | { | 122 | { | ||
107 | return d->querySchema; | 123 | return d->querySchema; | ||
108 | } | 124 | } | ||
109 | 125 | | |||
110 | QString KDbParseInfo::errorMessage() const | 126 | QString KDbParseInfo::errorMessage() const | ||
▲ Show 20 Lines • Show All 349 Lines • ▼ Show 20 Line(s) | 467 | // << columnNum; | |||
460 | //----- SELECT options | 476 | //----- SELECT options | ||
461 | if (options) { | 477 | if (options) { | ||
462 | //----- WHERE expr. | 478 | //----- WHERE expr. | ||
463 | if (!options->whereExpr.isNull()) { | 479 | if (!options->whereExpr.isNull()) { | ||
464 | if (!options->whereExpr.validate(&parseInfo)) { | 480 | if (!options->whereExpr.validate(&parseInfo)) { | ||
465 | setError(parseInfo.errorMessage(), parseInfo.errorDescription()); | 481 | setError(parseInfo.errorMessage(), parseInfo.errorDescription()); | ||
466 | return 0; | 482 | return 0; | ||
467 | } | 483 | } | ||
468 | querySchema->setWhereExpression(options->whereExpr); | 484 | KDbQuerySchema::Private::setWhereExpressionInternal(querySchema, options->whereExpr); | ||
469 | } | 485 | } | ||
470 | //----- ORDER BY | 486 | //----- ORDER BY | ||
471 | if (options->orderByColumns) { | 487 | if (options->orderByColumns) { | ||
472 | KDbOrderByColumnList *orderByColumnList = querySchema->orderByColumnList(); | 488 | KDbOrderByColumnList *orderByColumnList = querySchema->orderByColumnList(); | ||
473 | int count = options->orderByColumns->count(); | 489 | int count = options->orderByColumns->count(); | ||
474 | QList<OrderByColumnInternal>::ConstIterator it(options->orderByColumns->constEnd()); | 490 | QList<OrderByColumnInternal>::ConstIterator it(options->orderByColumns->constEnd()); | ||
475 | --it; | 491 | --it; | ||
476 | for (;count > 0; --it, --count) | 492 | for (;count > 0; --it, --count) | ||
Show All 34 Lines |