aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/plugins/dbplugin.h
blob: 2f2e62e1dd38505cc38864b23d908578398aed30 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef DBPLUGIN_H
#define DBPLUGIN_H

#include "db/db.h"
#include "db/dbpluginoption.h"
#include "plugins/plugin.h"

/**
 * @brief Interface for database plugins
 *
 * This is a specialization of Plugin interface, which all database plugins have to implement.
 */
class API_EXPORT DbPlugin : virtual public Plugin
{
    public:
        /**
         * @brief Creates database instance defined by the plugin.
         * @param name Name for the database.
         * @param path Path to the database file.
         * @param options Options for the database passed while registering the database in the application.
         * @param errorMessage If the result is null (on failure) and this pointer is not null, the error message will be stored in it.
         * @return Database instance on success, or null pointer on failure.
         *
         * Options can contain for example password for an encrypted database, or other connection options.
         */
        virtual Db* getInstance(const QString& name, const QString& path, const QHash<QString,QVariant> &options, QString* errorMessage = 0) = 0;

        /**
         * @brief Provides label of what type is the database.
         * @return Type label.
         *
         * The label is used for presenting to the user what kind of database this is. It's used on GUI
         * to display database type in databases dialog. It's usually either "SQLite3" or "SQLite2",
         * but it may be something else, like for example encrypted database might provide "Encrypted SQLite3",
         * or something similar.
         */
        virtual QString getLabel() const = 0;

        /**
         * @brief Provides list of options configurable for this database plugin.
         * @return List of options.
         *
         * DbDialog uses this to provide GUI interface, so user can configure connection options.
         * For each element in the list DbDialog adds QLabel and the input widget for entering option value.
         * Option values entered by user are later passed to getInstance() as second argument.
         */
        virtual QList<DbPluginOption> getOptionsList() const = 0;

        /**
         * @brief Generates suggestion for database name.
         * @param baseValue Value enterd as file path in DbDialog.
         * @return Generated name suggestion.
         *
         * This can be simply string representation of \p baseValue,
         * but the plugin may add something characteristic for the plugin.
         */
        virtual QString generateDbName(const QVariant& baseValue) = 0;

        /**
         * @brief Tests if the given database support is provided by this plugin.
         * @param db Database to test.
         * @return true if the database is supported by this plugin, or false otherwise.
         *
         * Implementation of this method should check if given database object
         * is of the same type, that those returned from getInstance().
         *
         * This method is used by DbManager to find out which databases are supported by which plugins,
         * so when some plugin is about to be unloaded, all its databases are closed properly first.
         */
        virtual bool checkIfDbServedByPlugin(Db* db) const = 0;
};

#endif // DBPLUGIN_H