From 849b8cf000fa00acaf59209ebf4b00c184f5b1b4 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Mon, 1 May 2023 10:23:53 +0200 Subject: [PATCH] QmlDesigner: Improve sqlite id https://www.sqlite.org/autoinc.html says that "If no negative ROWID values are inserted explicitly, then automatically generated ROWID values will always be greater than zero." So zero is an invalid value. This changes reflect on it and makes it an invalid value too. Null is a special value in SQL and it could cast to zero by accident. To prevent that ambiguty we make zero an invalid value too. You can explicit add negative rowids but that has size overhead because positive values can be compressed. So explicit not positive values are not supported. Change-Id: I417ea9fec1573cfd9f1a98134f8adc567021988c Reviewed-by: Tim Jenssen --- src/libs/sqlite/sqliteids.h | 4 ++-- tests/unit/unittest/storagecache-test.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libs/sqlite/sqliteids.h b/src/libs/sqlite/sqliteids.h index a0562b4df44..7613a2df46f 100644 --- a/src/libs/sqlite/sqliteids.h +++ b/src/libs/sqlite/sqliteids.h @@ -63,7 +63,7 @@ public: #pragma GCC diagnostic pop #endif - constexpr bool isValid() const { return id >= 0; } + constexpr bool isValid() const { return id > 0; } explicit operator bool() const { return isValid(); } @@ -74,7 +74,7 @@ public: [[noreturn, deprecated]] InternalIntegerType operator&() const { throw std::exception{}; } private: - InternalIntegerType id = -1; + InternalIntegerType id = 0; }; template diff --git a/tests/unit/unittest/storagecache-test.cpp b/tests/unit/unittest/storagecache-test.cpp index 3e3763dae4b..543b4dc5787 100644 --- a/tests/unit/unittest/storagecache-test.cpp +++ b/tests/unit/unittest/storagecache-test.cpp @@ -90,11 +90,11 @@ protected: Utils::PathString filePath5{"/file/pathFife"}; Utils::PathStringVector filePaths{filePath1, filePath2, filePath3, filePath4, filePath5}; Utils::PathStringVector reverseFilePaths{filePath1, filePath2, filePath3, filePath4, filePath5}; - SourceContextId id1{SourceContextId::create(0)}; - SourceContextId id2{SourceContextId::create(1)}; - SourceContextId id3{SourceContextId::create(2)}; - SourceContextId id4{SourceContextId::create(3)}; - SourceContextId id5{SourceContextId::create(4)}; + SourceContextId id1{SourceContextId::create(1)}; + SourceContextId id2{SourceContextId::create(2)}; + SourceContextId id3{SourceContextId::create(3)}; + SourceContextId id4{SourceContextId::create(4)}; + SourceContextId id5{SourceContextId::create(5)}; SourceContextId id41{SourceContextId::create(41)}; SourceContextId id42{SourceContextId::create(42)}; SourceContextId id43{SourceContextId::create(43)};