Clang: Add Symbol Indexing

It is a first step and now a database is generated if you start QtCreator.
Some code is now shared with the PchManager which can be improved in the
future.

Change-Id: Ic267fe7960f6c455d91832859a673ce98f269aa2
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2017-08-17 12:44:52 +02:00
parent 8488ce627b
commit 3adb71d45e
65 changed files with 1195 additions and 175 deletions

View File

@@ -43,7 +43,8 @@ HEADERS += \
$$PWD/utf8stringvector.h \
$$PWD/sqlitedatabase.h \
$$PWD/sqlitetable.h \
$$PWD/sqlitecolumn.h
$$PWD/sqlitecolumn.h \
$$PWD/sqliteindex.h
DEFINES += SQLITE_THREADSAFE=2 SQLITE_ENABLE_FTS4 SQLITE_ENABLE_FTS3_PARENTHESIS SQLITE_ENABLE_UNLOCK_NOTIFY SQLITE_ENABLE_COLUMN_METADATA

View File

@@ -29,6 +29,8 @@
#include <utils/smallstring.h>
#include <functional>
namespace Sqlite {
class SqliteColumn
@@ -108,5 +110,7 @@ private:
};
using SqliteColumns = std::vector<SqliteColumn>;
using SqliteColumnConstReference = std::reference_wrapper<const SqliteColumn>;
using SqliteColumnConstReferences = std::vector<SqliteColumnConstReference>;
} // namespace Sqlite

View File

@@ -0,0 +1,82 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "sqliteglobal.h"
#include "sqliteexception.h"
#include <utils/smallstringvector.h>
namespace Sqlite {
class SqliteIndex
{
public:
SqliteIndex(Utils::SmallString &&tableName, Utils::SmallStringVector &&columnNames)
: m_tableName(std::move(tableName)),
m_columnNames(std::move(columnNames))
{
}
Utils::SmallString sqlStatement() const
{
checkTableName();
checkColumns();
return {"CREATE INDEX IF NOT EXISTS index_",
m_tableName,
"_",
m_columnNames.join("_"),
" ON ",
m_tableName,
"(",
m_columnNames.join(", "),
")"
};
}
void checkTableName() const
{
if (m_tableName.isEmpty())
throw SqliteException("SqliteIndex has not table name!");
}
void checkColumns() const
{
if (m_columnNames.empty())
throw SqliteException("SqliteIndex has no columns!");
}
private:
Utils::SmallString m_tableName;
Utils::SmallStringVector m_columnNames;
};
using SqliteIndices = std::vector<SqliteIndex>;
} //

View File

@@ -28,6 +28,7 @@
#include "createtablesqlstatementbuilder.h"
#include "sqliteglobal.h"
#include "sqlitecolumn.h"
#include "sqliteindex.h"
#include "sqliteexception.h"
namespace Sqlite {
@@ -37,6 +38,12 @@ class SqliteDatabase;
class SqliteTable
{
public:
SqliteTable(std::size_t reserve = 10)
{
m_sqliteColumns.reserve(reserve);
m_sqliteIndices.reserve(reserve);
}
void setName(Utils::SmallString &&name)
{
m_tableName = std::move(name);
@@ -76,6 +83,13 @@ public:
return m_sqliteColumns.back();
}
SqliteIndex &addIndex(const SqliteColumnConstReferences &columns)
{
m_sqliteIndices.emplace_back(m_tableName.clone(), sqliteColumnNames(columns));
return m_sqliteIndices.back();
}
const SqliteColumns &columns() const
{
return m_sqliteColumns;
@@ -89,22 +103,25 @@ public:
template <typename Database>
void initialize(Database &database)
{
try {
CreateTableSqlStatementBuilder builder;
CreateTableSqlStatementBuilder builder;
builder.setTableName(m_tableName.clone());
builder.setUseWithoutRowId(m_withoutRowId);
builder.setUseIfNotExists(m_useIfNotExists);
builder.setUseTemporaryTable(m_useTemporaryTable);
builder.setColumns(m_sqliteColumns);
builder.setTableName(m_tableName.clone());
builder.setUseWithoutRowId(m_withoutRowId);
builder.setUseIfNotExists(m_useIfNotExists);
builder.setUseTemporaryTable(m_useTemporaryTable);
builder.setColumns(m_sqliteColumns);
database.execute(builder.sqlStatement());
database.execute(builder.sqlStatement());
m_isReady = true;
initializeIndices(database);
} catch (const SqliteException &exception) {
exception.printWarning();
}
m_isReady = true;
}
template <typename Database>
void initializeIndices(Database &database)
{
for (const SqliteIndex &index : m_sqliteIndices)
database.execute(index.sqlStatement());
}
friend bool operator==(const SqliteTable &first, const SqliteTable &second)
@@ -116,9 +133,21 @@ public:
&& first.m_sqliteColumns == second.m_sqliteColumns;
}
private:
Utils::SmallStringVector sqliteColumnNames(const SqliteColumnConstReferences &columns)
{
Utils::SmallStringVector columnNames;
for (const SqliteColumn &column : columns)
columnNames.push_back(column.name());
return columnNames;
}
private:
Utils::SmallString m_tableName;
SqliteColumns m_sqliteColumns;
SqliteIndices m_sqliteIndices;
bool m_withoutRowId = false;
bool m_useIfNotExists = false;
bool m_useTemporaryTable = false;

View File

@@ -36,7 +36,7 @@ template <typename Database>
class SqliteAbstractTransaction
{
public:
virtual ~SqliteAbstractTransaction()
~SqliteAbstractTransaction()
{
if (!m_isAlreadyCommited)
m_database.execute("ROLLBACK");
@@ -68,7 +68,6 @@ public:
{
database.execute("BEGIN");
}
};
template <typename Database>
@@ -80,7 +79,6 @@ public:
{
database.execute("BEGIN IMMEDIATE");
}
};
template <typename Database>
@@ -92,7 +90,6 @@ public:
{
database.execute("BEGIN EXCLUSIVE");
}
};
} // namespace Sqlite