forked from qt-creator/qt-creator
Sqlite: Move result count to class declaration
It move the magic number of column results to the sql statement and improves the mock a little bit. Change-Id: I101067444cf27ec5dea0c72de7fd484a7e8710f0 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -27,51 +27,54 @@
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
template<typename Database,
|
||||
typename ReadStatement>
|
||||
template<typename Database>
|
||||
class QuerySqliteStatementFactory
|
||||
{
|
||||
public:
|
||||
using DatabaseType = Database;
|
||||
using ReadStatementType = ReadStatement;
|
||||
template<int ResultCount>
|
||||
using ReadStatement = typename Database::template ReadStatement<ResultCount>;
|
||||
|
||||
QuerySqliteStatementFactory(Database &database)
|
||||
: database(database)
|
||||
{}
|
||||
Database &database;
|
||||
ReadStatement selectLocationsForSymbolLocation{
|
||||
ReadStatement<3> selectLocationsForSymbolLocation{
|
||||
"SELECT sourceId, line, column FROM locations WHERE symbolId = "
|
||||
" (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND column=?) "
|
||||
"ORDER BY sourceId, line, column",
|
||||
database};
|
||||
ReadStatement selectSourceUsagesForSymbolLocation{
|
||||
ReadStatement<3> selectSourceUsagesForSymbolLocation{
|
||||
"SELECT directoryPath || '/' || sourceName, line, column "
|
||||
"FROM locations NATURAL JOIN sources NATURAL JOIN directories "
|
||||
"WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND "
|
||||
"column=?)",
|
||||
database};
|
||||
ReadStatement selectSourceUsagesOrderedForSymbolLocation{
|
||||
ReadStatement<3> selectSourceUsagesOrderedForSymbolLocation{
|
||||
"SELECT directoryPath || '/' || sourceName, line, column "
|
||||
"FROM locations NATURAL JOIN sources NATURAL JOIN directories "
|
||||
"WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND "
|
||||
"column=?) ORDER BY locationKind LIMIT 2",
|
||||
database};
|
||||
ReadStatement selectSourceUsagesByLocationKindForSymbolLocation{
|
||||
ReadStatement<3> selectSourceUsagesByLocationKindForSymbolLocation{
|
||||
"SELECT directoryPath || '/' || sourceName, line, column "
|
||||
"FROM locations NATURAL JOIN sources NATURAL JOIN directories "
|
||||
"WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND "
|
||||
"column=?) AND locationKind = ?",
|
||||
database};
|
||||
ReadStatement selectSymbolsForKindAndStartsWith{
|
||||
"SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind = ? AND symbolName LIKE ?",
|
||||
ReadStatement<3> selectSymbolsForKindAndStartsWith{
|
||||
"SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind = ? AND symbolName "
|
||||
"LIKE ?",
|
||||
database};
|
||||
ReadStatement selectSymbolsForKindAndStartsWith2{
|
||||
"SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?) AND symbolName LIKE ?",
|
||||
ReadStatement<3> selectSymbolsForKindAndStartsWith2{
|
||||
"SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?) AND "
|
||||
"symbolName LIKE ?",
|
||||
database};
|
||||
ReadStatement selectSymbolsForKindAndStartsWith3{
|
||||
"SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?,?) AND symbolName LIKE ?",
|
||||
ReadStatement<3> selectSymbolsForKindAndStartsWith3{
|
||||
"SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?,?) AND "
|
||||
"symbolName LIKE ?",
|
||||
database};
|
||||
ReadStatement selectLocationOfSymbol{
|
||||
ReadStatement<3> selectLocationOfSymbol{
|
||||
"SELECT sourceId, line, column FROM locations AS l WHERE symbolId = ? AND locationKind = ?",
|
||||
database};
|
||||
};
|
||||
|
||||
@@ -40,8 +40,6 @@ namespace ClangRefactoring {
|
||||
template <typename StatementFactory>
|
||||
class SymbolQuery final : public SymbolQueryInterface
|
||||
{
|
||||
using ReadStatement = typename StatementFactory::ReadStatementType;
|
||||
|
||||
public:
|
||||
SymbolQuery(StatementFactory &statementFactory)
|
||||
: m_statementFactory(statementFactory)
|
||||
@@ -51,28 +49,28 @@ public:
|
||||
int line,
|
||||
int utf8Column) const override
|
||||
{
|
||||
ReadStatement &locationsStatement = m_statementFactory.selectLocationsForSymbolLocation;
|
||||
auto &locationsStatement = m_statementFactory.selectLocationsForSymbolLocation;
|
||||
|
||||
const std::size_t reserveSize = 128;
|
||||
|
||||
return locationsStatement.template values<SourceLocation, 3>(reserveSize,
|
||||
filePathId.filePathId,
|
||||
line,
|
||||
utf8Column);
|
||||
return locationsStatement.template values<SourceLocation>(reserveSize,
|
||||
filePathId.filePathId,
|
||||
line,
|
||||
utf8Column);
|
||||
}
|
||||
|
||||
CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId,
|
||||
int line,
|
||||
int utf8Column) const override
|
||||
{
|
||||
ReadStatement &locationsStatement = m_statementFactory.selectSourceUsagesForSymbolLocation;
|
||||
auto &locationsStatement = m_statementFactory.selectSourceUsagesForSymbolLocation;
|
||||
|
||||
const std::size_t reserveSize = 128;
|
||||
|
||||
return locationsStatement.template values<CppTools::Usage, 3>(reserveSize,
|
||||
filePathId.filePathId,
|
||||
line,
|
||||
utf8Column);
|
||||
return locationsStatement.template values<CppTools::Usage>(reserveSize,
|
||||
filePathId.filePathId,
|
||||
line,
|
||||
utf8Column);
|
||||
}
|
||||
|
||||
CppTools::Usages sourceUsagesAtByLocationKind(ClangBackEnd::FilePathId filePathId,
|
||||
@@ -80,46 +78,46 @@ public:
|
||||
int utf8Column,
|
||||
ClangBackEnd::SourceLocationKind kind) const override
|
||||
{
|
||||
ReadStatement &locationsStatement = m_statementFactory.selectSourceUsagesByLocationKindForSymbolLocation;
|
||||
auto &locationsStatement = m_statementFactory.selectSourceUsagesByLocationKindForSymbolLocation;
|
||||
|
||||
const std::size_t reserveSize = 128;
|
||||
|
||||
return locationsStatement.template values<CppTools::Usage, 3>(reserveSize,
|
||||
filePathId.filePathId,
|
||||
line,
|
||||
utf8Column,
|
||||
int(kind));
|
||||
return locationsStatement.template values<CppTools::Usage>(reserveSize,
|
||||
filePathId.filePathId,
|
||||
line,
|
||||
utf8Column,
|
||||
int(kind));
|
||||
}
|
||||
|
||||
CppTools::Usages declarationsAt(ClangBackEnd::FilePathId filePathId,
|
||||
int line,
|
||||
int utf8Column) const override
|
||||
{
|
||||
ReadStatement &locationsStatement = m_statementFactory.selectSourceUsagesOrderedForSymbolLocation;
|
||||
auto &locationsStatement = m_statementFactory.selectSourceUsagesOrderedForSymbolLocation;
|
||||
|
||||
const std::size_t reserveSize = 128;
|
||||
|
||||
return locationsStatement.template values<CppTools::Usage, 3>(reserveSize,
|
||||
filePathId.filePathId,
|
||||
line,
|
||||
utf8Column);
|
||||
return locationsStatement.template values<CppTools::Usage>(reserveSize,
|
||||
filePathId.filePathId,
|
||||
line,
|
||||
utf8Column);
|
||||
}
|
||||
|
||||
Symbols symbolsWithOneSymbolKinds(ClangBackEnd::SymbolKind symbolKind,
|
||||
Utils::SmallStringView searchTerm) const
|
||||
{
|
||||
ReadStatement &statement = m_statementFactory.selectSymbolsForKindAndStartsWith;
|
||||
auto &statement = m_statementFactory.selectSymbolsForKindAndStartsWith;
|
||||
|
||||
return statement.template values<Symbol, 3>(100, int(symbolKind), searchTerm);
|
||||
return statement.template values<Symbol>(100, int(symbolKind), searchTerm);
|
||||
}
|
||||
|
||||
Symbols symbolsWithTwoSymbolKinds(ClangBackEnd::SymbolKind symbolKind1,
|
||||
ClangBackEnd::SymbolKind symbolKind2,
|
||||
Utils::SmallStringView searchTerm) const
|
||||
{
|
||||
ReadStatement &statement = m_statementFactory.selectSymbolsForKindAndStartsWith2;
|
||||
auto &statement = m_statementFactory.selectSymbolsForKindAndStartsWith2;
|
||||
|
||||
return statement.template values<Symbol, 3>(100, int(symbolKind1), int(symbolKind2), searchTerm);
|
||||
return statement.template values<Symbol>(100, int(symbolKind1), int(symbolKind2), searchTerm);
|
||||
}
|
||||
|
||||
Symbols symbolsWithThreeSymbolKinds(ClangBackEnd::SymbolKind symbolKind1,
|
||||
@@ -127,9 +125,13 @@ public:
|
||||
ClangBackEnd::SymbolKind symbolKind3,
|
||||
Utils::SmallStringView searchTerm) const
|
||||
{
|
||||
ReadStatement &statement = m_statementFactory.selectSymbolsForKindAndStartsWith3;
|
||||
auto &statement = m_statementFactory.selectSymbolsForKindAndStartsWith3;
|
||||
|
||||
return statement.template values<Symbol, 3>(100, int(symbolKind1), int(symbolKind2), int(symbolKind3), searchTerm);
|
||||
return statement.template values<Symbol>(100,
|
||||
int(symbolKind1),
|
||||
int(symbolKind2),
|
||||
int(symbolKind3),
|
||||
searchTerm);
|
||||
}
|
||||
|
||||
Symbols symbols(const ClangBackEnd::SymbolKinds &symbolKinds,
|
||||
@@ -148,9 +150,9 @@ public:
|
||||
Utils::optional<SourceLocation> locationForSymbolId(SymbolId symbolId,
|
||||
ClangBackEnd::SourceLocationKind kind) const override
|
||||
{
|
||||
ReadStatement &statement = m_statementFactory.selectLocationOfSymbol;
|
||||
auto &statement = m_statementFactory.selectLocationOfSymbol;
|
||||
|
||||
return statement.template value<SourceLocation, 3>(symbolId, int(kind));
|
||||
return statement.template value<SourceLocation>(symbolId, int(kind));
|
||||
}
|
||||
private:
|
||||
StatementFactory &m_statementFactory;
|
||||
|
||||
@@ -43,7 +43,8 @@ template<typename DatabaseType>
|
||||
class ImageCacheStorage : public ImageCacheStorageInterface
|
||||
{
|
||||
public:
|
||||
using ReadStatement = typename DatabaseType::ReadStatement;
|
||||
template<int ResultCount>
|
||||
using ReadStatement = typename DatabaseType::template ReadStatement<ResultCount>;
|
||||
using WriteStatement = typename DatabaseType::WriteStatement;
|
||||
|
||||
ImageCacheStorage(DatabaseType &database)
|
||||
@@ -272,11 +273,11 @@ public:
|
||||
DatabaseType &database;
|
||||
Initializer initializer{database};
|
||||
Sqlite::ImmediateNonThrowingDestructorTransaction transaction{database};
|
||||
mutable ReadStatement selectImageStatement{
|
||||
mutable ReadStatement<1> selectImageStatement{
|
||||
"SELECT image FROM images WHERE name=?1 AND mtime >= ?2", database};
|
||||
mutable ReadStatement selectSmallImageStatement{
|
||||
mutable ReadStatement<1> selectSmallImageStatement{
|
||||
"SELECT smallImage FROM images WHERE name=?1 AND mtime >= ?2", database};
|
||||
mutable ReadStatement selectIconStatement{
|
||||
mutable ReadStatement<1> selectIconStatement{
|
||||
"SELECT icon FROM icons WHERE name=?1 AND mtime >= ?2", database};
|
||||
WriteStatement upsertImageStatement{
|
||||
"INSERT INTO images(name, mtime, image, smallImage) VALUES (?1, ?2, ?3, ?4) ON "
|
||||
|
||||
Reference in New Issue
Block a user