Files
qt-creator/src/libs/sqlite/sqliteindex.h
Marco Bubke cc507063bc Sqlite: Inject RTTI into TU
We had problems on macOS with the catching of exceptions because the has
type_info::hash_code was different. This is probably a bug because RTTI
code is injected for an inline class.

To work around that problem we implemented the virtual what method for
every exception.

Task-number: QDS-9266
Change-Id: I79052c8b70adead412d1940b17195151fb19ebb9
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
2023-02-28 09:48:30 +00:00

77 lines
2.0 KiB
C++

// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#pragma once
#include "sqliteglobal.h"
#include "sqliteexception.h"
#include <utils/smallstringvector.h>
namespace Sqlite {
enum class IndexType
{
Normal,
Unique
};
class Index
{
public:
Index(Utils::SmallStringView tableName,
Utils::SmallStringVector &&columnNames,
IndexType indexType = IndexType::Normal,
Utils::SmallStringView condition = {})
: m_tableName(std::move(tableName))
, m_columnNames(std::move(columnNames))
, m_indexType(indexType)
, m_condition{condition}
{}
Utils::SmallString sqlStatement() const
{
checkTableName();
checkColumns();
return Utils::SmallString::join({"CREATE ",
m_indexType == IndexType::Unique ? "UNIQUE " : "",
"INDEX IF NOT EXISTS index_",
m_tableName,
"_",
m_columnNames.join("_"),
" ON ",
m_tableName,
"(",
m_columnNames.join(", "),
")",
m_condition.hasContent() ? " WHERE " : "",
m_condition});
}
void checkTableName() const
{
if (m_tableName.isEmpty())
throw IndexHasNoTableName();
}
void checkColumns() const
{
if (m_columnNames.empty())
throw IndexHasNoColumns();
}
private:
Utils::SmallString m_tableName;
Utils::SmallStringVector m_columnNames;
IndexType m_indexType;
Utils::SmallString m_condition;
};
using SqliteIndices = std::vector<Index>;
} //