diff options
Diffstat (limited to 'Plugins/DbSqlite2')
| -rw-r--r-- | Plugins/DbSqlite2/DbSqlite2.pro | 26 | ||||
| -rw-r--r-- | Plugins/DbSqlite2/dbsqlite2.cpp | 51 | ||||
| -rw-r--r-- | Plugins/DbSqlite2/dbsqlite2.h | 23 | ||||
| -rw-r--r-- | Plugins/DbSqlite2/dbsqlite2.json | 7 | ||||
| -rw-r--r-- | Plugins/DbSqlite2/dbsqlite2_global.h | 12 | ||||
| -rw-r--r-- | Plugins/DbSqlite2/dbsqlite2instance.cpp | 7 | ||||
| -rw-r--r-- | Plugins/DbSqlite2/dbsqlite2instance.h | 27 |
7 files changed, 153 insertions, 0 deletions
diff --git a/Plugins/DbSqlite2/DbSqlite2.pro b/Plugins/DbSqlite2/DbSqlite2.pro new file mode 100644 index 0000000..656bd5d --- /dev/null +++ b/Plugins/DbSqlite2/DbSqlite2.pro @@ -0,0 +1,26 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2013-04-08T22:41:09 +# +#------------------------------------------------- + +include($$PWD/../../SQLiteStudio3/plugins.pri) + +QT -= gui + +TARGET = DbSqlite2 +TEMPLATE = lib + +DEFINES += DBSQLITE2_LIBRARY + +SOURCES += dbsqlite2.cpp \ + dbsqlite2instance.cpp + +HEADERS += dbsqlite2.h\ + dbsqlite2_global.h \ + dbsqlite2instance.h + +LIBS += -lsqlite + +OTHER_FILES += \ + dbsqlite2.json diff --git a/Plugins/DbSqlite2/dbsqlite2.cpp b/Plugins/DbSqlite2/dbsqlite2.cpp new file mode 100644 index 0000000..8047c7e --- /dev/null +++ b/Plugins/DbSqlite2/dbsqlite2.cpp @@ -0,0 +1,51 @@ +#include "dbsqlite2.h" +#include "dbsqlite2instance.h" +#include "common/unused.h" +#include <QFileInfo> + +DbSqlite2::DbSqlite2() +{ +} + +Db* DbSqlite2::getInstance(const QString& name, const QString& path, const QHash<QString, QVariant>& options, QString* errorMessage) +{ + UNUSED(errorMessage); + Db* db = new DbSqlite2Instance(name, path, options); + + if (!db->openForProbing()) + { + delete db; + return nullptr; + } + + SqlQueryPtr results = db->exec("SELECT * FROM sqlite_master"); + if (results->isError()) + { + delete db; + return nullptr; + } + + db->closeQuiet(); + return db; +} + +QList<DbPluginOption> DbSqlite2::getOptionsList() const +{ + return QList<DbPluginOption>(); +} + +QString DbSqlite2::generateDbName(const QVariant& baseValue) +{ + QFileInfo file(baseValue.toString()); + return file.baseName(); +} + +QString DbSqlite2::getLabel() const +{ + return "SQLite 2"; +} + +bool DbSqlite2::checkIfDbServedByPlugin(Db* db) const +{ + return (db && dynamic_cast<DbSqlite2Instance*>(db)); +} diff --git a/Plugins/DbSqlite2/dbsqlite2.h b/Plugins/DbSqlite2/dbsqlite2.h new file mode 100644 index 0000000..c428031 --- /dev/null +++ b/Plugins/DbSqlite2/dbsqlite2.h @@ -0,0 +1,23 @@ +#ifndef DBSQLITE2_H +#define DBSQLITE2_H + +#include "dbsqlite2_global.h" +#include "plugins/dbplugin.h" +#include "plugins/genericplugin.h" + +class DBSQLITE2SHARED_EXPORT DbSqlite2 : public GenericPlugin, public DbPlugin +{ + Q_OBJECT + SQLITESTUDIO_PLUGIN("dbsqlite2.json") + + public: + DbSqlite2(); + + QString getLabel() const; + bool checkIfDbServedByPlugin(Db* db) const; + Db* getInstance(const QString& name, const QString& path, const QHash<QString, QVariant>& options, QString* errorMessage); + QList<DbPluginOption> getOptionsList() const; + QString generateDbName(const QVariant& baseValue); +}; + +#endif // DBSQLITE2_H diff --git a/Plugins/DbSqlite2/dbsqlite2.json b/Plugins/DbSqlite2/dbsqlite2.json new file mode 100644 index 0000000..275a794 --- /dev/null +++ b/Plugins/DbSqlite2/dbsqlite2.json @@ -0,0 +1,7 @@ +{ + "type": "DbPlugin", + "title": "SQLite 2", + "description": "Provides support for SQLite 2.* databases", + "version": 10001, + "author": "SalSoft" +} diff --git a/Plugins/DbSqlite2/dbsqlite2_global.h b/Plugins/DbSqlite2/dbsqlite2_global.h new file mode 100644 index 0000000..42b7af8 --- /dev/null +++ b/Plugins/DbSqlite2/dbsqlite2_global.h @@ -0,0 +1,12 @@ +#ifndef DBSQLITE2_GLOBAL_H +#define DBSQLITE2_GLOBAL_H + +#include <QtCore/qglobal.h> + +#if defined(DBSQLITE2_LIBRARY) +# define DBSQLITE2SHARED_EXPORT Q_DECL_EXPORT +#else +# define DBSQLITE2SHARED_EXPORT Q_DECL_IMPORT +#endif + +#endif // DBSQLITE2_GLOBAL_H diff --git a/Plugins/DbSqlite2/dbsqlite2instance.cpp b/Plugins/DbSqlite2/dbsqlite2instance.cpp new file mode 100644 index 0000000..905f6fe --- /dev/null +++ b/Plugins/DbSqlite2/dbsqlite2instance.cpp @@ -0,0 +1,7 @@ +#include "dbsqlite2instance.h" + +DbSqlite2Instance::DbSqlite2Instance(const QString& name, const QString& path, const QHash<QString, QVariant>& connOptions) : + AbstractDb2<Sqlite2>(name, path, connOptions) +{ + +} diff --git a/Plugins/DbSqlite2/dbsqlite2instance.h b/Plugins/DbSqlite2/dbsqlite2instance.h new file mode 100644 index 0000000..83c54d3 --- /dev/null +++ b/Plugins/DbSqlite2/dbsqlite2instance.h @@ -0,0 +1,27 @@ +#ifndef DBSQLITE2INSTANCE_H +#define DBSQLITE2INSTANCE_H + +#include "db/abstractdb2.h" +#include "common/global.h" +#include <sqlite.h> + +struct Sqlite2 +{ + static_char* label = "SQLite 2"; +}; + +class DbSqlite2Instance : public AbstractDb2<Sqlite2> +{ + public: + /** + * @brief Creates SQLite database object. + * @param name Name for the database. + * @param path File path of the database. + * @param connOptions Connection options. See AbstractDb for details. + * + * All values from this constructor are just passed to AbstractDb2 constructor. + */ + DbSqlite2Instance(const QString& name, const QString& path, const QHash<QString, QVariant>& connOptions); +}; + +#endif // DBSQLITE2INSTANCE_H |
