Commit 382c9647 authored by Marco Bubke's avatar Marco Bubke Committed by Tim Jenssen

Sqlite: Remove the Sqlite Prefix

We use a name space now, so the prefix is not of much use.

Change-Id: I2b077576f94dab778add6ab2e54870f7ca18da78
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent d2aaa266
......@@ -101,7 +101,7 @@ void CreateTableSqlStatementBuilder::bindColumnDefinitions() const
{
Utils::SmallStringVector columnDefinitionStrings;
for (const SqliteColumn &columns : m_columns) {
for (const Column &columns : m_columns) {
Utils::SmallString columnDefinitionString = {columns.name(), " ", columns.typeString()};
switch (columns.constraint()) {
......
......@@ -33,14 +33,14 @@
namespace Sqlite {
class SqliteColumn
class Column
{
public:
SqliteColumn() = default;
Column() = default;
SqliteColumn(Utils::SmallString &&name,
ColumnType type = ColumnType::Numeric,
Contraint constraint = Contraint::NoConstraint)
Column(Utils::SmallString &&name,
ColumnType type = ColumnType::Numeric,
Contraint constraint = Contraint::NoConstraint)
: m_name(std::move(name)),
m_type(type),
m_constraint(constraint)
......@@ -96,7 +96,7 @@ public:
Q_UNREACHABLE();
}
friend bool operator==(const SqliteColumn &first, const SqliteColumn &second)
friend bool operator==(const Column &first, const Column &second)
{
return first.m_name == second.m_name
&& first.m_type == second.m_type
......@@ -109,8 +109,8 @@ private:
Contraint m_constraint = Contraint::NoConstraint;
};
using SqliteColumns = std::vector<SqliteColumn>;
using SqliteColumnConstReference = std::reference_wrapper<const SqliteColumn>;
using SqliteColumns = std::vector<Column>;
using SqliteColumnConstReference = std::reference_wrapper<const Column>;
using SqliteColumnConstReferences = std::vector<SqliteColumnConstReference>;
} // namespace Sqlite
......@@ -30,18 +30,18 @@
namespace Sqlite {
SqliteDatabase::SqliteDatabase()
Database::Database()
: m_databaseBackend(*this)
{
}
SqliteDatabase::SqliteDatabase(Utils::PathString &&databaseFilePath)
Database::Database(Utils::PathString &&databaseFilePath)
: m_databaseBackend(*this)
{
open(std::move(databaseFilePath));
}
void SqliteDatabase::open()
void Database::open()
{
m_databaseBackend.open(m_databaseFilePath, m_openMode);
m_databaseBackend.setJournalMode(m_journalMode);
......@@ -49,91 +49,91 @@ void SqliteDatabase::open()
m_isOpen = true;
}
void SqliteDatabase::open(Utils::PathString &&databaseFilePath)
void Database::open(Utils::PathString &&databaseFilePath)
{
setDatabaseFilePath(std::move(databaseFilePath));
open();
}
void SqliteDatabase::close()
void Database::close()
{
m_isOpen = false;
m_databaseBackend.close();
}
bool SqliteDatabase::isOpen() const
bool Database::isOpen() const
{
return m_isOpen;
}
SqliteTable &SqliteDatabase::addTable()
Table &Database::addTable()
{
m_sqliteTables.emplace_back();
return m_sqliteTables.back();
}
const std::vector<SqliteTable> &SqliteDatabase::tables() const
const std::vector<Table> &Database::tables() const
{
return m_sqliteTables;
}
void SqliteDatabase::setDatabaseFilePath(Utils::PathString &&databaseFilePath)
void Database::setDatabaseFilePath(Utils::PathString &&databaseFilePath)
{
m_databaseFilePath = std::move(databaseFilePath);
}
const Utils::PathString &SqliteDatabase::databaseFilePath() const
const Utils::PathString &Database::databaseFilePath() const
{
return m_databaseFilePath;
}
void SqliteDatabase::setJournalMode(JournalMode journalMode)
void Database::setJournalMode(JournalMode journalMode)
{
m_journalMode = journalMode;
}
JournalMode SqliteDatabase::journalMode() const
JournalMode Database::journalMode() const
{
return m_journalMode;
}
void SqliteDatabase::setOpenMode(OpenMode openMode)
void Database::setOpenMode(OpenMode openMode)
{
m_openMode = openMode;
}
OpenMode SqliteDatabase::openMode() const
OpenMode Database::openMode() const
{
return m_openMode;
}
int SqliteDatabase::changesCount()
int Database::changesCount()
{
return m_databaseBackend.changesCount();
}
int SqliteDatabase::totalChangesCount()
int Database::totalChangesCount()
{
return m_databaseBackend.totalChangesCount();
}
void SqliteDatabase::execute(Utils::SmallStringView sqlStatement)
void Database::execute(Utils::SmallStringView sqlStatement)
{
m_databaseBackend.execute(sqlStatement);
}
void SqliteDatabase::initializeTables()
void Database::initializeTables()
{
SqliteImmediateTransaction<SqliteDatabase> transaction(*this);
ImmediateTransaction<Database> transaction(*this);
for (SqliteTable &table : m_sqliteTables)
for (Table &table : m_sqliteTables)
table.initialize(*this);
transaction.commit();
}
SqliteDatabaseBackend &SqliteDatabase::backend()
DatabaseBackend &Database::backend()
{
return m_databaseBackend;
}
......
......@@ -35,7 +35,7 @@
namespace Sqlite {
class SQLITE_EXPORT SqliteDatabase
class SQLITE_EXPORT Database
{
template <typename Database>
friend class SqliteAbstractTransaction;
......@@ -43,14 +43,14 @@ class SQLITE_EXPORT SqliteDatabase
friend class SqliteBackend;
public:
SqliteDatabase();
SqliteDatabase(Utils::PathString &&databaseFilePath);
Database();
Database(Utils::PathString &&databaseFilePath);
SqliteDatabase(const SqliteDatabase &) = delete;
bool operator=(const SqliteDatabase &) = delete;
Database(const Database &) = delete;
bool operator=(const Database &) = delete;
SqliteDatabase(SqliteDatabase &&) = delete;
bool operator=(SqliteDatabase &&) = delete;
Database(Database &&) = delete;
bool operator=(Database &&) = delete;
void open();
void open(Utils::PathString &&databaseFilePath);
......@@ -58,8 +58,8 @@ public:
bool isOpen() const;
SqliteTable &addTable();
const std::vector<SqliteTable> &tables() const;
Table &addTable();
const std::vector<Table> &tables() const;
void setDatabaseFilePath(Utils::PathString &&databaseFilePath);
const Utils::PathString &databaseFilePath() const;
......@@ -75,15 +75,15 @@ public:
void execute(Utils::SmallStringView sqlStatement);
SqliteDatabaseBackend &backend();
DatabaseBackend &backend();
private:
void initializeTables();
private:
SqliteDatabaseBackend m_databaseBackend;
std::vector<SqliteTable> m_sqliteTables;
DatabaseBackend m_databaseBackend;
std::vector<Table> m_sqliteTables;
Utils::PathString m_databaseFilePath;
JournalMode m_journalMode = JournalMode::Wal;
OpenMode m_openMode = OpenMode::ReadWrite;
......
This diff is collapsed.
......@@ -33,19 +33,19 @@ struct sqlite3;
namespace Sqlite {
class SqliteDatabase;
class Database;
class SQLITE_EXPORT SqliteDatabaseBackend
class SQLITE_EXPORT DatabaseBackend
{
public:
SqliteDatabaseBackend(SqliteDatabase &database);
~SqliteDatabaseBackend();
DatabaseBackend(Database &database);
~DatabaseBackend();
SqliteDatabaseBackend(const SqliteDatabase &) = delete;
SqliteDatabase &operator=(const SqliteDatabase &) = delete;
DatabaseBackend(const Database &) = delete;
Database &operator=(const Database &) = delete;
SqliteDatabaseBackend(SqliteDatabase &&) = delete;
SqliteDatabase &operator=(SqliteDatabase &&) = delete;
DatabaseBackend(Database &&) = delete;
Database &operator=(Database &&) = delete;
void setMmapSize(qint64 defaultSize, qint64 maximumSize);
void activateMultiThreading();
......@@ -114,7 +114,7 @@ protected:
private:
SqliteDatabase &m_database;
Database &m_database;
sqlite3 *m_databaseHandle;
TextEncoding m_cachedTextEncoding;
......
......@@ -31,7 +31,7 @@
namespace Sqlite {
void SqliteException::printWarning() const
void Exception::printWarning() const
{
if (!m_sqliteErrorMessage.isEmpty())
qWarning() << m_whatErrorHasHappen << m_sqliteErrorMessage;
......
......@@ -31,11 +31,11 @@
namespace Sqlite {
class SQLITE_EXPORT SqliteException
class SQLITE_EXPORT Exception
{
public:
SqliteException(const char *whatErrorHasHappen,
Utils::SmallString &&sqliteErrorMessage = Utils::SmallString())
Exception(const char *whatErrorHasHappen,
Utils::SmallString &&sqliteErrorMessage = Utils::SmallString())
: m_whatErrorHasHappen(whatErrorHasHappen),
m_sqliteErrorMessage(std::move(sqliteErrorMessage))
{
......
......@@ -34,10 +34,10 @@
namespace Sqlite {
class SqliteIndex
class Index
{
public:
SqliteIndex(Utils::SmallString &&tableName, Utils::SmallStringVector &&columnNames)
Index(Utils::SmallString &&tableName, Utils::SmallStringVector &&columnNames)
: m_tableName(std::move(tableName)),
m_columnNames(std::move(columnNames))
{
......@@ -63,13 +63,13 @@ public:
void checkTableName() const
{
if (m_tableName.isEmpty())
throw SqliteException("SqliteIndex has not table name!");
throw Exception("SqliteIndex has not table name!");
}
void checkColumns() const
{
if (m_columnNames.empty())
throw SqliteException("SqliteIndex has no columns!");
throw Exception("SqliteIndex has no columns!");
}
private:
......@@ -77,6 +77,6 @@ private:
Utils::SmallStringVector m_columnNames;
};
using SqliteIndices = std::vector<SqliteIndex>;
using SqliteIndices = std::vector<Index>;
} //
......@@ -29,14 +29,14 @@
namespace Sqlite {
SqliteReadStatement::SqliteReadStatement(Utils::SmallStringView sqlStatement,
SqliteDatabase &database)
: SqliteStatement(sqlStatement, database)
ReadStatement::ReadStatement(Utils::SmallStringView sqlStatement,
Database &database)
: Statement(sqlStatement, database)
{
checkIsReadOnlyStatement();
}
void SqliteReadStatement::checkIsReadOnlyStatement()
void ReadStatement::checkIsReadOnlyStatement()
{
if (!isReadOnlyStatement())
throwException("SqliteStatement::SqliteReadStatement: is not read only statement!");
......
......@@ -29,28 +29,28 @@
namespace Sqlite {
class SQLITE_EXPORT SqliteReadStatement final : private SqliteStatement
class SQLITE_EXPORT ReadStatement final : private Statement
{
public:
explicit SqliteReadStatement(Utils::SmallStringView sqlStatement, SqliteDatabase &database);
explicit ReadStatement(Utils::SmallStringView sqlStatement, Database &database);
using SqliteStatement::next;
using SqliteStatement::reset;
using SqliteStatement::value;
using SqliteStatement::structValues;
using SqliteStatement::tupleValues;
using SqliteStatement::text;
using SqliteStatement::values;
using SqliteStatement::columnCount;
using SqliteStatement::columnNames;
using SqliteStatement::bind;
using SqliteStatement::bindValues;
using SqliteStatement::bindNameValues;
using SqliteStatement::bindingIndexForName;
using SqliteStatement::setBindingColumnNames;
using SqliteStatement::bindingColumnNames;
using SqliteStatement::toValue;
using SqliteStatement::database;
using Statement::next;
using Statement::reset;
using Statement::value;
using Statement::structValues;
using Statement::tupleValues;
using Statement::text;
using Statement::values;
using Statement::columnCount;
using Statement::columnNames;
using Statement::bind;
using Statement::bindValues;
using Statement::bindNameValues;
using Statement::bindingIndexForName;
using Statement::setBindingColumnNames;
using Statement::bindingColumnNames;
using Statement::toValue;
using Statement::database;
protected:
void checkIsReadOnlyStatement();
......
......@@ -27,9 +27,9 @@
namespace Sqlite {
SqliteReadWriteStatement::SqliteReadWriteStatement(Utils::SmallStringView sqlStatement,
SqliteDatabase &database)
: SqliteStatement(sqlStatement, database)
ReadWriteStatement::ReadWriteStatement(Utils::SmallStringView sqlStatement,
Database &database)
: Statement(sqlStatement, database)
{
}
......
......@@ -29,33 +29,33 @@
namespace Sqlite {
class SQLITE_EXPORT SqliteReadWriteStatement final : private SqliteStatement
class SQLITE_EXPORT ReadWriteStatement final : private Statement
{
friend class SqliteDatabaseBackend;
friend class DatabaseBackend;
public:
SqliteReadWriteStatement(Utils::SmallStringView sqlStatement, SqliteDatabase &database);
ReadWriteStatement(Utils::SmallStringView sqlStatement, Database &database);
using SqliteStatement::next;
using SqliteStatement::execute;
using SqliteStatement::reset;
using SqliteStatement::bind;
using SqliteStatement::bindValues;
using SqliteStatement::bindNameValues;
using SqliteStatement::bindingIndexForName;
using SqliteStatement::setBindingColumnNames;
using SqliteStatement::bindingColumnNames;
using SqliteStatement::value;
using SqliteStatement::text;
using SqliteStatement::values;
using SqliteStatement::structValues;
using SqliteStatement::tupleValues;
using SqliteStatement::columnCount;
using SqliteStatement::columnNames;
using SqliteStatement::toValue;
using SqliteStatement::database;
using SqliteStatement::write;
using SqliteStatement::writeNamed;
using Statement::next;
using Statement::execute;
using Statement::reset;
using Statement::bind;
using Statement::bindValues;
using Statement::bindNameValues;
using Statement::bindingIndexForName;
using Statement::setBindingColumnNames;
using Statement::bindingColumnNames;
using Statement::value;
using Statement::text;
using Statement::values;
using Statement::structValues;
using Statement::tupleValues;
using Statement::columnCount;
using Statement::columnNames;
using Statement::toValue;
using Statement::database;
using Statement::write;
using Statement::writeNamed;
};
} // namespace Sqlite
This diff is collapsed.
......@@ -43,13 +43,13 @@ struct sqlite3;
namespace Sqlite {
class SqliteDatabase;
class SqliteDatabaseBackend;
class Database;
class DatabaseBackend;
class SQLITE_EXPORT SqliteStatement
class SQLITE_EXPORT Statement
{
protected:
explicit SqliteStatement(Utils::SmallStringView sqlStatement, SqliteDatabase &database);
explicit Statement(Utils::SmallStringView sqlStatement, Database &database);
static void deleteCompiledStatement(sqlite3_stmt *m_compiledStatement);
......@@ -344,7 +344,7 @@ protected:
}
template <typename Type>
static Type toValue(Utils::SmallStringView sqlStatement, SqliteDatabase &database);
static Type toValue(Utils::SmallStringView sqlStatement, Database &database);
void prepare(Utils::SmallStringView sqlStatement);
void waitForUnlockNotify() const;
......@@ -372,11 +372,11 @@ protected:
QString columnName(int column) const;
SqliteDatabase &database() const;
Database &database() const;
protected:
explicit SqliteStatement(Utils::SmallStringView sqlStatement,
SqliteDatabaseBackend &databaseBackend);
explicit Statement(Utils::SmallStringView sqlStatement,
DatabaseBackend &databaseBackend);
private:
template <typename ContainerType,
......@@ -452,27 +452,27 @@ private:
private:
std::unique_ptr<sqlite3_stmt, void (*)(sqlite3_stmt*)> m_compiledStatement;
Utils::SmallStringVector m_bindingColumnNames;
SqliteDatabase &m_database;
Database &m_database;
int m_bindingParameterCount;
int m_columnCount;
mutable bool m_isReadyToFetchValues;
};
extern template SQLITE_EXPORT void SqliteStatement::bind(Utils::SmallStringView name, int value);
extern template SQLITE_EXPORT void SqliteStatement::bind(Utils::SmallStringView name, long value);
extern template SQLITE_EXPORT void SqliteStatement::bind(Utils::SmallStringView name, long long value);
extern template SQLITE_EXPORT void SqliteStatement::bind(Utils::SmallStringView name, double value);
extern template SQLITE_EXPORT void SqliteStatement::bind(Utils::SmallStringView name, Utils::SmallStringView text);
extern template SQLITE_EXPORT int SqliteStatement::toValue<int>(Utils::SmallStringView sqlStatement, SqliteDatabase &database);
extern template SQLITE_EXPORT long long SqliteStatement::toValue<long long>(Utils::SmallStringView sqlStatement, SqliteDatabase &database);
extern template SQLITE_EXPORT double SqliteStatement::toValue<double>(Utils::SmallStringView sqlStatement, SqliteDatabase &database);
extern template SQLITE_EXPORT Utils::SmallString SqliteStatement::toValue<Utils::SmallString>(Utils::SmallStringView sqlStatement, SqliteDatabase &database);
template <> SQLITE_EXPORT int SqliteStatement::value<int>(int column) const;
template <> SQLITE_EXPORT long SqliteStatement::value<long>(int column) const;
template <> SQLITE_EXPORT long long SqliteStatement::value<long long>(int column) const;
template <> SQLITE_EXPORT double SqliteStatement::value<double>(int column) const;
extern template SQLITE_EXPORT Utils::SmallString SqliteStatement::value<Utils::SmallString>(int column) const;
extern template SQLITE_EXPORT Utils::PathString SqliteStatement::value<Utils::PathString>(int column) const;
extern template SQLITE_EXPORT void Statement::bind(Utils::SmallStringView name, int value);
extern template SQLITE_EXPORT void Statement::bind(Utils::SmallStringView name, long value);
extern template SQLITE_EXPORT void Statement::bind(Utils::SmallStringView name, long long value);
extern template SQLITE_EXPORT void Statement::bind(Utils::SmallStringView name, double value);
extern template SQLITE_EXPORT void Statement::bind(Utils::SmallStringView name, Utils::SmallStringView text);
extern template SQLITE_EXPORT int Statement::toValue<int>(Utils::SmallStringView sqlStatement, Database &database);
extern template SQLITE_EXPORT long long Statement::toValue<long long>(Utils::SmallStringView sqlStatement, Database &database);
extern template SQLITE_EXPORT double Statement::toValue<double>(Utils::SmallStringView sqlStatement, Database &database);
extern template SQLITE_EXPORT Utils::SmallString Statement::toValue<Utils::SmallString>(Utils::SmallStringView sqlStatement, Database &database);
template <> SQLITE_EXPORT int Statement::value<int>(int column) const;
template <> SQLITE_EXPORT long Statement::value<long>(int column) const;
template <> SQLITE_EXPORT long long Statement::value<long long>(int column) const;
template <> SQLITE_EXPORT double Statement::value<double>(int column) const;
extern template SQLITE_EXPORT Utils::SmallString Statement::value<Utils::SmallString>(int column) const;
extern template SQLITE_EXPORT Utils::PathString Statement::value<Utils::PathString>(int column) const;
} // namespace Sqlite
......@@ -33,12 +33,12 @@
namespace Sqlite {
class SqliteDatabase;
class Database;
class SqliteTable
class Table
{
public:
SqliteTable(std::size_t reserve = 10)
Table(std::size_t reserve = 10)
{
m_sqliteColumns.reserve(reserve);
m_sqliteIndices.reserve(reserve);
......@@ -74,7 +74,7 @@ public:
m_useTemporaryTable = useTemporaryTable;
}
SqliteColumn &addColumn(Utils::SmallString &&name,
Column &addColumn(Utils::SmallString &&name,
ColumnType type = ColumnType::Numeric,
Contraint constraint = Contraint::NoConstraint)
{
......@@ -83,7 +83,7 @@ public:
return m_sqliteColumns.back();
}
SqliteIndex &addIndex(const SqliteColumnConstReferences &columns)
Index &addIndex(const SqliteColumnConstReferences &columns)
{
m_sqliteIndices.emplace_back(m_tableName.clone(), sqliteColumnNames(columns));
......@@ -120,11 +120,11 @@ public:
template <typename Database>
void initializeIndices(Database &database)
{
for (const SqliteIndex &index : m_sqliteIndices)
for (const Index &index : m_sqliteIndices)
database.execute(index.sqlStatement());
}
friend bool operator==(const SqliteTable &first, const SqliteTable &second)
friend bool operator==(const Table &first, const Table &second)
{
return first.m_tableName == second.m_tableName
&& first.m_withoutRowId == second.m_withoutRowId
......@@ -138,7 +138,7 @@ private:
{
Utils::SmallStringVector columnNames;
for (const SqliteColumn &column : columns)
for (const Column &column : columns)
columnNames.push_back(column.name());
return columnNames;
......
......@@ -29,14 +29,14 @@
namespace Sqlite {
class SqliteDatabaseBackend;
class SqliteDatabase;
class DatabaseBackend;
class Database;
template <typename Database>
class SqliteAbstractTransaction
class AbstractTransaction
{
public:
~SqliteAbstractTransaction()
~AbstractTransaction()
{
if (!m_isAlreadyCommited)
m_database.execute("ROLLBACK");
......@@ -49,7 +49,7 @@ public:
}
protected:
SqliteAbstractTransaction(Database &database)
AbstractTransaction(Database &database)
: m_database(database)
{
}
......@@ -60,33 +60,33 @@ private:
};
template <typename Database>
class SqliteTransaction final : public SqliteAbstractTransaction<Database>
class DeferredTransaction final : public AbstractTransaction<Database>
{
public:
SqliteTransaction(Database &database)
: SqliteAbstractTransaction<Database>(database)
DeferredTransaction(Database &database)
: AbstractTransaction<Database>(database)
{
database.execute("BEGIN");
}
};
template <typename Database>
class SqliteImmediateTransaction final : public SqliteAbstractTransaction<Database>
class ImmediateTransaction final : public AbstractTransaction<Database>
{
public:
SqliteImmediateTransaction(Database &database)
: SqliteAbstractTransaction<Database>(database)
ImmediateTransaction(Database &database)
: AbstractTransaction<Database>(database)
{
database.execute("BEGIN IMMEDIATE");
}
};
template <typename Database>
class SqliteExclusiveTransaction final : public SqliteAbstractTransaction<Database>
class ExclusiveTransaction final : public AbstractTransaction<Database>
{