LibEngsas
esqltable.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 ESQLTABLE_H
21 #define ESQLTABLE_H
22 
23 #include "eglobal.h"
24 
25 #include "esqlfield.h"
26 
27 #include <QString>
28 #include <QStringList>
29 #include <QMultiHash>
30 
41 {
42  Q_OBJECT
43  public:
47  enum FkAction {
51  Restrict
52  };
53 
54  ESqlTable ( QString name = "" );
55  ~ESqlTable();
56  bool isValid();
57  QString name();
58  void setName ( QString name );
59  QList<ESqlField*> fields();
60  void appendField ( ESqlField *append );
66  ESqlField *appendField ( QString name = "", ESqlField::Type type = ESqlField::NoType, bool notNull = false, bool autoIncrement = false );
73  void appendFieldId (QString name = "id");
83  ESqlField * appendFieldVarchar ( QString name = "", uint length = 45, bool notNull = false );
84 
85  bool appendValues ( QStringList value );
86  QList<QStringList> values();
97  void addForeignKey ( QString fieldName,
98  QString refTable,
99  QString refFieldName = "id",
112  void addForeignKey ( ESqlField *ourField, ESqlTable *refTable,
128  void addForeignKey ( ESqlTable *refTable,
129  QString newFieldName = QString(),
132  QString idFieldName = "id" );
133  QString sqlConstraintsString ( EngSaS::SQL::DatabaseType type = EngSaS::SQL::Other );
137  void addIndex ( QString fieldName, unsigned int length = 0, Qt::SortOrder order = Qt::AscendingOrder );
143  void addIndex ( ESqlField *field, unsigned int length = 0, Qt::SortOrder order = Qt::AscendingOrder );
144  QString indizes();
145 
153  QString createStatement(QString dbName, EngSaS::SQL::DatabaseType type);
154 
155  private:
156  QString tableName;
157  QList<ESqlField*> myFields;
158  QList<QStringList> myValues;
159  QList<QStringList> constraints;
160  QStringList myIndizes;
161  QMultiHash<ESqlTable::FkAction, QString> fkActionMap;
162 };
163 
164 #endif // ESQLTABLE_H
Mostly the same as EWidget but for QObject as base class.
Definition: eobject.h:42
Definition: esqltable.h:49
QStringList myIndizes
Definition: esqltable.h:160
Definition: esqltable.h:50
Definition: eglobal.h:182
QList< ESqlField * > myFields
Definition: esqltable.h:157
#define E_CORE_EXPORT
Definition: eglobal.h:107
QList< QStringList > myValues
Definition: esqltable.h:158
Definition: esqlfield.h:43
QString tableName
Definition: esqltable.h:156
Represents an sql table.This class is used with ESqlInit to define database schemas.
Definition: esqltable.h:40
Definition: esqltable.h:48
Type
Definition: esqlfield.h:43
QList< QStringList > constraints
Definition: esqltable.h:159
QMultiHash< ESqlTable::FkAction, QString > fkActionMap
Definition: esqltable.h:161
Represents an field in an sql table.This class is used with ESqlInit to define database schemas...
Definition: esqlfield.h:39
DatabaseType
Choose the type of the used database.
Definition: eglobal.h:181
FkAction
Actions, which are done, if an foreign key is changed.
Definition: esqltable.h:47