KDb

SqliteAdmin.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006-2012 Jarosław Staniek <staniek@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "SqliteAdmin.h"
21#include "SqliteVacuum.h"
22
23#include "KDbConnectionData.h"
24#include "KDbDriverManager.h"
25
26#include <QDir>
27
28SqliteAdminTools::SqliteAdminTools()
30{
31}
32
33SqliteAdminTools::~SqliteAdminTools()
34{
35}
36
37#ifdef KDB_SQLITE_VACUUM
38bool SqliteAdminTools::vacuum(const KDbConnectionData& data, const QString& databaseName)
39{
40 clearResult();
41 KDbDriverManager manager;
42 KDbDriver *drv = manager.driver(data.driverId());
43 QString title(SqliteVacuum::tr("Could not compact database \"%1\".").arg(QDir::fromNativeSeparators(databaseName)));
44 if (!drv) {
45 m_result = manager.result();
46 m_result.prependMessage(title);
47 return false;
48 }
49 QFileInfo file(databaseName);
50 SqliteVacuum vacuum(QDir::fromNativeSeparators(file.absoluteFilePath()));
51 tristate result = vacuum.run();
52 if (false == result) {
53 m_result = KDbResult(title);
54 return false;
55 } else { //success or cancelled
56 return true;
57 }
58}
59#endif
An interface containing a set of tools for database administration.
Definition KDbAdmin.h:31
virtual bool vacuum(const KDbConnectionData &data, const QString &databaseName)
Definition KDbAdmin.cpp:42
Database specific connection data, e.g. host, port.
A driver manager for finding and loading driver plugins.
KDbResult result() const
KDbDriver * driver(const QString &id)
Database driver's abstraction.
Definition KDbDriver.h:50
void prependMessage(int code, const QString &message)
Sets result code and prepends message to an existing message.
Definition KDbResult.cpp:80
Helper class performing interactive compacting (VACUUM) of the SQLite database.
3-state logical type with three values: true, false and cancelled and convenient operators.
QString fromNativeSeparators(const QString &pathName)
QString tr(const char *sourceText, const char *disambiguation, int n)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.