/** * @RDE_HEADER@ * Template for 'real' structures including insert/update/delete functions for db * $Id: svc_db_impl.h.grantlee 53676 2021-06-10 10:21:06Z diers $ * $HeadURL: svn://192.168.133.21/TDS/branches/product/features/25_02_refactoring/Lts/Common/CodeGen/svc_db_impl.h.grantlee $ * $Author: diers $ */ {% autoescape off %} // filename: {{ namespace_abbr }}_dao.h #pragma once #include #include #include #include #include #include #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 Dao {% if not custom_db_procs %}final {%endif %}: public QObject { Q_OBJECT public: explicit Dao(int exerciseId); ~Dao(); bool init(const QString &dbUser, const QString &dbPasswd, const QString &dbDriver, const QString &dbHost, const QString &dbName); QString schemaName() const; QString dbUser() const; const QSqlDatabase &database() const { return m_dbConnection; } void setEmitMessageOnError(bool bEmit); QSqlError getLastError() const; {% for cpp_struct in cpp_structs %} // --> Database::{{ cpp_struct.name }} public: bool select(QVector &dataVec, const QString &where = QString()); private: bool selectPrepareInternal{{ cpp_struct.name }}(const QString &where); bool selectFetchInternal{{ cpp_struct.name }}(const std::function &cb); // <-- Database::{{ cpp_struct.name }} {% endfor %} static QString qVariantToJsonString(const QVariant &value); 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); Q_SIGNALS: {% for cpp_struct in cpp_structs %}{% for db_notify in cpp_struct.dbNotifications %} void signal{{ db_notify }}(int id); {% endfor %}{% endfor %}{% endif %} protected: QSqlDatabase m_dbConnection; std::unique_ptr 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 Dao } // namespace {{ namespace }} {% endautoescape %}