Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
getsinglevalue.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2024 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8#include "getsinglevalue.h"
9
10#include <QSqlQuery>
11
12namespace QH {
13
14
15namespace PKG {
16
18 const QString& field,
19 const QString& primaryKey) {
20
21 _table = address.table();
22 _primaryValue = address.id();
23 _field = field;
24 _primaryKey = primaryKey;
25}
26
27QVariant GetSingleValue::value() const {
28 return _value;
29}
30
32 return create<GetSingleValue>(dbAddress(), _field);
33}
34
36 QString queryString = "SELECT %0 FROM %1 WHERE %2=:%2";
37 queryString = queryString.arg(_field, table(), _primaryKey);
38
39 if (!q.prepare(queryString)) {
41 }
42
43 q.bindValue(":" + _primaryKey, _primaryValue);
44
46}
47
48bool GetSingleValue::fromSqlRecord(const QSqlRecord &q) {
49 _value = q.value(0);
50
51 return true;
52}
53
55 return false;
56}
57
58QString GetSingleValue::table() const {
59 return _table;
60}
61
63 return _primaryKey;
64}
65
67 return _primaryValue;
68}
69
70}
71}
The DbAddress class use to work with database addresses. Database Address it is structure with 2 valu...
Definition dbaddress.h:24
const QString & table() const
table This method return table name.
Definition dbaddress.cpp:58
const QVariant & id() const
id This method return id of object in table.
Definition dbaddress.cpp:67
The DBObject class- main class for work with data base.
Definition dbobject.h:94
DbAddress dbAddress() const
dbAddress This method return address of the database object. IF the object is not valid then this met...
Definition dbobject.cpp:242
GetSingleValue(const DbAddress &address, const QString &field, const QString &primaryKey="id")
GetSingleValue This is default constructor of the GetMaxIntegerId class.
QString table() const override
table This method should be return name of the database table that should be contains objects with th...
bool isCached() const override
isCached This method sholud be return status of object. If this method return true then this object c...
QVariant primaryValue() const override
primaryValue This method is wraper of DBAddress::id. If This object do not contains a id value then r...
DBObject * createDBObject() const override
createDBObject This method should be create a object with the some type as the object called this met...
QVariant value() const
value This method return Maximum value of a sql tables field.
bool fromSqlRecord(const QSqlRecord &q) override
fromSqlRecord This method should be initialize this object from the executed sqlRecord....
PrepareResult prepareSelectQuery(QSqlQuery &q) const override
prepareSelectQuery This method should be prepare a query for selected data. Override this method for ...
QString primaryKey() const override
primaryKey This method must be return the name of primary key of this object table....
PrepareResult
The PrepareResult enum is result of work prepare sql query of dbobjects.
Definition dbobject.h:24
@ Success
prepare finished successful.
@ Fail
prepare is failed.
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13