From 5d9314f134ddd3dc4c853e398ac90ba247fb2e4f Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Mon, 13 Jun 2016 18:42:42 -0400 Subject: Imported Upstream version 3.1.0 --- .../parser/ast/sqlitecreateindex.cpp | 55 ++++++++++++--- .../parser/ast/sqlitecreateindex.h | 13 +++- .../parser/ast/sqlitecreatetable.cpp | 22 +++++- .../parser/ast/sqlitecreatetable.h | 7 +- .../parser/ast/sqlitecreatetrigger.cpp | 10 +++ .../parser/ast/sqlitecreatetrigger.h | 5 +- .../parser/ast/sqlitecreateview.cpp | 29 +++++++- .../coreSQLiteStudio/parser/ast/sqlitecreateview.h | 9 ++- .../parser/ast/sqliteddlwithdbcontext.h | 16 +++++ .../coreSQLiteStudio/parser/ast/sqliteexpr.cpp | 8 ++- .../parser/ast/sqliteextendedindexedcolumn.h | 19 +++++ .../parser/ast/sqliteindexedcolumn.cpp | 27 ++++++- .../parser/ast/sqliteindexedcolumn.h | 8 ++- .../coreSQLiteStudio/parser/ast/sqliteorderby.cpp | 82 ++++++++++++++++++++++ .../coreSQLiteStudio/parser/ast/sqliteorderby.h | 12 +++- .../parser/ast/sqlitetablerelatedddl.h | 1 + .../coreSQLiteStudio/parser/ast/sqlitevacuum.cpp | 3 + 17 files changed, 301 insertions(+), 25 deletions(-) create mode 100644 SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteddlwithdbcontext.h create mode 100644 SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteextendedindexedcolumn.h (limited to 'SQLiteStudio3/coreSQLiteStudio/parser/ast') diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateindex.cpp b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateindex.cpp index 16cec8f..fdbadf8 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateindex.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateindex.cpp @@ -14,11 +14,10 @@ SqliteCreateIndex::SqliteCreateIndex(const SqliteCreateIndex& other) : SqliteQuery(other), uniqueKw(other.uniqueKw), ifNotExistsKw(other.ifNotExistsKw), database(other.database), index(other.index), table(other.table) { - DEEP_COPY_COLLECTION(SqliteIndexedColumn, indexedColumns); + DEEP_COPY_COLLECTION(SqliteOrderBy, indexedColumns); } -SqliteCreateIndex::SqliteCreateIndex(bool unique, bool ifNotExists, const QString &name1, const QString &name2, const QString &name3, - const QList &columns, SqliteConflictAlgo onConflict) +SqliteCreateIndex::SqliteCreateIndex(bool unique, bool ifNotExists, const QString& name1, const QString& name2, const QString& name3, const QList& columns, SqliteConflictAlgo onConflict) : SqliteCreateIndex() { // Constructor for SQLite 2 @@ -36,14 +35,11 @@ SqliteCreateIndex::SqliteCreateIndex(bool unique, bool ifNotExists, const QStrin table = name2; this->onConflict = onConflict; - this->indexedColumns = columns; - - foreach (SqliteIndexedColumn* idxCol, columns) - idxCol->setParent(this); + this->indexedColumns = toOrderColumns(columns); } SqliteCreateIndex::SqliteCreateIndex(bool unique, bool ifNotExists, const QString& name1, const QString& name2, const QString& name3, - const QList& columns, SqliteExpr* where) + const QList& columns, SqliteExpr* where) : SqliteCreateIndex() { // Constructor for SQLite 3 @@ -61,7 +57,7 @@ SqliteCreateIndex::SqliteCreateIndex(bool unique, bool ifNotExists, const QStrin table = name3; this->indexedColumns = columns; - foreach (SqliteIndexedColumn* idxCol, columns) + foreach (SqliteOrderBy* idxCol, columns) idxCol->setParent(this); this->where = where; @@ -189,3 +185,44 @@ TokenList SqliteCreateIndex::rebuildTokensFromContents() return builder.build(); } + +QList SqliteCreateIndex::toOrderColumns(const QList& columns) +{ + QList result; + SqliteOrderBy* orderBy = nullptr; + SqliteExpr* expr = nullptr; + for (SqliteIndexedColumn* idxCol : columns) + { + orderBy = new SqliteOrderBy(); + orderBy->setParent(this); + orderBy->expr = new SqliteExpr(); + orderBy->expr->setParent(orderBy); + + if (!idxCol->collate.isNull()) + { + expr = new SqliteExpr(); + expr->initId(idxCol->name); + expr->setParent(orderBy->expr); + + orderBy->expr->initCollate(expr, idxCol->collate); + } + else + { + orderBy->expr->initId(idxCol->name); + } + + result << orderBy; + delete idxCol; + } + return result; +} + +QString SqliteCreateIndex::getTargetDatabase() const +{ + return database; +} + +void SqliteCreateIndex::setTargetDatabase(const QString& database) +{ + this->database = database; +} diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateindex.h b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateindex.h index 9251b18..033a663 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateindex.h +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateindex.h @@ -5,12 +5,14 @@ #include "sqlitetablerelatedddl.h" #include "sqliteconflictalgo.h" #include "sqliteexpr.h" +#include "sqliteddlwithdbcontext.h" +#include "sqliteorderby.h" #include #include class SqliteIndexedColumn; -class API_EXPORT SqliteCreateIndex : public SqliteQuery, public SqliteTableRelatedDdl +class API_EXPORT SqliteCreateIndex : public SqliteQuery, public SqliteTableRelatedDdl, public SqliteDdlWithDbContext { public: SqliteCreateIndex(); @@ -19,16 +21,18 @@ class API_EXPORT SqliteCreateIndex : public SqliteQuery, public SqliteTableRelat const QString& name3, const QList& columns, SqliteConflictAlgo onConflict = SqliteConflictAlgo::null); SqliteCreateIndex(bool unique, bool ifNotExists, const QString& name1, const QString& name2, - const QString& name3, const QList& columns, + const QString& name3, const QList& columns, SqliteExpr* where); ~SqliteCreateIndex(); SqliteStatement* clone(); QString getTargetTable() const; + QString getTargetDatabase() const; + void setTargetDatabase(const QString& database); bool uniqueKw = false; bool ifNotExistsKw = false; - QList indexedColumns; + QList indexedColumns; // The database refers to index name in Sqlite3, but in Sqlite2 it refers to the table. QString database = QString::null; QString index = QString::null; @@ -43,6 +47,9 @@ class API_EXPORT SqliteCreateIndex : public SqliteQuery, public SqliteTableRelat TokenList getDatabaseTokensInStatement(); QList getFullObjectsInStatement(); TokenList rebuildTokensFromContents(); + + private: + QList toOrderColumns(const QList& columns); }; typedef QSharedPointer SqliteCreateIndexPtr; diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetable.cpp b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetable.cpp index d21578e..2ac6c04 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetable.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetable.cpp @@ -669,13 +669,23 @@ bool SqliteCreateTable::Column::hasConstraint(SqliteCreateTable::Column::Constra SqliteCreateTable::Column::Constraint* SqliteCreateTable::Column::getConstraint(SqliteCreateTable::Column::Constraint::Type type) const { - foreach (Constraint* constr, constraints) + for (Constraint* constr : constraints) if (constr->type == type) return constr; return nullptr; } +QList SqliteCreateTable::Column::getConstraints(SqliteCreateTable::Column::Constraint::Type type) const +{ + QList list; + for (Constraint* constr : constraints) + if (constr->type == type) + list << constr; + + return list; +} + QList SqliteCreateTable::Column::getForeignKeysByTable(const QString& foreignTable) const { QList results; @@ -768,3 +778,13 @@ TokenList SqliteCreateTable::Column::Constraint::rebuildTokensFromContents() return builder.build(); } + +QString SqliteCreateTable::getTargetDatabase() const +{ + return database; +} + +void SqliteCreateTable::setTargetDatabase(const QString& database) +{ + this->database = database; +} diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetable.h b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetable.h index 877d0fa..74f4fce 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetable.h +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetable.h @@ -10,10 +10,11 @@ #include "sqlitecolumntype.h" #include "sqlitesortorder.h" #include "sqlitedeferrable.h" +#include "sqliteddlwithdbcontext.h" #include #include -class API_EXPORT SqliteCreateTable : public SqliteQuery +class API_EXPORT SqliteCreateTable : public SqliteQuery, public SqliteDdlWithDbContext { public: class API_EXPORT Column : public SqliteStatement @@ -93,6 +94,7 @@ class API_EXPORT SqliteCreateTable : public SqliteQuery bool hasConstraint(Constraint::Type type) const; Constraint* getConstraint(Constraint::Type type) const; + QList getConstraints(Constraint::Type type) const; QList getForeignKeysByTable(const QString& foreignTable) const; QString name = QString::null; @@ -181,6 +183,8 @@ class API_EXPORT SqliteCreateTable : public SqliteQuery QList getColumnForeignKeysByTable(const QString& foreignTable) const; QStringList getColumnNames() const; QHash getModifiedColumnsMap(bool lowercaseKeys = false, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const; + QString getTargetDatabase() const; + void setTargetDatabase(const QString& database); bool ifNotExistsKw = false; bool tempKw = false; @@ -202,7 +206,6 @@ class API_EXPORT SqliteCreateTable : public SqliteQuery private: void init(bool ifNotExistsKw, int temp, const QString& name1, const QString& name2); - }; typedef QSharedPointer SqliteCreateTablePtr; diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetrigger.cpp b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetrigger.cpp index 8f67aea..e15ddd6 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetrigger.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetrigger.cpp @@ -379,3 +379,13 @@ TokenList SqliteCreateTrigger::rebuildTokensFromContents() return builder.build(); } + +QString SqliteCreateTrigger::getTargetDatabase() const +{ + return database; +} + +void SqliteCreateTrigger::setTargetDatabase(const QString& database) +{ + this->database = database; +} diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetrigger.h b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetrigger.h index 2fb8ae4..2ccf876 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetrigger.h +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreatetrigger.h @@ -1,6 +1,7 @@ #ifndef SQLITECREATETRIGGER_H #define SQLITECREATETRIGGER_H +#include "sqliteddlwithdbcontext.h" #include "sqlitequery.h" #include "sqlitetablerelatedddl.h" @@ -9,7 +10,7 @@ class SqliteExpr; -class API_EXPORT SqliteCreateTrigger : public SqliteQuery, public SqliteTableRelatedDdl +class API_EXPORT SqliteCreateTrigger : public SqliteQuery, public SqliteTableRelatedDdl, public SqliteDdlWithDbContext { public: enum class Time @@ -63,6 +64,8 @@ class API_EXPORT SqliteCreateTrigger : public SqliteQuery, public SqliteTableRel SqliteStatement* clone(); QString getTargetTable() const; + QString getTargetDatabase() const; + void setTargetDatabase(const QString& database); bool tempKw = false; bool temporaryKw = false; diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateview.cpp b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateview.cpp index d1a8961..fe638db 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateview.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateview.cpp @@ -3,6 +3,7 @@ #include "sqlitequerytype.h" #include "parser/statementtokenbuilder.h" #include "common/global.h" +#include "sqliteindexedcolumn.h" SqliteCreateView::SqliteCreateView() { @@ -14,7 +15,7 @@ SqliteCreateView::SqliteCreateView(const SqliteCreateView& other) : database(other.database), view(other.view) { DEEP_COPY_FIELD(SqliteSelect, select); - + DEEP_COPY_COLLECTION(SqliteIndexedColumn, columns); } SqliteCreateView::SqliteCreateView(int temp, bool ifNotExists, const QString &name1, const QString &name2, SqliteSelect *select) : @@ -41,6 +42,15 @@ SqliteCreateView::SqliteCreateView(int temp, bool ifNotExists, const QString &na select->setParent(this); } +SqliteCreateView::SqliteCreateView(int temp, bool ifNotExists, const QString& name1, const QString& name2, SqliteSelect* select, const QList& columns) + : SqliteCreateView(temp, ifNotExists, name1, name2, select) +{ + this->columns = columns; + + for (SqliteIndexedColumn* col : columns) + col->setParent(this); +} + SqliteCreateView::~SqliteCreateView() { } @@ -112,9 +122,24 @@ TokenList SqliteCreateView::rebuildTokensFromContents() if (dialect == Dialect::Sqlite3 && !database.isNull()) builder.withOther(database, dialect).withOperator("."); - builder.withOther(view, dialect).withSpace().withKeyword("AS").withStatement(select); + builder.withOther(view, dialect).withSpace(); + + if (columns.size() > 0) + builder.withParLeft().withStatementList(columns).withParRight().withSpace(); + + builder.withKeyword("AS").withStatement(select); builder.withOperator(";"); return builder.build(); } + +QString SqliteCreateView::getTargetDatabase() const +{ + return database; +} + +void SqliteCreateView::setTargetDatabase(const QString& database) +{ + this->database = database; +} diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateview.h b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateview.h index 4858227..1f46d5e 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateview.h +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitecreateview.h @@ -1,20 +1,26 @@ #ifndef SQLITECREATEVIEW_H #define SQLITECREATEVIEW_H +#include "sqliteddlwithdbcontext.h" #include "sqlitequery.h" +#include #include class SqliteSelect; +class SqliteIndexedColumn; -class API_EXPORT SqliteCreateView : public SqliteQuery +class API_EXPORT SqliteCreateView : public SqliteQuery, public SqliteDdlWithDbContext { public: SqliteCreateView(); SqliteCreateView(const SqliteCreateView& other); SqliteCreateView(int temp, bool ifNotExists, const QString& name1, const QString& name2, SqliteSelect* select); + SqliteCreateView(int temp, bool ifNotExists, const QString& name1, const QString& name2, SqliteSelect* select, const QList& columns); ~SqliteCreateView(); SqliteStatement* clone(); + QString getTargetDatabase() const; + void setTargetDatabase(const QString& database); bool tempKw = false; bool temporaryKw = false; @@ -22,6 +28,7 @@ class API_EXPORT SqliteCreateView : public SqliteQuery QString database = QString::null; QString view = QString::null; SqliteSelect* select = nullptr; + QList columns; protected: QStringList getDatabasesInStatement(); diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteddlwithdbcontext.h b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteddlwithdbcontext.h new file mode 100644 index 0000000..cb64986 --- /dev/null +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteddlwithdbcontext.h @@ -0,0 +1,16 @@ +#ifndef SQLITEDDLWITHDBCONTEXT_H +#define SQLITEDDLWITHDBCONTEXT_H + +#include "coreSQLiteStudio_global.h" +#include + +class API_EXPORT SqliteDdlWithDbContext +{ + public: + virtual QString getTargetDatabase() const = 0; + virtual void setTargetDatabase(const QString& database) = 0; +}; + +typedef QSharedPointer SqliteDdlWithDbContextPtr; + +#endif // SQLITEDDLWITHDBCONTEXT_H diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteexpr.cpp b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteexpr.cpp index b84a818..3009b4b 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteexpr.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteexpr.cpp @@ -91,7 +91,7 @@ QString SqliteExpr::notNullOp(SqliteExpr::NotNull value) } } -SqliteStatement*SqliteExpr::clone() +SqliteStatement* SqliteExpr::clone() { return new SqliteExpr(*this); } @@ -462,7 +462,11 @@ TokenList SqliteExpr::rebuildTokensFromContents() if (distinctKw) builder.withKeyword("DISTINCT"); - builder.withStatementList(exprList).withParRight(); + if (star) + builder.withOperator("*").withParRight(); + else + builder.withStatementList(exprList).withParRight(); + break; case SqliteExpr::Mode::SUB_EXPR: builder.withParLeft().withStatement(expr1).withParRight(); diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteextendedindexedcolumn.h b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteextendedindexedcolumn.h new file mode 100644 index 0000000..1ea6119 --- /dev/null +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteextendedindexedcolumn.h @@ -0,0 +1,19 @@ +#ifndef SQLITEEXTENDEDINDEXEDCOLUMN_H +#define SQLITEEXTENDEDINDEXEDCOLUMN_H + +#include "coreSQLiteStudio_global.h" +#include + +class API_EXPORT SqliteExtendedIndexedColumn +{ + public: + virtual QString getColumnName() const = 0; + virtual void setColumnName(const QString& name) = 0; + virtual QString getCollation() const = 0; + virtual void setCollation(const QString& name) = 0; + virtual void clearCollation() = 0; +}; + +typedef QSharedPointer SqliteExtendedIndexedColumnPtr; + +#endif // SQLITEEXTENDEDINDEXEDCOLUMN_H diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteindexedcolumn.cpp b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteindexedcolumn.cpp index 5e65eab..142af06 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteindexedcolumn.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteindexedcolumn.cpp @@ -24,11 +24,26 @@ SqliteIndexedColumn::SqliteIndexedColumn(const QString& name) this->name = name; } -SqliteStatement*SqliteIndexedColumn::clone() +SqliteStatement* SqliteIndexedColumn::clone() { return new SqliteIndexedColumn(*this); } +QString SqliteIndexedColumn::getColumnName() const +{ + return name; +} + +void SqliteIndexedColumn::setColumnName(const QString& name) +{ + this->name = name; +} + +void SqliteIndexedColumn::setCollation(const QString& name) +{ + this->collate = name; +} + QStringList SqliteIndexedColumn::getColumnsInStatement() { return getStrListFromValue(name); @@ -50,3 +65,13 @@ TokenList SqliteIndexedColumn::rebuildTokensFromContents() builder.withSortOrder(sortOrder); return builder.build(); } + +QString SqliteIndexedColumn::getCollation() const +{ + return collate; +} + +void SqliteIndexedColumn::clearCollation() +{ + collate.clear(); +} diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteindexedcolumn.h b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteindexedcolumn.h index c013d17..c0fe680 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteindexedcolumn.h +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteindexedcolumn.h @@ -3,9 +3,10 @@ #include "sqlitestatement.h" #include "sqlitesortorder.h" +#include "sqliteextendedindexedcolumn.h" #include -class API_EXPORT SqliteIndexedColumn : public SqliteStatement +class API_EXPORT SqliteIndexedColumn : public SqliteStatement, public SqliteExtendedIndexedColumn { public: SqliteIndexedColumn(); @@ -14,6 +15,11 @@ class API_EXPORT SqliteIndexedColumn : public SqliteStatement explicit SqliteIndexedColumn(const QString& name); SqliteStatement* clone(); + QString getColumnName() const; + void setColumnName(const QString& name); + void setCollation(const QString& name); + QString getCollation() const; + void clearCollation(); QString name = QString::null; SqliteSortOrder sortOrder = SqliteSortOrder::null; diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteorderby.cpp b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteorderby.cpp index 3bb1b44..8eb7b46 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteorderby.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteorderby.cpp @@ -30,6 +30,76 @@ SqliteStatement*SqliteOrderBy::clone() return new SqliteOrderBy(*this); } +bool SqliteOrderBy::isSimpleColumn() const +{ + return !getColumnName().isEmpty(); +} + +QString SqliteOrderBy::getColumnName() const +{ + if (!expr) + return QString(); + + if (expr->mode == SqliteExpr::Mode::ID) + return expr->column; + + if (expr->mode == SqliteExpr::Mode::COLLATE && expr->expr1 && expr->expr1->mode == SqliteExpr::Mode::ID) + return expr->expr1->literalValue.toString(); + + return QString(); +} + +QString SqliteOrderBy::getCollation() const +{ + if (expr->mode == SqliteExpr::Mode::COLLATE) + return expr->collation; + + return QString(); +} + +QString SqliteOrderBy::getColumnString() const +{ + QString res = getColumnName(); + if (res.isNull()) + return expr->detokenize(); + + return res; +} + +void SqliteOrderBy::setColumnName(const QString& name) +{ + if (expr && expr->mode == SqliteExpr::Mode::COLLATE) + { + safe_delete(expr->expr1); + expr->expr1 = new SqliteExpr(); + expr->expr1->setParent(expr); + expr->expr1->initId(name); + } + else + { + safe_delete(expr); + expr = new SqliteExpr(); + expr->setParent(this); + expr->initId(name); + } +} + +void SqliteOrderBy::setCollation(const QString& name) +{ + if (expr && expr->mode == SqliteExpr::Mode::COLLATE) + { + expr->collation = name; + } + else + { + SqliteExpr* theExpr = expr; + SqliteExpr* collationExpr = new SqliteExpr(); + collationExpr->initCollate(theExpr, name); + theExpr->setParent(collationExpr); + collationExpr->setParent(this); + } +} + TokenList SqliteOrderBy::rebuildTokensFromContents() { StatementTokenBuilder builder; @@ -39,3 +109,15 @@ TokenList SqliteOrderBy::rebuildTokensFromContents() return builder.build(); } + + +void SqliteOrderBy::clearCollation() +{ + if (expr->mode != SqliteExpr::Mode::COLLATE) + return; + + SqliteExpr* tmpExpr = expr; + expr = tmpExpr->expr1; + expr->setParent(this); + delete tmpExpr; +} diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteorderby.h b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteorderby.h index 598423d..4f75c78 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteorderby.h +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteorderby.h @@ -3,10 +3,11 @@ #include "sqlitestatement.h" #include "sqlitesortorder.h" +#include "sqliteextendedindexedcolumn.h" class SqliteExpr; -class API_EXPORT SqliteOrderBy : public SqliteStatement +class API_EXPORT SqliteOrderBy : public SqliteStatement, public SqliteExtendedIndexedColumn { public: SqliteOrderBy(); @@ -15,9 +16,16 @@ class API_EXPORT SqliteOrderBy : public SqliteStatement ~SqliteOrderBy(); SqliteStatement* clone(); + bool isSimpleColumn() const; + QString getColumnName() const; + QString getCollation() const; + QString getColumnString() const; + void setColumnName(const QString& name); + void setCollation(const QString& name); + void clearCollation(); SqliteExpr* expr = nullptr; - SqliteSortOrder order; + SqliteSortOrder order = SqliteSortOrder::null; protected: TokenList rebuildTokensFromContents(); diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitetablerelatedddl.h b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitetablerelatedddl.h index 599849a..9de9be7 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitetablerelatedddl.h +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitetablerelatedddl.h @@ -2,6 +2,7 @@ #define SQLITETABLERELATEDDDL_H #include "coreSQLiteStudio_global.h" +#include class API_EXPORT SqliteTableRelatedDdl { diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitevacuum.cpp b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitevacuum.cpp index 96ff7a4..9d595ed 100644 --- a/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitevacuum.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitevacuum.cpp @@ -32,6 +32,9 @@ QStringList SqliteVacuum::getDatabasesInStatement() TokenList SqliteVacuum::getDatabaseTokensInStatement() { + if (!tokensMap.contains("nm")) + return TokenList(); + return getTokenListFromNamedKey("nm"); } -- cgit v1.2.3