Nut  0.1
 All Classes Functions
sqlgeneratorbase_p.h
1 /**************************************************************************
2 **
3 ** This file is part of Nut project.
4 ** https://github.com/HamedMasafi/Nut
5 **
6 ** Nut is free software: you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published by
8 ** the Free Software Foundation, either version 3 of the License, or
9 ** (at your option) any later version.
10 **
11 ** Nut is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU Lesser General Public License for more details.
15 **
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with Nut. If not, see <http://www.gnu.org/licenses/>.
18 **
19 **************************************************************************/
20 
21 #ifndef SQLGENERATORBASE_H
22 #define SQLGENERATORBASE_H
23 
24 #include <QtCore/qglobal.h>
25 #include <QtCore/QObject>
26 #include <QtCore/QStringList>
27 #include "wherephrase.h"
28 
29 QT_BEGIN_NAMESPACE
30 
31 class Table;
32 struct FieldModel;
33 class DatabaseModel;
34 class TableModel;
35 class Database;
36 //struct PhraseData;
37 //class WherePhrase;
38 class SqlGeneratorBase : public QObject
39 {
40 // Q_OBJECT
41 
42  Database *_database;
43 public:
44  enum CommandType{
45  Select,
46  Insert,
47  Update,
48  Delete
49  };
50  enum AgregateType{
51  SelectALl,
52  Count,
53  Min,
54  Max,
55  Average
56  };
57 
58  SqlGeneratorBase(Database *parent);
59  virtual ~SqlGeneratorBase();
60 
61  virtual QString masterDatabaseName(QString databaseName);
62 
63  virtual QString fieldType(FieldModel *field) = 0;
64  virtual QString fieldDeclare(FieldModel *field);
65 
66  virtual QStringList diff(DatabaseModel lastModel, DatabaseModel newModel);
67  virtual QString diff(FieldModel *oldField, FieldModel *newField);
68  virtual QString diff(TableModel *oldTable, TableModel *newTable);
69 
70  virtual QString saveRecord(Table *t, QString tableName);
71  virtual QString insertRecord(Table *t, QString tableName);
72  virtual QString updateRecord(Table *t, QString tableName);
73  virtual QString deleteRecord(Table *t, QString tableName);
74 
75 
76  virtual QString deleteRecords(QString tableName, QString where);
77 
78  virtual QString selectCommand(AgregateType t, QString agregateArg,
79  QList<WherePhrase> &wheres, QList<WherePhrase> &orders,
80  QString tableName, QString joinClassName);
81 
82  virtual QString selectCommand(QList<WherePhrase> &wheres, QHash<QString, QString> &orders,
83  QString tableName, QString joinClassName);
84  virtual QString selectCommand(QString selectPhrase,
85  QList<WherePhrase> &wheres, QHash<QString, QString> &orders,
86  QString tableName, QString joinClassName);
87 
88  virtual QString deleteCommand(QList<WherePhrase> &wheres, QString tableName);
89 
90  virtual QString escapeValue(const QVariant &v) const;
91  virtual QString phrase(const PhraseData *d) const;
92  virtual QString operatorString(const PhraseData::Condition &cond) const;
93 
94 private:
95  QString agregateText(const AgregateType &t, const QString &arg = QString::null) const;
96  QString fromTableText(const QString &tableName, QString &joinClassName, QString &orderBy) const;
97  QString createWhere(QList<WherePhrase> &wheres);
98  QString phraseOrder(const PhraseData *d) const;
99 };
100 
101 QT_END_NAMESPACE
102 
103 #endif // SQLGENERATORBASE_H