DbStruct Pile   version 0.0.1
This pile contains classes that can be used to
dbstruct.h
Go to the documentation of this file.
1 
10 #ifndef GUARD_DBSTRUCT_H_INCLUDE
11 #define GUARD_DBSTRUCT_H_INCLUDE
12 
13 #include <dbstruct/dbstruct-config.h>
14 #include <dbstruct/dbobject.h>
15 #include <dbstruct/dbtable.h>
16 #include <dbstruct/dbview.h>
17 
18 #include <QSqlDatabase>
19 
20 class DbTaew;
21 
23 class DBSTRUCT_EXPORT DbStructMeta : public DbObject {
24 
25 public:
26 
28  DbStructMeta ();
29 
31  virtual ~DbStructMeta();
32 
34  virtual Type
35  type () const {
36  return DBO_STRUCT;
37  }
38 
40  virtual DbTaew *
41  taew (
42  const QString & value) {
43  return taew (idFromName (value));
44  }
45 
46 
47  /* - - - - - - - - - - - - - - - - */
52 
55  virtual QString
56  databaseName () const = 0;
57 
59  virtual QString
60  componentName (
61  int index) const = 0;
62 
64  virtual int
65  idFromName (
66  const QString & value) const = 0;
67 
69  virtual DbTaew *
70  taew (
71  int index) const = 0;
72 
73 
74  /* -- T A B L E S -- */
75 
77  virtual int
78  comp2table (
79  int value) const = 0;
80 
82  virtual int
83  table2comp (
84  int value) const = 0;
85 
87  virtual int
88  tableIdFromName (
89  const QString & value) const = 0;
90 
92  virtual QString
93  tableName (
94  int index) const = 0;
95 
96 
97  /* -- V I E W S -- */
98 
100  virtual int
101  comp2view (
102  int value) const = 0;
103 
105  virtual int
106  view2comp (
107  int value) const = 0;
108 
110  virtual int
111  viewIdFromName (
112  const QString & value) const = 0;
113 
114 
116  virtual QString
117  viewName (
118  int index) const = 0;
119 
121  /* - - - - - - - - - - - - - - - - */
122 
123 protected:
124 
125 private:
126 }; /* class DbStructMeta */
127 
128 
130 class DBSTRUCT_EXPORT DbStruct {
131 
132  QSqlDatabase db_;
134 public:
135 
138  db_()
139  {}
140 
142  DbStruct(const QSqlDatabase & db) :
143  db_(db)
144  {}
145 
147  inline QSqlDatabase &
148  database () {
149  return db_;
150  }
151 
153  inline void
154  setDatabase (const QSqlDatabase & value) {
155  db_ = value;
156  }
157 
159  virtual DbStructMeta *
160  metaDatabase () = 0;
161 
162 }; /* class DbStructMeta */
163 
165 #define META_DATA_BASE_CTORS(__name__) \
166  __name__() : __name__ ## Meta(), DbStruct() {} \
167  __name__(const QSqlDatabase & db) : __name__ ## Meta(), DbStruct(db) {}
168 
170 #define META_DATA_BASE_GETTER \
171  virtual DbStructMeta * \
172  metaDatabase () { \
173  return static_cast<DbStructMeta*>(this); \
174  }
175 
177 #define META_DATA_BASE(__name__) \
178 class %(EXPORT)s __name__ : public __name__ ## Meta, public DbStruct { \
179 public: \
180  META_DATA_BASE_CTORS(__name__); \
181  META_DATA_BASE_GETTER; \
182 };
183 
184 
185 #endif // GUARD_DBSTRUCT_H_INCLUDE
Definition: dbobject.h:36
virtual Type type() const
The type of this object.
Definition: dbstruct.h:35
DbStruct()
Default constructor.
Definition: dbstruct.h:137
Declarations for DbView class.
Declarations for DbTable class.
The structure of a database.
Definition: dbstruct.h:23
void setDatabase(const QSqlDatabase &value)
Set the database.
Definition: dbstruct.h:154
virtual DbTaew * taew(const QString &value)
Create a table or view based on a table or view name.
Definition: dbstruct.h:41
Declarations for DbObject class.
Type
The types of objects that use this class as a base.
Definition: dbobject.h:33
A table or view in a database.
Definition: dbtaew.h:24
QSqlDatabase & database()
Retreive the database.
Definition: dbstruct.h:148
The objecture of a database.
Definition: dbobject.h:28
The structure of a database.
Definition: dbstruct.h:130
DbStruct(const QSqlDatabase &db)
Constructor that also initializes the database.
Definition: dbstruct.h:142