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 --- SQLiteStudio3/coreSQLiteStudio/tablemodifier.h | 50 +++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) (limited to 'SQLiteStudio3/coreSQLiteStudio/tablemodifier.h') diff --git a/SQLiteStudio3/coreSQLiteStudio/tablemodifier.h b/SQLiteStudio3/coreSQLiteStudio/tablemodifier.h index 675202d..cba27ed 100644 --- a/SQLiteStudio3/coreSQLiteStudio/tablemodifier.h +++ b/SQLiteStudio3/coreSQLiteStudio/tablemodifier.h @@ -59,6 +59,7 @@ class API_EXPORT TableModifier bool handleAllExprWithTrigTable(SqliteStatement* stmt, const QString& contextTable); bool handleExprListWithTrigTable(const QList& exprList); bool handleExprWithTrigTable(SqliteExpr* expr); + bool handleExpr(SqliteExpr* expr); void simpleHandleIndexes(); void simpleHandleTriggers(const QString& view = QString::null); SqliteQueryPtr parseQuery(const QString& ddl); @@ -68,16 +69,55 @@ class API_EXPORT TableModifier * @param newCreateTable * Finds all tables referencing currently modified table and updates their referenced table name and columns. */ - void handleFks(const QString& tempTableName); - void subHandleFks(const QString& oldName, const QString& oldTempName); - bool subHandleFks(SqliteForeignKey* fk, const QString& oldName, const QString& oldTempName); + void handleFks(); + void handleFks(const QString& oldName, const QString& theNewName); + bool handleFks(SqliteForeignKey* fk, const QString& oldName, const QString& theNewName); + bool handleFkConstrains(SqliteCreateTable* stmt, const QString& oldName, const QString& theNewName); bool handleName(const QString& oldName, QString& valueToUpdate); - bool handleIndexedColumns(QList& columnsToUpdate); + static bool handleName(const QString& oldName, const QString& theNewName, QString& valueToUpdate); + bool handleIndexedColumns(const QList& columnsToUpdate); + bool handleIndexedColumnsInitial(SqliteOrderBy* col, bool& modified); + bool handleIndexedColumnsInitial(SqliteIndexedColumn* col, bool& modified); bool handleColumnNames(QStringList& columnsToUpdate); bool handleColumnTokens(TokenList& columnsToUpdate); bool handleUpdateColumns(SqliteUpdate* update); + + template + bool handleIndexedColumns(QList& columnsToUpdate) + { + bool modified = false; + QString lowerName; + QString colName; + QMutableListIterator it(columnsToUpdate); + while (it.hasNext()) + { + T* idxCol = it.next(); + if (handleIndexedColumnsInitial(idxCol, modified)) + continue; + + colName = idxCol->getColumnName(); + + // If column was modified, assign new name + lowerName = colName.toLower(); + if (tableColMap.contains(lowerName)) + { + idxCol->setColumnName(tableColMap[lowerName]); + modified = true; + continue; + } + + // It wasn't modified, but it's not on existing columns list? Remove it. + if (indexOf(existingColumns, colName, Qt::CaseInsensitive) == -1) + { + it.remove(); + modified = true; + } + } + return modified; + } + Db* db = nullptr; Dialect dialect; @@ -114,6 +154,7 @@ class API_EXPORT TableModifier QStringList existingColumns; QHash tableColMap; QHash triggerNameToDdlMap; + QStringList tablesHandledForFk; QStringList modifiedTables; QStringList modifiedIndexes; QStringList modifiedTriggers; @@ -121,4 +162,5 @@ class API_EXPORT TableModifier QStringList usedTempTableNames; }; + #endif // TABLEMODIFIER_H -- cgit v1.2.3