LibEngsas
esqlinit.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2012 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17  MA 02110-1301 USA.
18 */
19 
20 #ifndef ESQLINIT_H
21 #define ESQLINIT_H
22 
23 #include "eglobal.h"
24 #include "eobject.h"
25 
26 #include "esqltable.h"
27 // #include "esqlfield.h"
28 #include "esqldatabase.h"
29 
84 {
85  Q_OBJECT
86  public:
91  enum privileges { SELECT, INSERT, UPDATE, DEL, CREATE, ALTER };
92  enum Status { BadSettings, LoggedIn, LoginFailed, UpdateNeeded, UpdateFailed, NoUpdateNeeded };
93 
94  ESqlInit ( QObject *parent = 0,
95  QString username = QString(), QString host = QString(),
96  QString database = QString(), QString driver = QString(),
97  QString password = QString());
98  virtual ~ESqlInit();
108  ESqlInit::Status login(bool loginOnly = true, bool runUpdate = false);
109  ESqlInit::Status loginGuiless(bool loginOnly = true, bool runUpdate = false);
110 
116  QString label() const;
121  int schemaVersion() const;
125  QString databaseName() const;
132  void addInformation(QString msg);
133 
134  public slots:
135  void reloadSettings();
136 
137  protected:
142  virtual void scheme() = 0;
176  void addUpdateRoutine(int toVersion, bool (*functionPointer)(ESqlInit *, QList<ESqlTable*>, QString&) );
177 
187  ESqlTable *addTable ( QString name, bool appendFieldId = true, bool addPrefix = true );
196  void addView( QString name, QString selectStatement, bool addPrefix = true );
204  void setup(QString name, QString label, int version);
205 
206  private slots:
210  bool updateDb();
211 
212  private:
216  ESqlInit::Status login(bool loginOnly, bool runUpdate, bool enableGui);
222  bool updateNeeded();
226  bool doUpdate();
237  bool compareTables ( ESqlTable *table, QString &errorString, bool create = false );
246  bool compareViews ( QStringList view, QString &errorString, bool create = false );
252  QString createViewStatement ( QStringList view );
253 
266  bool runUpdateRoutines(int fromVersion, QString& errorString, int toVersion);
267 
273  void init();
274 
275  QString dbName, versionTable;
276  bool transactions, gui;
278  QList<ESqlInit::privileges> neededPrivs;
280  QString username, password, host, driver;
289  QString thisName;
290  QString moduleLabel;
294  QList<ESqlTable*> tables;
295  QList<QStringList> views;
301  QMap<int, bool (*)(ESqlInit *, QList<ESqlTable*>, QString&)> updateRoutines;
302 
303  signals:
307  void actualStep ( QString msg );
311  void finishedStep();
315  void neededSteps ( int num );
316 };
317 
318 #endif // ESQLINIT_H
Mostly the same as EWidget but for QObject as base class.
Definition: eobject.h:42
EngSaS::SQL::DatabaseType dbType
Definition: esqlinit.h:277
QList< ESqlTable * > tables
Definition: esqlinit.h:294
QString username
Definition: esqlinit.h:280
bool transactions
Definition: esqlinit.h:276
virtual void reloadSettings()
Used to reload the settings.
Definition: eobject.h:81
QList< QStringList > views
Definition: esqlinit.h:295
#define E_CORE_EXPORT
Definition: eglobal.h:107
ESqlDatabase db
Definition: esqlinit.h:281
int currentVersion
Definition: esqlinit.h:285
An improved QSqlDatabase class.
Definition: esqldatabase.h:35
QString thisName
Definition: esqlinit.h:289
int actVersion
Definition: esqlinit.h:279
Represents an sql table.This class is used with ESqlInit to define database schemas.
Definition: esqltable.h:40
QString versionTable
Definition: esqlinit.h:275
privileges
Definition: esqlinit.h:91
QString moduleLabel
Definition: esqlinit.h:290
Definition: esqlinit.h:91
Class to manage database structures.This class is able to create and modify complexe database structu...
Definition: esqlinit.h:83
QList< ESqlInit::privileges > neededPrivs
Definition: esqlinit.h:278
Status
Definition: esqlinit.h:92
Definition: esqlinit.h:92
DatabaseType
Choose the type of the used database.
Definition: eglobal.h:181