This repository was archived by the owner on Dec 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbrecord.h
More file actions
134 lines (106 loc) · 2.84 KB
/
dbrecord.h
File metadata and controls
134 lines (106 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* @file dbrecord.h
* @brief Declarations for DbRecord class
* @author Nicu Tofan <nicu.tofan@gmail.com>
* @copyright Copyright 2015 piles contributors. All rights reserved.
* This file is released under the
* [MIT License](http://opensource.org/licenses/mit-license.html)
*/
#ifndef GUARD_DBRECORD_H_INCLUDE
#define GUARD_DBRECORD_H_INCLUDE
#include <dbstruct/dbstruct-config.h>
#include <dbstruct/dbobject.h>
#include <dbstruct/dbcolumn.h>
#include <assert.h>
#include <QMap>
#include <QString>
#include <QVariant>
QT_BEGIN_NAMESPACE
class QSqlDatabase;
class QSqlQuery;
class QSqlRecord;
QT_END_NAMESPACE
class DbTable;
class DbTaew;
typedef QMap<QString, QVariant> DbRecMap;
//! A record in a database.
class DBSTRUCT_EXPORT DbRecord {
public:
//! Default constructor.
DbRecord ();
//! Destructor.
virtual ~DbRecord();
//! The type of this object.
virtual DbObject::Type
type () const {
return DbObject::DBO_RECORD;
}
//! Initialize this instance from a given id.
virtual bool
initFromId (
DbTaew * table,
QSqlDatabase & db,
long db_id);
//! Initialize this instance from a given field
virtual bool
initFrom (
DbTaew * table,
QSqlDatabase & db,
int column);
//! Saves the instance to the database.
virtual bool
save (
DbTaew * table,
QSqlDatabase & db);
//! Remove this entry from the database.
bool
remFromDb (
DbTaew * table,
QSqlDatabase &db,
int column,
const QString & s_col_value);
//! Tell if this instance is a new one or it has a database correspondent.
virtual bool
isNew () const {
return getId() < 0;
}
//! Bind a single value identified by column index in a query.
virtual void
bindOne (
QSqlQuery & query,
int i) const = 0;
//! Bind values to names in a query.
virtual void
bind (
QSqlQuery & query) const = 0;
//! Export the content of a record to a map.
virtual DbRecMap
toMap () const = 0;
//! Get values from a query.
virtual bool
retrieve (
const QSqlQuery & query,
QSqlDatabase & db) = 0;
//! Get values from a record.
virtual bool
retrieve (
const QSqlRecord & rec,
QSqlDatabase & db) = 0;
//! Load values from an associative array.
virtual bool
retrieve (
const DbRecMap & map,
QSqlDatabase & db) = 0;
//! Set the index to given value (if the model has an id column).
virtual void
setId (
long /*value*/) {
// by default do nothing
}
//! Get the index of this instance (if the model has an id column).
virtual long
getId () const;
protected:
private:
};
#endif // GUARD_DBRECORD_H_INCLUDE