forked from qt-creator/qt-creator
ClangRefactoring: Ensure that database is written to log after indexing
Change-Id: Ic2473d9fe8dc9b41a7da728c9e1b5202524c1a79 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -29,6 +29,7 @@ SOURCES += \
|
||||
HEADERS += \
|
||||
$$PWD/createtablesqlstatementbuilder.h \
|
||||
$$PWD/sqlitedatabasebackend.h \
|
||||
$$PWD/sqlitedatabaseinterface.h \
|
||||
$$PWD/sqliteexception.h \
|
||||
$$PWD/sqliteglobal.h \
|
||||
$$PWD/sqlitereadstatement.h \
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "sqlitedatabasebackend.h"
|
||||
#include "sqlitedatabaseinterface.h"
|
||||
#include "sqliteglobal.h"
|
||||
#include "sqlitetable.h"
|
||||
#include "sqlitetransaction.h"
|
||||
@@ -43,7 +44,7 @@ using namespace std::chrono_literals;
|
||||
class ReadStatement;
|
||||
class WriteStatement;
|
||||
|
||||
class SQLITE_EXPORT Database final : public TransactionInterface
|
||||
class SQLITE_EXPORT Database final : public TransactionInterface, public DatabaseInterface
|
||||
{
|
||||
template <typename Database>
|
||||
friend class Statement;
|
||||
@@ -105,19 +106,18 @@ public:
|
||||
return m_databaseBackend.changesCount();
|
||||
}
|
||||
|
||||
int totalChangesCount()
|
||||
{
|
||||
return m_databaseBackend.totalChangesCount();
|
||||
}
|
||||
int totalChangesCount() { return m_databaseBackend.totalChangesCount(); }
|
||||
|
||||
void walCheckpointFull() override { m_databaseBackend.walCheckpointFull(); }
|
||||
|
||||
private:
|
||||
void deferredBegin();
|
||||
void immediateBegin();
|
||||
void exclusiveBegin();
|
||||
void commit();
|
||||
void rollback();
|
||||
void lock();
|
||||
void unlock();
|
||||
void deferredBegin() override;
|
||||
void immediateBegin() override;
|
||||
void exclusiveBegin() override;
|
||||
void commit() override;
|
||||
void rollback() override;
|
||||
void lock() override;
|
||||
void unlock() override;
|
||||
|
||||
void initializeTables();
|
||||
void registerTransactionStatements();
|
||||
|
||||
@@ -406,6 +406,27 @@ void DatabaseBackend::setBusyTimeout(std::chrono::milliseconds timeout)
|
||||
sqlite3_busy_timeout(m_databaseHandle, int(timeout.count()));
|
||||
}
|
||||
|
||||
void DatabaseBackend::walCheckpointFull()
|
||||
{
|
||||
int resultCode = sqlite3_wal_checkpoint_v2(m_databaseHandle,
|
||||
nullptr,
|
||||
SQLITE_CHECKPOINT_TRUNCATE,
|
||||
nullptr,
|
||||
nullptr);
|
||||
|
||||
switch (resultCode) {
|
||||
case SQLITE_OK:
|
||||
break;
|
||||
case SQLITE_BUSY:
|
||||
throw DatabaseIsBusy("DatabaseBackend::walCheckpointFull: Operation could not concluded "
|
||||
"because database is busy!");
|
||||
case SQLITE_ERROR:
|
||||
throwException("DatabaseBackend::walCheckpointFull: Error occurred!");
|
||||
case SQLITE_MISUSE:
|
||||
throwExceptionStatic("DatabaseBackend::walCheckpointFull: Misuse of database!");
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseBackend::throwExceptionStatic(const char *whatHasHappens)
|
||||
{
|
||||
throw Exception(whatHasHappens);
|
||||
|
||||
@@ -85,6 +85,8 @@ public:
|
||||
|
||||
void setBusyTimeout(std::chrono::milliseconds timeout);
|
||||
|
||||
void walCheckpointFull();
|
||||
|
||||
protected:
|
||||
bool databaseIsOpen() const;
|
||||
|
||||
|
||||
37
src/libs/sqlite/sqlitedatabaseinterface.h
Normal file
37
src/libs/sqlite/sqlitedatabaseinterface.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2019 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
|
||||
|
||||
namespace Sqlite {
|
||||
class DatabaseInterface
|
||||
{
|
||||
public:
|
||||
virtual void walCheckpointFull() = 0;
|
||||
|
||||
protected:
|
||||
~DatabaseInterface() = default;
|
||||
};
|
||||
} // namespace Sqlite
|
||||
Reference in New Issue
Block a user