aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/selectresolver.h
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2023-04-30 18:30:36 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2023-04-30 18:30:36 -0400
commit3565aad630864ecdbe53fdaa501ea708555b3c7c (patch)
treec743e4ad0bad39ebdb2f514c7cc52d34a257ebbe /SQLiteStudio3/coreSQLiteStudio/selectresolver.h
parent1fdc150116cad39aae5c5da407c3312b47a59e3a (diff)
New upstream version 3.4.4+dfsg.upstream/3.4.4+dfsg
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/selectresolver.h')
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/selectresolver.h58
1 files changed, 43 insertions, 15 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/selectresolver.h b/SQLiteStudio3/coreSQLiteStudio/selectresolver.h
index cb93d65..a77ffe1 100644
--- a/SQLiteStudio3/coreSQLiteStudio/selectresolver.h
+++ b/SQLiteStudio3/coreSQLiteStudio/selectresolver.h
@@ -1,9 +1,9 @@
#ifndef SELECTRESOLVER_H
#define SELECTRESOLVER_H
+#include "common/strhash.h"
#include "parser/ast/sqliteselect.h"
#include "common/bistrhash.h"
-#include "expectedtoken.h"
#include "parser/ast/sqlitewith.h"
#include <QString>
#include <QHash>
@@ -63,7 +63,8 @@ class API_EXPORT SelectResolver
FROM_ANONYMOUS_SELECT = 0x02,
FROM_DISTINCT_SELECT = 0x04,
FROM_GROUPED_SELECT = 0x08,
- FROM_CTE_SELECT = 0x10
+ FROM_CTE_SELECT = 0x10,
+ FROM_VIEW = 0x20
};
/**
@@ -71,9 +72,6 @@ class API_EXPORT SelectResolver
*/
struct API_EXPORT Table
{
- Table();
- Table(const Table& other);
-
/**
* @brief Database name.
*
@@ -112,7 +110,6 @@ class API_EXPORT SelectResolver
QString alias;
QString displayName;
bool aliasDefinedInSubQuery = false;
- SqliteSelect::Core::ResultColumn* originalColumn = nullptr;
int operator==(const Column& other);
Table getTable() const;
@@ -123,16 +120,18 @@ class API_EXPORT SelectResolver
~SelectResolver();
QList<Column> resolveColumnsFromFirstCore();
- QList<QList<Column> > resolveColumns();
+ QList<QList<Column>> resolveColumns();
QList<Column> resolve(SqliteSelect::Core* selectCore);
- QList<QList<Column> > resolve(SqliteSelect* select);
+ QList<QList<Column>> resolve(SqliteSelect* select);
QList<Column> resolveAvailableColumns(SqliteSelect::Core* selectCore);
- QList<QList<Column> > resolveAvailableColumns(SqliteSelect* select);
+ QList<QList<Column>> resolveAvailableColumns(SqliteSelect* select);
+ QList<Column> resolveAvailableColumns(SqliteSelect::Core::JoinSource* joinSrc);
QSet<Table> resolveTables(SqliteSelect::Core* selectCore);
- QList<QSet<Table> > resolveTables(SqliteSelect* select);
+ QList<QSet<Table>> resolveTables(SqliteSelect* select);
+ QSet<Table> resolveTables(SqliteSelect::Core::JoinSource* joinSrc);
/**
* @brief Translates tokens representing column name in the SELECT into full column objects.
@@ -180,6 +179,30 @@ class API_EXPORT SelectResolver
const QStringList& getErrors() const;
/**
+ * @brief This is a convenient overload of method that uses database object passed to the constructor.
+ * @param query SQL query to analyze.
+ * @return Column with limited metadata (database, table name - if applicable, column name - if applicable, and displayName)
+ *
+ * See static overloaded method for more details.
+ */
+ QList<Column> sqliteResolveColumns(const QString& query);
+
+ /**
+ * @brief Does quick analysis of result columns for the query, using SQLite built-in API.
+ * @param db Database to analyze the query against.
+ * @param query SQL query to analyze.
+ * @param dbNameToAttach A mapping of database name to its attach name, used to resolve db name if SQLite API returns it as attach name.
+ * @return Column with limited metadata (database, table name - if applicable, column name - if applicable, and displayName)
+ *
+ * Instead of doing full scale anaysis of the query, it leverages SQLite API for a query metadata,
+ * but it lacks information about source table aliases, subquery aliases,
+ * flags (compund query, aggregate query, cte query, etc).
+ * It's convenient, but must be complemented by sophisticated logic of the SchemaResolver to provide full info.
+ * Yet it's good enough if these extended information are not needed, as it can be much faster, than full analysis.
+ */
+ static QList<Column> sqliteResolveColumns(Db* db, const QString& query, const BiStrHash& dbNameToAttach = BiStrHash());
+
+ /**
* @brief resolveMultiCore
* If true (by default), the multi-core subselects will be resolved using
* first core from the list. If false, then the subselect will be ignored by resolver,
@@ -197,6 +220,8 @@ class API_EXPORT SelectResolver
private:
QList<Column> resolveCore(SqliteSelect::Core* selectCore);
QList<Column> resolveAvailableCoreColumns(SqliteSelect::Core* selectCore);
+ QSet<Table> resolveTablesFromCore(SqliteSelect::Core* selectCore);
+ void markFlagsBySelect(SqliteSelect::Core* core, QList<Column>& columns);
Column translateTokenToColumn(SqliteSelect* select, TokenPtr token);
void resolve(SqliteSelect::Core::ResultColumn* resCol);
void resolveStar(SqliteSelect::Core::ResultColumn* resCol);
@@ -214,16 +239,16 @@ class API_EXPORT SelectResolver
QList<Column> resolveSingleSourceSubSelect(SqliteSelect::Core::SingleSource* joinSrc);
QList<Column> resolveOtherSource(SqliteSelect::Core::JoinSourceOther *otherSrc);
QList<Column> resolveSubSelect(SqliteSelect* select);
- QList<Column> resolveView(const QString& database, const QString& name, const QString &alias);
+ QList<Column> resolveView(SqliteSelect::Core::SingleSource *joinSrc);
bool isView(const QString& database, const QString& name);
QStringList getTableColumns(const QString& database, const QString& table, const QString &alias);
void applySubSelectAlias(QList<Column>& columns, const QString& alias);
QString resolveDatabase(const QString& database);
bool parseOriginalQuery();
- void markDistinctColumns();
- void markCompoundColumns();
- void markGroupedColumns();
+ void markDistinctColumns(QList<Column>* columnList = nullptr);
+ void markCompoundColumns(QList<Column>* columnList = nullptr);
+ void markGroupedColumns(QList<Column>* columnList = nullptr);
void fixColumnNames();
void markCurrentColumnsWithFlag(Flag flag, QList<Column>* columnList = nullptr);
bool matchTable(const Column& sourceColumn, const QString& table);
@@ -234,7 +259,7 @@ class API_EXPORT SelectResolver
Db* db = nullptr;
QString query;
SqliteSelectPtr originalQueryParsed;
- QHash<QString, SqliteWith::CommonTableExpression*> cteList;
+ StrHash<SqliteWith::CommonTableExpression*> cteList;
/**
* @brief Database name to attach name map.
@@ -307,4 +332,7 @@ API_EXPORT uint qHash(const SelectResolver::Table& table);
API_EXPORT int operator==(const SelectResolver::Column& c1, const SelectResolver::Column& c2);
API_EXPORT uint qHash(const SelectResolver::Column& column);
+API_EXPORT QDebug operator<<(QDebug debug, const SelectResolver::Column &c);
+API_EXPORT QDebug operator<<(QDebug debug, const SelectResolver::Table &c);
+
#endif // SELECTRESOLVER_H