summaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/tablemodifier.h
diff options
context:
space:
mode:
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/tablemodifier.h')
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/tablemodifier.h50
1 files changed, 46 insertions, 4 deletions
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<SqliteExpr*>& 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<SqliteIndexedColumn*>& columnsToUpdate);
+ static bool handleName(const QString& oldName, const QString& theNewName, QString& valueToUpdate);
+ bool handleIndexedColumns(const QList<SqliteOrderBy*>& 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 <class T>
+ bool handleIndexedColumns(QList<T*>& columnsToUpdate)
+ {
+ bool modified = false;
+ QString lowerName;
+ QString colName;
+ QMutableListIterator<T*> 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<QString, QString> tableColMap;
QHash<QString, QString> triggerNameToDdlMap;
+ QStringList tablesHandledForFk;
QStringList modifiedTables;
QStringList modifiedIndexes;
QStringList modifiedTriggers;
@@ -121,4 +162,5 @@ class API_EXPORT TableModifier
QStringList usedTempTableNames;
};
+
#endif // TABLEMODIFIER_H