aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/tablemodifier.h
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2016-06-13 18:42:57 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2016-06-13 18:42:57 -0400
commit65d5f68cc6dc81799c5a5d90400a2c1f0dd02547 (patch)
tree6f245ba901b87ef42fed69965aea22f5eea6b590 /SQLiteStudio3/coreSQLiteStudio/tablemodifier.h
parentaeb6bad01630d325a4e768e798a7a6d44e18fdaf (diff)
parent5d9314f134ddd3dc4c853e398ac90ba247fb2e4f (diff)
Merge tag 'upstream/3.1.0'
Upstream version 3.1.0 # gpg: Signature made Mon 13 Jun 2016 06:42:54 PM EDT using RSA key ID EBE9BD91 # gpg: Good signature from "Unit 193 <unit193@gmail.com>" # gpg: aka "Unit 193 <unit193@ninthfloor.org>" # gpg: aka "Unit 193 <unit193@ubuntu.com>" # gpg: aka "Unit 193 <unit193@ninthfloor.com>"
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