diff options
| author | 2014-12-06 17:33:25 -0500 | |
|---|---|---|
| committer | 2014-12-06 17:33:25 -0500 | |
| commit | 7167ce41b61d2ba2cdb526777a4233eb84a3b66a (patch) | |
| tree | a35c14143716e1f2c98f808c81f89426045a946f /SQLiteStudio3/coreSQLiteStudio/tablemodifier.h | |
Imported Upstream version 2.99.6upstream/2.99.6
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/tablemodifier.h')
| -rw-r--r-- | SQLiteStudio3/coreSQLiteStudio/tablemodifier.h | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/tablemodifier.h b/SQLiteStudio3/coreSQLiteStudio/tablemodifier.h new file mode 100644 index 0000000..6a39b33 --- /dev/null +++ b/SQLiteStudio3/coreSQLiteStudio/tablemodifier.h @@ -0,0 +1,114 @@ +#ifndef TABLEMODIFIER_H +#define TABLEMODIFIER_H + +#include "db/db.h" +#include "parser/ast/sqlitecreatetable.h" +#include "parser/ast/sqliteupdate.h" +#include "parser/ast/sqliteinsert.h" +#include "parser/ast/sqlitedelete.h" +#include "parser/ast/sqlitecreateindex.h" +#include "parser/ast/sqlitecreatetrigger.h" +#include "parser/ast/sqlitecreateview.h" + +class API_EXPORT TableModifier +{ + public: + TableModifier(Db* db, const QString& table); + TableModifier(Db* db, const QString& database, const QString& table); + + void alterTable(SqliteCreateTablePtr newCreateTable); + + QStringList generateSqls() const; + bool isValid() const; + QStringList getErrors() const; + QStringList getWarnings() const; + QStringList getModifiedTables() const; + QStringList getModifiedIndexes() const; + QStringList getModifiedTriggers() const; + QStringList getModifiedViews() const; + bool hasMessages() const; + + private: + void init(); + void parseDdl(); + QString getTempTableName() const; + void copyDataTo(const QString& targetTable, const QStringList& srcCols, const QStringList& dstCols); + void renameTo(const QString& newName); + QString renameToTemp(); + void copyDataTo(const QString& table); + void copyDataTo(SqliteCreateTablePtr newCreateTable); + + void handleIndexes(); + void handleIndex(SqliteCreateIndexPtr index); + void handleTriggers(); + void handleTrigger(SqliteCreateTriggerPtr trigger); + void handleViews(); + void handleView(SqliteCreateViewPtr view); + SqliteQuery* handleTriggerQuery(SqliteQuery* query, const QString& trigName); + SqliteSelect* handleSelect(SqliteSelect* select); + SqliteUpdate* handleTriggerUpdate(SqliteUpdate* update, const QString& trigName); + SqliteInsert* handleTriggerInsert(SqliteInsert* insert, const QString& trigName); + SqliteDelete* handleTriggerDelete(SqliteDelete* del, const QString& trigName); + bool handleSubSelects(SqliteStatement* stmt); + bool handleExprWithSelect(SqliteExpr* expr); + void simpleHandleIndexes(); + void simpleHandleTriggers(const QString& view = QString::null); + SqliteQueryPtr parseQuery(const QString& ddl); + + /** + * @brief alterTableHandleFks + * @param newCreateTable + * Finds all tables referencing currently modified table and updates their referenced table name and columns. + */ + void handleFks(); + void subHandleFks(const QString& oldName); + bool subHandleFks(SqliteForeignKey* fk, const QString& oldName); + + bool handleName(const QString& oldName, QString& valueToUpdate); + bool handleIndexedColumns(QList<SqliteIndexedColumn*>& columnsToUpdate); + bool handleColumnNames(QStringList& columnsToUpdate); + bool handleColumnTokens(TokenList& columnsToUpdate); + bool handleUpdateColumns(SqliteUpdate* update); + + Db* db = nullptr; + Dialect dialect; + + /** + * @brief database Database name. The "main" is default. + * Other databases (temp, attached...) are not supported at the moment. + */ + QString database; + + /** + * @brief table Current table name (after renaming) + */ + QString table; + + /** + * @brief originalTable Initial table name, before any renaming. + */ + QString originalTable; + + /** + * @brief createTable Original DDL. + */ + SqliteCreateTablePtr createTable; + + /** + * @brief sqls Statements to be executed to make changes real. + */ + QStringList sqls; + + QStringList warnings; + QStringList errors; + + QString newName; + QStringList existingColumns; + QHash<QString, QString> tableColMap; + QStringList modifiedTables; + QStringList modifiedIndexes; + QStringList modifiedTriggers; + QStringList modifiedViews; +}; + +#endif // TABLEMODIFIER_H |
