aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2024-03-26 13:58:07 +0100
committerMarco Bubke <marco.bubke@qt.io>2024-04-09 13:40:29 +0000
commit6751fc82efefd4923990cd46a31d13e9c47326cb (patch)
treea53b46c843febf72f19ca6c0d59b09d61a11289b /src/libs
parent5a13304d728d48aa601f379b6048cfbfc8f6d565 (diff)
Sqlite: Prevent name collisions for indices
There can be unique and not unique indices with the same columns. So we add that attribute to the name to distinguish between the indices. Change-Id: I96eac1f0e95c135d625f09fd5399b16f2293d645 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/sqlite/sqliteindex.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libs/sqlite/sqliteindex.h b/src/libs/sqlite/sqliteindex.h
index f320fcd599..7c7a8dbb2b 100644
--- a/src/libs/sqlite/sqliteindex.h
+++ b/src/libs/sqlite/sqliteindex.h
@@ -40,6 +40,8 @@ public:
return Utils::SmallString::join({"CREATE ",
m_indexType == IndexType::Unique ? "UNIQUE " : "",
"INDEX IF NOT EXISTS index_",
+ kindName(),
+ "_",
m_tableName,
"_",
m_columnNames.join("_"),
@@ -65,6 +67,23 @@ public:
}
private:
+ std::string_view kindName() const
+ {
+ using namespace std::string_view_literals;
+
+ if (m_indexType == IndexType::Unique && m_condition.hasContent())
+ return "unique_partial"sv;
+
+ if (m_indexType == IndexType::Unique)
+ return "unique"sv;
+
+ if (m_condition.hasContent())
+ return "partial"sv;
+
+ return "normal"sv;
+ }
+
+private:
Utils::SmallString m_tableName;
Utils::SmallStringVector m_columnNames;
IndexType m_indexType;