2015-06-01 18:51:55 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:58:39 +01:00
|
|
|
** 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.
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** 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.
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
#include "sqliteglobal.h"
|
|
|
|
|
|
2017-07-27 15:59:54 +02:00
|
|
|
#include <utils/smallstringvector.h>
|
2015-06-16 12:38:04 +02:00
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
struct sqlite3;
|
|
|
|
|
|
2017-07-26 16:02:24 +02:00
|
|
|
namespace Sqlite {
|
|
|
|
|
|
2017-09-18 10:21:45 +02:00
|
|
|
class Database;
|
Sqlite: Add variadic bind and write functions
You can now write
SqliteWriteStatement statement("UPDATE test SET name=?, number=?
WHERE rowid=?", database);
statement.write("see", 7.23, 1);
and
SqliteWriteStatement statement("UPDATE test SET name=@name, number=@number
WHERE rowid=@id", database);
statement.writeNamed("@name", "see", "@number", 7.23, "@id", 1);
This is more type safe than using variants and performant too.
Change-Id: Ie1ed2a6d326b956be5c4ec056214f3f5b1531f45
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-07-31 19:44:39 +02:00
|
|
|
|
2017-09-18 10:21:45 +02:00
|
|
|
class SQLITE_EXPORT DatabaseBackend
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2017-09-18 10:21:45 +02:00
|
|
|
DatabaseBackend(Database &database);
|
|
|
|
|
~DatabaseBackend();
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-09-18 10:21:45 +02:00
|
|
|
DatabaseBackend(const Database &) = delete;
|
|
|
|
|
Database &operator=(const Database &) = delete;
|
2017-08-01 14:02:57 +02:00
|
|
|
|
2017-09-18 10:21:45 +02:00
|
|
|
DatabaseBackend(Database &&) = delete;
|
|
|
|
|
Database &operator=(Database &&) = delete;
|
Sqlite: Add variadic bind and write functions
You can now write
SqliteWriteStatement statement("UPDATE test SET name=?, number=?
WHERE rowid=?", database);
statement.write("see", 7.23, 1);
and
SqliteWriteStatement statement("UPDATE test SET name=@name, number=@number
WHERE rowid=@id", database);
statement.writeNamed("@name", "see", "@number", 7.23, "@id", 1);
This is more type safe than using variants and performant too.
Change-Id: Ie1ed2a6d326b956be5c4ec056214f3f5b1531f45
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-07-31 19:44:39 +02:00
|
|
|
|
2017-07-26 18:43:07 +02:00
|
|
|
void setMmapSize(qint64 defaultSize, qint64 maximumSize);
|
|
|
|
|
void activateMultiThreading();
|
|
|
|
|
void activateLogging();
|
|
|
|
|
void initializeSqliteLibrary();
|
|
|
|
|
void shutdownSqliteLibrary();
|
|
|
|
|
void checkpointFullWalLog();
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-08-01 18:32:29 +02:00
|
|
|
void open(Utils::SmallStringView databaseFilePath, OpenMode openMode);
|
2015-06-01 18:51:55 +02:00
|
|
|
void close();
|
|
|
|
|
void closeWithoutException();
|
|
|
|
|
|
2017-09-21 11:33:26 +02:00
|
|
|
sqlite3* sqliteDatabaseHandle() const;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
void setJournalMode(JournalMode journalMode);
|
2017-07-26 18:43:07 +02:00
|
|
|
JournalMode journalMode();
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
void setTextEncoding(TextEncoding textEncoding);
|
|
|
|
|
TextEncoding textEncoding();
|
|
|
|
|
|
2017-07-27 15:59:54 +02:00
|
|
|
Utils::SmallStringVector columnNames(Utils::SmallStringView tableName);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-09-21 11:33:26 +02:00
|
|
|
int changesCount() const;
|
|
|
|
|
int totalChangesCount() const;
|
|
|
|
|
|
|
|
|
|
int64_t lastInsertedRowId() const;
|
2017-07-26 18:43:07 +02:00
|
|
|
|
2017-07-27 15:59:54 +02:00
|
|
|
void execute(Utils::SmallStringView sqlStatement);
|
2017-07-26 18:43:07 +02:00
|
|
|
|
|
|
|
|
template <typename Type>
|
2017-07-27 15:59:54 +02:00
|
|
|
Type toValue(Utils::SmallStringView sqlStatement);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-08-01 18:32:29 +02:00
|
|
|
static int openMode(OpenMode);
|
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
protected:
|
|
|
|
|
bool databaseIsOpen() const;
|
|
|
|
|
|
2017-07-27 15:59:54 +02:00
|
|
|
void setPragmaValue(Utils::SmallStringView pragma, Utils::SmallStringView value);
|
|
|
|
|
Utils::SmallString pragmaValue(Utils::SmallStringView pragma);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
void registerBusyHandler();
|
|
|
|
|
void registerRankingFunction();
|
|
|
|
|
static int busyHandlerCallback(void*, int counter);
|
|
|
|
|
|
|
|
|
|
void cacheTextEncoding();
|
|
|
|
|
|
|
|
|
|
void checkForOpenDatabaseWhichCanBeClosed();
|
|
|
|
|
void checkDatabaseClosing(int resultCode);
|
2017-07-27 15:59:54 +02:00
|
|
|
void checkCanOpenDatabase(Utils::SmallStringView databaseFilePath);
|
2015-06-01 18:51:55 +02:00
|
|
|
void checkDatabaseCouldBeOpened(int resultCode);
|
2017-07-27 15:59:54 +02:00
|
|
|
void checkPragmaValue(Utils::SmallStringView databaseValue, Utils::SmallStringView expectedValue);
|
2017-09-21 11:33:26 +02:00
|
|
|
void checkDatabaseHandleIsNotNull() const;
|
2017-07-26 18:43:07 +02:00
|
|
|
void checkIfMultithreadingIsActivated(int resultCode);
|
|
|
|
|
void checkIfLoogingIsActivated(int resultCode);
|
|
|
|
|
void checkMmapSizeIsSet(int resultCode);
|
|
|
|
|
void checkInitializeSqliteLibraryWasSuccesful(int resultCode);
|
|
|
|
|
void checkShutdownSqliteLibraryWasSuccesful(int resultCode);
|
|
|
|
|
void checkIfLogCouldBeCheckpointed(int resultCode);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-07-27 15:59:54 +02:00
|
|
|
static Utils::SmallStringView journalModeToPragma(JournalMode journalMode);
|
|
|
|
|
static JournalMode pragmaToJournalMode(Utils::SmallStringView pragma);
|
|
|
|
|
Utils::SmallStringView textEncodingToPragma(TextEncoding textEncoding);
|
|
|
|
|
static TextEncoding pragmaToTextEncoding(Utils::SmallStringView pragma);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-08-01 18:32:29 +02:00
|
|
|
|
2017-07-26 18:43:07 +02:00
|
|
|
Q_NORETURN static void throwExceptionStatic(const char *whatHasHappens);
|
2017-09-18 11:23:09 +02:00
|
|
|
[[noreturn]] void throwException(const char *whatHasHappens) const;
|
|
|
|
|
[[noreturn]] void throwUnknowError(const char *whatHasHappens) const;
|
|
|
|
|
[[noreturn]] void throwDatabaseIsNotOpen(const char *whatHasHappens) const;
|
2017-08-01 18:32:29 +02:00
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
private:
|
2017-09-18 10:21:45 +02:00
|
|
|
Database &m_database;
|
2017-07-26 16:02:24 +02:00
|
|
|
sqlite3 *m_databaseHandle;
|
|
|
|
|
TextEncoding m_cachedTextEncoding;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
};
|
2017-07-26 16:02:24 +02:00
|
|
|
|
|
|
|
|
} // namespace Sqlite
|