KDb

SqliteAdmin.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2006-2012 JarosÅ‚aw Staniek <[email protected]>
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 
28 SqliteAdminTools::SqliteAdminTools()
29  : KDbAdminTools()
30 {
31 }
32 
33 SqliteAdminTools::~SqliteAdminTools()
34 {
35 }
36 
37 #ifdef KDB_SQLITE_VACUUM
38 bool 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
Database driver's abstraction.
Definition: KDbDriver.h:49
KDbResult result() const
void prependMessage(int code, const QString &message)
Sets result code and prepends message to an existing message.
Definition: KDbResult.cpp:80
QString fromNativeSeparators(const QString &pathName)
3-state logical type with three values: true, false and cancelled and convenient operators.
Definition: KDbTristate.h:100
An interface containing a set of tools for database administration.
Definition: KDbAdmin.h:30
Database specific connection data, e.g. host, port.
Helper class performing interactive compacting (VACUUM) of the SQLite database.
Definition: SqliteVacuum.h:45
A driver manager for finding and loading driver plugins.
virtual bool vacuum(const KDbConnectionData &data, const QString &databaseName)
Definition: KDbAdmin.cpp:42
QString tr(const char *sourceText, const char *disambiguation, int n)
KDbDriver * driver(const QString &id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:21:34 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.