103 lines
4.2 KiB
Plaintext
Executable File
103 lines
4.2 KiB
Plaintext
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Template for 'real' structures including insert/update/delete functions for db
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
{% autoescape off %}
|
|
// filename: {{ namespace_abbr }}_db_impl.h
|
|
#pragma once
|
|
|
|
#include <QPointF>
|
|
#include <QString>
|
|
#include <QVector>
|
|
#include <QSqlDriver>
|
|
#include <QSqlDatabase>
|
|
#include <QtSql/QSqlError>
|
|
|
|
#include <{{ include_prefix }}/{{ namespace_abbr }}_enums.hpp>
|
|
#include <{{ include_prefix }}/{{ namespace_abbr }}_db.h>
|
|
#include <{{ include_prefix }}/logger.h>
|
|
|
|
class NSqlQuery;
|
|
namespace {{ namespace }}
|
|
{
|
|
class {{ namespace_abbr_upper }}_COMMON_EXPORT DatabaseInterfaceImpl {% if not custom_db_procs %}final {%endif %}: public DatabaseInterface
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit DatabaseInterfaceImpl(int exerciseId);
|
|
~DatabaseInterfaceImpl();
|
|
|
|
bool init(const QSqlDatabase &dbConnection) override final;
|
|
bool init(const QString &dbUser,
|
|
const QString &dbPasswd,
|
|
const QString &dbDriver,
|
|
const QString &dbHost,
|
|
const QString &dbName) override final;
|
|
|
|
QString schemaName() const override final;
|
|
QString dbUser() const override final;
|
|
const QSqlDatabase &database() const override final { return m_dbConnection; }
|
|
void setEmitMessageOnError(bool bEmit) override final;
|
|
QSqlError getLastError() const override final;
|
|
|
|
{% for cpp_struct in cpp_structs %}
|
|
|
|
// Database::{{ cpp_struct.name }}
|
|
bool insert(Database::{{ cpp_struct.name }} &data) override final;
|
|
bool upsert(Database::{{ cpp_struct.name }} &data) override final;
|
|
bool update(const Database::{{ cpp_struct.name }} &data) override final;
|
|
{% if cpp_struct.insertStructures|length == 1 %}
|
|
bool insert(std::vector<Database::{{ cpp_struct.name }}> &cont) override final;
|
|
bool upsert(std::vector<Database::{{ cpp_struct.name }}> &cont) override final;
|
|
bool update(const std::vector<Database::{{ cpp_struct.name }}> &cont) override final;
|
|
{% endif %}
|
|
bool select(QVector<Database::{{ cpp_struct.name }}> &dataVec) override final;
|
|
bool select(const std::function<void(const Database::{{ cpp_struct.name }} &data)> &cb) override final;
|
|
{% for fk in cpp_struct.selectRemoveMember %}
|
|
bool selectBy{{ fk.cppMemberNameCc }}(QVector<Database::{{ cpp_struct.name }}> &dataVec, const {{ fk.cppType }} &{{ fk.cppMemberName }}, const QString &orderBy = QString()) override final;
|
|
bool selectBy{{ fk.cppMemberNameCc }}(const std::function<void(const Database::{{ cpp_struct.name }} &data)> &cb, const {{ fk.cppType }} &{{ fk.cppMemberName }}, const QString &orderBy = QString()) override final;
|
|
{% endfor %}
|
|
protected:
|
|
bool selectPrepareInternal{{ cpp_struct.name }}(const QString &where);
|
|
bool selectFetchInternal{{ cpp_struct.name }}(const std::function<void(const Database::{{ cpp_struct.name }} &data)> &cb);
|
|
public:
|
|
bool select{{ cpp_struct.name }}({{ cpp_struct.primaryKey.cppType }} {{ cpp_struct.primaryKey.cppMemberName }}, Database::{{ cpp_struct.name }} &data) override final;
|
|
bool remove{{ cpp_struct.name }}({{ cpp_struct.primaryKey.cppType }} {{ cpp_struct.primaryKey.cppMemberName }}) override final;
|
|
{% if cpp_struct.deleteWithoutPkAllowed %} {% for fk in cpp_struct.selectRemoveMember %}
|
|
bool remove{{ cpp_struct.nameCc }}By{{ fk.cppMemberNameCc }}(const {{ fk.cppType }} &{{ fk.cppMemberName }}) override final;
|
|
{% endfor %} {% endif %}
|
|
bool fixUpSequence{{ cpp_struct.name }}() override final;
|
|
bool truncate{{ cpp_struct.name }}() override final;
|
|
// Database::{{ cpp_struct.name }}
|
|
{% endfor %}
|
|
|
|
{% for data_struct in data_structs %}
|
|
// read only struct{{ data_struct.name }}
|
|
bool select(QVector<Database::{{ data_struct.name }}> &dataVec) override final;
|
|
{% endfor %}
|
|
|
|
protected:
|
|
QString getTableName(const QString &tableName) const;
|
|
{% if has_db_notifications %}
|
|
private Q_SLOTS:
|
|
void onNotification(const QString &name, QSqlDriver::NotificationSource source, const QVariant &payload);
|
|
{% endif %}
|
|
protected:
|
|
QSqlDatabase m_dbConnection;
|
|
std::unique_ptr<NSqlQuery> m_query;
|
|
QSqlError m_lastError;
|
|
int m_exerciseId;
|
|
bool m_bEmitMessageOnError;
|
|
bool m_bCanHandleSchemas;
|
|
bool m_ownDatabaseConnection;
|
|
LOGGER_T m_logger;
|
|
private:
|
|
bool initInternal();
|
|
};// class DatabaseInterfaceImpl
|
|
} // namespace {{ namespace }}
|
|
{% endautoescape %}
|