From d4ef90e6328b0e6cb46d682f61035623e7e7fceb Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 29 Mar 2018 18:40:35 +0200 Subject: [PATCH] Clang: Filter duplicate locations An unique index is prevent double locations in the database. Change-Id: I167cafe1a707dd8a8a9754b8d69790a8382f4eea Reviewed-by: Ivan Donchevskii --- .../source/storagesqlitestatementfactory.h | 8 ++++---- .../unittest/storagesqlitestatementfactory-test.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h b/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h index 7c63b0478f1..56548f0b315 100644 --- a/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h +++ b/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h @@ -69,10 +69,10 @@ public: table.setUseTemporaryTable(true); table.addColumn("temporarySymbolId", Sqlite::ColumnType::Integer); table.addColumn("symbolId", Sqlite::ColumnType::Integer); - table.addColumn("line", Sqlite::ColumnType::Integer); - table.addColumn("column", Sqlite::ColumnType::Integer); const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); - table.addIndex({sourceIdColumn}); + const Sqlite::Column &lineColumn = table.addColumn("line", Sqlite::ColumnType::Integer); + const Sqlite::Column &columnColumn = table.addColumn("column", Sqlite::ColumnType::Integer); + table.addUniqueIndex({sourceIdColumn, lineColumn, columnColumn}); table.initialize(database); @@ -118,7 +118,7 @@ public: "INSERT INTO newSymbols(temporarySymbolId, usr, symbolName) VALUES(?,?,?)", database}; WriteStatement insertLocationsToNewLocationsStatement{ - "INSERT INTO newLocations(temporarySymbolId, line, column, sourceId) VALUES(?,?,?,?)", + "INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId) VALUES(?,?,?,?)", database }; ReadStatement selectNewSourceIdsStatement{ diff --git a/tests/unit/unittest/storagesqlitestatementfactory-test.cpp b/tests/unit/unittest/storagesqlitestatementfactory-test.cpp index 63876bbb368..922a229d47b 100644 --- a/tests/unit/unittest/storagesqlitestatementfactory-test.cpp +++ b/tests/unit/unittest/storagesqlitestatementfactory-test.cpp @@ -59,8 +59,8 @@ TEST_F(StorageSqliteStatementFactory, AddNewLocationsTable) { InSequence s; - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, line INTEGER, column INTEGER, sourceId INTEGER)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newLocations_sourceId ON newLocations(sourceId)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, sourceId INTEGER, line INTEGER, column INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_newLocations_sourceId_line_column ON newLocations(sourceId, line, column)"))); factory.createNewLocationsTable(); } @@ -93,8 +93,8 @@ TEST_F(StorageSqliteStatementFactory, AddTablesInConstructor) EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newSymbols(temporarySymbolId INTEGER PRIMARY KEY, symbolId INTEGER, usr TEXT, symbolName TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_usr_symbolName ON newSymbols(usr, symbolName)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_symbolId ON newSymbols(symbolId)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, line INTEGER, column INTEGER, sourceId INTEGER)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newLocations_sourceId ON newLocations(sourceId)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, sourceId INTEGER, line INTEGER, column INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_newLocations_sourceId_line_column ON newLocations(sourceId, line, column)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newUsedMacros(sourceId INTEGER, macroName TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newUsedMacros_sourceId_macroName ON newUsedMacros(sourceId, macroName)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newSourceDependencies(sourceId INTEGER, dependencySourceId TEXT)"))); @@ -113,7 +113,7 @@ TEST_F(StorageSqliteStatementFactory, InsertNewSymbolsStatement) TEST_F(StorageSqliteStatementFactory, InsertNewLocationsToLocations) { ASSERT_THAT(factory.insertLocationsToNewLocationsStatement.sqlStatement, - Eq("INSERT INTO newLocations(temporarySymbolId, line, column, sourceId) VALUES(?,?,?,?)")); + Eq("INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId) VALUES(?,?,?,?)")); } TEST_F(StorageSqliteStatementFactory, SelectNewSourceIdsStatement)