DbStruct Pile   version 0.0.1
This pile contains classes that can be used to
dbrecord.h
Go to the documentation of this file.
1 
10 #ifndef GUARD_DBRECORD_H_INCLUDE
11 #define GUARD_DBRECORD_H_INCLUDE
12 
13 #include <dbstruct/dbstruct-config.h>
14 #include <dbstruct/dbobject.h>
15 #include <dbstruct/dbcolumn.h>
16 #include <assert.h>
17 
18 #include <QMap>
19 #include <QString>
20 #include <QVariant>
21 
22 QT_BEGIN_NAMESPACE
23 class QSqlDatabase;
24 class QSqlQuery;
25 class QSqlRecord;
26 QT_END_NAMESPACE
27 
28 class DbTable;
29 class DbTaew;
30 
31 typedef QMap<QString, QVariant> DbRecMap;
32 
34 class DBSTRUCT_EXPORT DbRecord {
35 
36 public:
37 
39  DbRecord ();
40 
42  virtual ~DbRecord();
43 
45  virtual DbObject::Type
46  type () const {
47  return DbObject::DBO_RECORD;
48  }
49 
51  bool
52  initFromId (
53  DbTaew * table,
54  QSqlDatabase & db,
55  long db_id);
56 
58  bool
59  initFrom (
60  DbTaew * table,
61  QSqlDatabase & db,
62  int column);
63 
65  virtual bool
66  save (
67  DbTaew * table,
68  QSqlDatabase & db);
69 
71  bool
72  remFromDb (
73  DbTaew * table,
74  QSqlDatabase &db,
75  int column);
76 
78  virtual bool
79  isNew () const {
80  return getId() < 0;
81  }
82 
84  virtual void
85  bindOne (
86  QSqlQuery & query,
87  int i) const = 0;
88 
90  virtual void
91  bind (
92  QSqlQuery & query) const = 0;
93 
95  virtual DbRecMap
96  toMap () const = 0;
97 
99  virtual bool
100  retreive (
101  const QSqlQuery & query) = 0;
102 
104  virtual bool
105  retreive (
106  const QSqlRecord & rec) = 0;
107 
109  virtual bool
110  retreive (
111  const DbRecMap & map) = 0;
112 
114  virtual void
116  long /*value*/) {
117  // by default do nothing
118  }
119 
121  virtual long
122  getId () const;
123 
124 
125 protected:
126 
127 private:
128 };
129 
130 #endif // GUARD_DBRECORD_H_INCLUDE
virtual void setId(long)
Set the index to given value (if the model has an id column).
Definition: dbrecord.h:115
A record in a database.
Definition: dbrecord.h:34
Definition: dbobject.h:38
virtual DbObject::Type type() const
The type of this object.
Definition: dbrecord.h:46
virtual bool isNew() const
Tell if this instance is a new one or it has a database correspondent.
Definition: dbrecord.h:79
Declarations for DbColumn class.
A table in a database.
Definition: dbtable.h:22
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