TreeFrogFramework  1.18
tsqlobject.h
Go to the documentation of this file.
1 #ifndef TSQLOBJECT_H
2 #define TSQLOBJECT_H
3 
4 #include <QObject>
5 #include <QSqlRecord>
6 #include <QSqlError>
7 #include <QDateTime>
8 #include <QVariantMap>
9 #include <QStringList>
10 #include <TGlobal>
11 #include <TModelObject>
12 
13 
14 class T_CORE_EXPORT TSqlObject : public TModelObject, public QSqlRecord
15 {
16  Q_OBJECT
17 public:
18  TSqlObject();
19  TSqlObject(const TSqlObject &other);
20  TSqlObject &operator=(const TSqlObject &other);
21  virtual ~TSqlObject() { }
22 
23  virtual QString tableName() const;
24  virtual int primaryKeyIndex() const { return -1; }
25  virtual int autoValueIndex() const { return -1; }
26  virtual int databaseId() const { return 0; }
27  void setRecord(const QSqlRecord &record, const QSqlError &error);
28  bool create() override;
29  bool update() override;
30  bool save() override;
31  bool remove() override;
32  bool reload();
33  bool isNull() const override { return QSqlRecord::isEmpty(); }
34  bool isNew() const { return QSqlRecord::isEmpty(); }
35  bool isModified() const;
36  void clear() { QSqlRecord::clear(); }
37  QSqlError error() const { return sqlError; }
38 
39 protected:
40  void syncToSqlRecord();
41  void syncToObject();
42  QSqlError sqlError;
43 };
44 
45 #endif // TSQLOBJECT_H
#define T_CORE_EXPORT
Definition: tglobal.h:81
bool isNull() const override
Returns true if there is no database record associated with the object; otherwise returns false...
Definition: tsqlobject.h:33
QSqlError sqlError
Definition: tsqlobject.h:42
virtual int primaryKeyIndex() const
Returns the position of the primary key field on the table.
Definition: tsqlobject.h:24
virtual bool save()=0
void clear()
Clears the contents of the object.
Definition: tsqlobject.h:36
The TModelObject class provides an abstract base for model objects.
Definition: tmodelobject.h:11
virtual bool create()=0
virtual int autoValueIndex() const
Returns the position of the auto-generated value field on the table.
Definition: tsqlobject.h:25
The TSqlObject class is the base class of ORM objects.
Definition: tsqlobject.h:14
bool isNew() const
Returns true if it is a new object, otherwise returns false.
Definition: tsqlobject.h:34
virtual int databaseId() const
Returns the database ID.
Definition: tsqlobject.h:26
virtual ~TSqlObject()
Definition: tsqlobject.h:21
virtual bool update()=0
QSqlError error() const
Returns a QSqlError object which contains information about the last error that occurred on the datab...
Definition: tsqlobject.h:37