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>
Public Types | |
enum | privileges { SELECT, INSERT, UPDATE, DEL, CREATE, ALTER } |
enum | Status { BadSettings, LoggedIn, LoginFailed, UpdateNeeded, UpdateFailed, NoUpdateNeeded } |
Public Slots | |
void | reloadSettings () |
![]() | |
virtual void | reloadSettings () |
Used to reload the settings. |
Signals | |
void | actualStep (QString msg) |
Set the text above the upper progress bar to msg . | |
void | finishedStep () |
Increases the value of the progress bar by 1. | |
void | neededSteps (int num) |
Sets the maximum of the progress bar to num . | |
![]() | |
void | error (const QString &message) |
void | warning (const QString &message) |
void | information (const QString &message) |
void | reloadEnableActions () |
Request reloading of enabled actions in EMainWindow. | |
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. | |
void | doReloadSettings () |
Emitted to bring the reload request back to the farest child. |
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. | |
ESqlInit::Status | loginGuiless (bool loginOnly=true, bool runUpdate=false) |
QString | label () const |
Returns the label set with setup(). | |
int | schemaVersion () const |
Returns the schema version set with setup(). | |
QString | databaseName () const |
Returns the database name, currently managed. | |
void | addInformation (QString msg) |
Emits the signal information() with content msg . | |
![]() | |
EObject (QObject *parent=0) | |
virtual | ~EObject () |
void | connectByPass (QObject *object) |
Protected Member Functions | |
virtual void | scheme ()=0 |
Stores the database scheme. | |
void | addUpdateRoutine (int toVersion, bool(*functionPointer)(ESqlInit *, QList< ESqlTable * >, QString &)) |
Registers the update routine. | |
ESqlTable * | addTable (QString name, bool appendFieldId=true, bool addPrefix=true) |
Adds a new table to the list of tables. | |
void | addView (QString name, QString selectStatement, bool addPrefix=true) |
Adds a view to the list of views. | |
void | setup (QString name, QString label, int version) |
Setup the needed meta data of this module. | |
![]() | |
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. |
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. | |
void | init () |
Initializes the structure by calling scheme(). |
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 void | connectByPass (QObject *parent, QObject *child) |
![]() | |
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, ...
enum ESqlInit::privileges |
enum ESqlInit::Status |
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
.
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).
|
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.
|
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 |
|
private |
create views statement
view | index of view at QList views; |
QString ESqlInit::databaseName | ( | ) | const |
Returns the database name, currently managed.
|
private |
does the update
|
signal |
Increases the value of the progress bar by 1.
|
private |
Initializes the structure by calling scheme().
It allso adds the standard table "dbmoduleversions" as first table.
QString ESqlInit::label | ( | ) | const |
Returns the label set with setup().
This string is used as a prefix for all tables of this module.
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 |
|
private |
The internal login function
ESqlInit::Status ESqlInit::loginGuiless | ( | bool | loginOnly = true , |
bool | runUpdate = false |
||
) |
|
signal |
Sets the maximum of the progress bar to num
.
|
slot |
|
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().
int ESqlInit::schemaVersion | ( | ) | const |
Returns the schema version set with setup().
|
protectedpure virtual |
Stores the database scheme.
|
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
.
|
privateslot |
initializes the update
|
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
|
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 |