summaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/constraints/tableforeignkeypanel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/constraints/tableforeignkeypanel.cpp')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/constraints/tableforeignkeypanel.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/constraints/tableforeignkeypanel.cpp b/SQLiteStudio3/guiSQLiteStudio/constraints/tableforeignkeypanel.cpp
index cecf5f4..5e85915 100644
--- a/SQLiteStudio3/guiSQLiteStudio/constraints/tableforeignkeypanel.cpp
+++ b/SQLiteStudio3/guiSQLiteStudio/constraints/tableforeignkeypanel.cpp
@@ -53,6 +53,8 @@ bool TableForeignKeyPanel::validate()
setValidState(combo, idxOk, tr("Pick the foreign column."));
if (!idxOk)
columnsSelected = false;
+ else
+ handleFkTypeMatched(combo, check->property(UI_PROP_COLUMN).toString(), combo->currentText());
break;
}
@@ -386,6 +388,36 @@ void TableForeignKeyPanel::storeMatchCondition(const QString& reaction)
constr->foreignKey->conditions << condition;
}
+void TableForeignKeyPanel::handleFkTypeMatched(QWidget* indicatorParent, const QString &localColumn, const QString fkColumn)
+{
+ SqliteCreateTable::Column* column = createTableStmt->getColumn(localColumn);
+ if (!column || !column->type)
+ return;
+
+ QString localType = column->type->toDataType().toString();
+
+ // FK column type
+ QString fkTable = ui->fkTableCombo->currentText();
+ if (!fkTableTypesCache.contains(fkTable, Qt::CaseInsensitive))
+ {
+ SchemaResolver resolver(db);
+ fkTableTypesCache[fkTable] = resolver.getTableColumnDataTypesByName(fkTable);
+ }
+
+ StrHash<DataType> fkTypes = fkTableTypesCache.value(fkTable, Qt::CaseInsensitive);
+ if (!fkTypes.contains(fkColumn, Qt::CaseInsensitive))
+ return;
+
+ QString fkType = fkTypes.value(fkColumn, Qt::CaseInsensitive).toString();
+
+ if (localType.toLower().trimmed() != fkType.toLower().trimmed())
+ {
+ setValidStateWarning(indicatorParent,
+ tr("Referenced column type (%1) is different than type declared for local column (%2). It may cause issues while inserting or updating data.")
+ .arg(fkType, localType));
+ }
+}
+
void TableForeignKeyPanel::readTables()
{
SchemaResolver resolver(db);