2014-10-14 13:14:57 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OWNSQL_H
|
|
|
|
#define OWNSQL_H
|
|
|
|
|
|
|
|
#include <sqlite3.h>
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QVariant>
|
|
|
|
|
2014-10-20 21:57:59 +04:00
|
|
|
#include "owncloudlib.h"
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2014-10-14 22:51:51 +04:00
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The SqlDatabase class
|
|
|
|
* @ingroup libsync
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2014-10-20 21:57:59 +04:00
|
|
|
class OWNCLOUDSYNC_EXPORT SqlDatabase
|
2014-10-14 13:14:57 +04:00
|
|
|
{
|
2014-10-23 17:34:07 +04:00
|
|
|
Q_DISABLE_COPY(SqlDatabase)
|
2014-10-14 13:14:57 +04:00
|
|
|
public:
|
|
|
|
explicit SqlDatabase();
|
|
|
|
|
|
|
|
bool isOpen();
|
2014-12-04 15:55:58 +03:00
|
|
|
bool openOrCreateReadWrite( const QString& filename );
|
|
|
|
bool openReadOnly( const QString& filename );
|
2014-10-14 13:14:57 +04:00
|
|
|
bool transaction();
|
|
|
|
bool commit();
|
|
|
|
void close();
|
|
|
|
QString error() const;
|
|
|
|
sqlite3* sqliteDb();
|
|
|
|
|
|
|
|
private:
|
2014-12-04 15:55:58 +03:00
|
|
|
bool openHelper( const QString& filename, int sqliteFlags );
|
|
|
|
bool checkDb();
|
|
|
|
|
2014-10-14 13:14:57 +04:00
|
|
|
sqlite3 *_db;
|
|
|
|
QString _error; // last error string
|
|
|
|
int _errId;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The SqlQuery class
|
|
|
|
* @ingroup libsync
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2014-10-20 21:57:59 +04:00
|
|
|
class OWNCLOUDSYNC_EXPORT SqlQuery
|
2014-10-14 13:14:57 +04:00
|
|
|
{
|
2014-10-16 17:10:25 +04:00
|
|
|
Q_DISABLE_COPY(SqlQuery)
|
2014-10-14 13:14:57 +04:00
|
|
|
public:
|
2014-10-23 17:34:07 +04:00
|
|
|
explicit SqlQuery(SqlDatabase& db);
|
|
|
|
explicit SqlQuery(const QString& sql, SqlDatabase& db);
|
2014-10-14 13:14:57 +04:00
|
|
|
|
|
|
|
~SqlQuery();
|
|
|
|
QString error() const;
|
|
|
|
|
2015-10-28 13:00:03 +03:00
|
|
|
/// Checks whether the value at the given column index is NULL
|
|
|
|
bool nullValue(int index);
|
|
|
|
|
2014-10-14 13:14:57 +04:00
|
|
|
QString stringValue(int index);
|
|
|
|
int intValue(int index);
|
|
|
|
quint64 int64Value(int index);
|
|
|
|
QByteArray baValue(int index);
|
|
|
|
|
2014-10-14 22:51:51 +04:00
|
|
|
bool isSelect();
|
|
|
|
bool isPragma();
|
2014-10-14 13:14:57 +04:00
|
|
|
bool exec();
|
2014-10-14 22:51:51 +04:00
|
|
|
int prepare( const QString& sql );
|
2014-10-14 13:14:57 +04:00
|
|
|
bool next();
|
|
|
|
void bindValue(int pos, const QVariant& value);
|
|
|
|
QString lastQuery() const;
|
|
|
|
int numRowsAffected();
|
2016-03-15 16:32:09 +03:00
|
|
|
void reset_and_clear_bindings();
|
2014-10-14 13:14:57 +04:00
|
|
|
void finish();
|
|
|
|
|
|
|
|
private:
|
|
|
|
sqlite3 *_db;
|
|
|
|
sqlite3_stmt *_stmt;
|
|
|
|
QString _error;
|
|
|
|
int _errId;
|
2014-10-14 22:51:51 +04:00
|
|
|
QString _sql;
|
2014-10-14 13:14:57 +04:00
|
|
|
};
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|
2014-10-14 22:51:51 +04:00
|
|
|
|
2014-10-14 13:14:57 +04:00
|
|
|
#endif // OWNSQL_H
|