aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/constraints/tableforeignkeypanel.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2025-01-16 01:58:22 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2025-01-16 01:58:22 -0500
commita5ae79be08125b31bb6b8d9703090a98c6fd2e30 (patch)
tree569ee612c9de85b2bb423efa485688ef1d43852e /SQLiteStudio3/guiSQLiteStudio/constraints/tableforeignkeypanel.cpp
parent21966b4f924b0a1933d9662e75ff253bd154fdb7 (diff)
parent81a21e6ce040e7740de86340c8ea4dba30e69bc3 (diff)
Update upstream source from tag 'upstream/3.4.13+dfsg'
Update to upstream version '3.4.13+dfsg' with Debian dir bf81ee0219cb8e4562a4751df17d75814772d2d6
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);