|
LibEngsas
|
Class to manage database structures.This class is able to create and modify complexe database structures. You can define a structure in scheme() and this class handles the creation of this structure or updates an existing one automatically. To allow more customization, you can register update routines, to get a more customized post processsing of updates. More...
#include <esqlinit.h>
Inheritance diagram for ESqlInit:
Collaboration diagram for ESqlInit:Public Types | |
| enum | privileges { SELECT, INSERT, UPDATE, DEL, CREATE, ALTER } |
| enum | Status { BadSettings, LoggedIn, LoginFailed, UpdateNeeded, UpdateFailed, NoUpdateNeeded } |
Public Slots | |
| void | reloadSettings () |
Public Slots inherited from EObject | |
| virtual void | reloadSettings () |
| Used to reload the settings. More... | |
Signals | |
| void | actualStep (QString msg) |
Set the text above the upper progress bar to msg. More... | |
| void | finishedStep () |
| Increases the value of the progress bar by 1. More... | |
| void | neededSteps (int num) |
Sets the maximum of the progress bar to num. More... | |
Signals inherited from EObject | |
| void | error (const QString &message) |
| void | warning (const QString &message) |
| void | information (const QString &message) |
| void | reloadEnableActions () |
| Request reloading of enabled actions in EMainWindow. More... | |
| void | addMenu (QMenu *newMenu, const QString &parent, QString before=QString()) |
| void | addAction (QAction *newAction, const QString &parent, QString before=QString()) |
| void | addToolBar (QToolBar *newToolBar, Qt::ToolBarArea area=Qt::TopToolBarArea) |
| void | addNewDockWidget (QDockWidget *widget, const Qt::DockWidgetArea &area) |
| void | setCentralWidget (QWidget *centralWidget) |
| void | showSettings () |
| void | showHelp (const QString &page) |
| void | showStatusWidget (QWidget *widget) |
| void | reloadSettingsRequest () |
| Indicates, that a reload of the settings is needed. More... | |
| void | doReloadSettings () |
| Emitted to bring the reload request back to the farest child. More... | |
Public Member Functions | |
| ESqlInit (QObject *parent=0, QString username=QString(), QString host=QString(), QString database=QString(), QString driver=QString(), QString password=QString()) | |
| virtual | ~ESqlInit () |
| ESqlInit::Status | login (bool loginOnly=true, bool runUpdate=false) |
| Logs in and after logging it's check the structure of the database against the given one at the scheme() function. More... | |
| ESqlInit::Status | loginGuiless (bool loginOnly=true, bool runUpdate=false) |
| QString | label () const |
| Returns the label set with setup(). More... | |
| int | schemaVersion () const |
| Returns the schema version set with setup(). More... | |
| QString | databaseName () const |
| Returns the database name, currently managed. More... | |
| void | addInformation (QString msg) |
Emits the signal information() with content msg. More... | |
Public Member Functions inherited from EObject | |
| EObject (QObject *parent=0) | |
| virtual | ~EObject () |
| void | connectByPass (QObject *object) |
Protected Member Functions | |
| virtual void | scheme ()=0 |
| Stores the database scheme. More... | |
| void | addUpdateRoutine (int toVersion, bool(*functionPointer)(ESqlInit *, QList< ESqlTable * >, QString &)) |
| Registers the update routine. More... | |
| ESqlTable * | addTable (QString name, bool appendFieldId=true, bool addPrefix=true) |
| Adds a new table to the list of tables. More... | |
| void | addView (QString name, QString selectStatement, bool addPrefix=true) |
| Adds a view to the list of views. More... | |
| void | setup (QString name, QString label, int version) |
| Setup the needed meta data of this module. More... | |
Protected Member Functions inherited from EObject | |
| void | addManagedDockWidget (QDockWidget *widget, const Qt::DockWidgetArea &area, QString actionLabel=QString(), QString actionParent=QString()) |
Adds an dock widget via addNewDockWidget() and adds widget to the list of managed dock widgets. More... | |
Private Slots | |
| bool | updateDb () |
Private Member Functions | |
| ESqlInit::Status | login (bool loginOnly, bool runUpdate, bool enableGui) |
| bool | updateNeeded () |
| bool | doUpdate () |
| bool | compareTables (ESqlTable *table, QString &errorString, bool create=false) |
| bool | compareViews (QStringList view, QString &errorString, bool create=false) |
| QString | createViewStatement (QStringList view) |
| bool | runUpdateRoutines (int fromVersion, QString &errorString, int toVersion) |
| Runs all needed and registered update routines. More... | |
| void | init () |
| Initializes the structure by calling scheme(). More... | |
Private Attributes | |
| QString | dbName |
| QString | versionTable |
| bool | transactions |
| bool | gui |
| EngSaS::SQL::DatabaseType | dbType |
| QList< ESqlInit::privileges > | neededPrivs |
| int | actVersion |
| QString | username |
| QString | password |
| QString | host |
| QString | driver |
| ESqlDatabase | db |
| int | currentVersion |
| QString | thisName |
| QString | moduleLabel |
| QList< ESqlTable * > | tables |
| QList< QStringList > | views |
| QMap< int, bool(*)(ESqlInit *, QList< ESqlTable * > , QString &)> | updateRoutines |
Additional Inherited Members | |
Static Public Member Functions inherited from EObject | |
| static void | connectByPass (QObject *parent, QObject *child) |
Protected Slots inherited from EObject | |
| virtual void | errorByPass (const QString &message) |
| virtual void | warningByPass (const QString &message) |
| virtual void | informationByPass (const QString &message) |
| virtual void | reloadEnableActionsByPass () |
| virtual void | addMenuByPass (QMenu *newMenu, const QString &parent, QString before=QString()) |
| virtual void | addActionByPass (QAction *newAction, const QString &parent, QString before=QString()) |
| virtual void | addToolBarByPass (QToolBar *newToolBar, Qt::ToolBarArea area=Qt::TopToolBarArea) |
| virtual void | addNewDockWidgetByPass (QDockWidget *widget, const Qt::DockWidgetArea &area) |
| virtual void | setCentralWidgetByPass (QWidget *centralWidget) |
| virtual void | showSettingsByPass () |
| virtual void | showHelpByPass (const QString &page) |
| virtual void | showStatusWidgetByPass (QWidget *widget) |
| virtual void | reloadSettingsRequestByPass () |
Class to manage database structures.
This class is able to create and modify complexe database structures. You can define a structure in scheme() and this class handles the creation of this structure or updates an existing one automatically. To allow more customization, you can register update routines, to get a more customized post processsing of updates.
To use this class, subclass it and implement scheme(). There you should setup the needed meta data by calling setup(). Afterwards, you can use addTable() to add tables. At last you can use addUpdateRoutine() to add some custom post update processing.
Here is an example scheme function:
error message when inserting of vaules have failed
check needed rights and ask for username and password with extended rights, if they are needed for example things like create tables, ...
| ESqlInit::ESqlInit | ( | QObject * | parent = 0, |
| QString | username = QString(), |
||
| QString | host = QString(), |
||
| QString | database = QString(), |
||
| QString | driver = QString(), |
||
| QString | password = QString() |
||
| ) |
|
virtual |
|
signal |
Set the text above the upper progress bar to msg.
Here is the caller graph for this function:| void ESqlInit::addInformation | ( | QString | msg | ) |
Emits the signal information() with content msg.
Use this function to add information messages to the log in your updateRoutines.
|
protected |
Adds a new table to the list of tables.
The added table will be named name with prefix of the name set by setup() (if addPrefix is true) and gets an id field, if appendFieldId is true (Default).
Here is the call graph for this function:
Here is the caller graph for this function:
|
protected |
Registers the update routine.
In the update routine, you can access the label set with setup() with help of caller->label(). To get the database name, which is used by current connection, use caller->databaseName(). If you want to add a message to the logs, use caller->addInformation().
| toVersion | Version which is reached, after the updateroutine is run |
functionPointer should handle a QString& to give back error messages
|
protected |
Adds a view to the list of views.
The added view will be named name with prefix of the name set by setup() (if addPrefix is true). The view itself is defined with help of a select statement, which is the second parameter selectStatement.
|
private |
compares to tables in mode create = false it returns true if both tables are identical and false if not if update is set to true, it updates the table or even create it.
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
checks, if view with current statement exists
| view | the view which a create statement should be created |
| error | a pointer to a QString where the error message is appended |
| create | create view if it not exist or with other select statement |
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
create views statement
| view | index of view at QList views; |
Here is the caller graph for this function:| QString ESqlInit::databaseName | ( | ) | const |
Returns the database name, currently managed.
|
private |
does the update
Here is the call graph for this function:
Here is the caller graph for this function:
|
signal |
Increases the value of the progress bar by 1.
Here is the caller graph for this function:
|
private |
Initializes the structure by calling scheme().
It allso adds the standard table "dbmoduleversions" as first table.
Here is the call graph for this function:
Here is the caller graph for this function:| QString ESqlInit::label | ( | ) | const |
Returns the label set with setup().
This string is used as a prefix for all tables of this module.
Here is the caller graph for this function:| ESqlInit::Status ESqlInit::login | ( | bool | loginOnly = true, |
| bool | runUpdate = false |
||
| ) |
Logs in and after logging it's check the structure of the database against the given one at the scheme() function.
For convenience, this function enables GUI automatically, if QApplication is available. If only QCoreApplication is available, GUI is disabled automatically.
| runUpdate | is set to false login returns true if an update is needed |
| runUpdate | is set to true, login runs the update and return true if the updates are done successfull |
Here is the caller graph for this function:
|
private |
The internal login function
Here is the call graph for this function:| ESqlInit::Status ESqlInit::loginGuiless | ( | bool | loginOnly = true, |
| bool | runUpdate = false |
||
| ) |
Here is the call graph for this function:
|
signal |
Sets the maximum of the progress bar to num.
Here is the caller graph for this function:
|
slot |
Here is the call graph for this function:
|
private |
Runs all needed and registered update routines.
It runs all registered update routines, which are needed to reach toVersion from fromVersion. If an error occurs, errorString is filled and false is returned.
To register an update routine, call addUpdateRoutine().
Here is the caller graph for this function:| int ESqlInit::schemaVersion | ( | ) | const |
Returns the schema version set with setup().
|
protectedpure virtual |
Stores the database scheme.
Here is the caller graph for this function:
|
protected |
Setup the needed meta data of this module.
The chosen name is used as a prefix for some tables and also an entry in the dbmodulesversion is done with this name. This entry contains also label and version.
Here is the call graph for this function:
|
privateslot |
initializes the update
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
checks wether update of the structure is needed or not it also checks wether structure is newer than needed which might be bad too
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
|
private |
current version of db structure
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
a list of all tables of the database which are needed by this module
|
private |
prefix of all tables which belongs to this module
|
private |
the first int (QMap-Key) is the result version, which is reached, if updateFunction runs successfully. updateFunction should than return true
|
private |
|
private |
|
private |
1.8.8