2018-09-09 18:52:32 +02:00
|
|
|
|
#ifndef CODEBUILDER_H
|
|
|
|
|
|
#define CODEBUILDER_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "Pgsql_declare.h"
|
|
|
|
|
|
#include <QString>
|
2018-09-18 11:53:19 +02:00
|
|
|
|
#include <vector>
|
2018-09-09 18:52:32 +02:00
|
|
|
|
|
|
|
|
|
|
class LanguageConfig;
|
|
|
|
|
|
class QTextStream;
|
|
|
|
|
|
|
|
|
|
|
|
class CodeBuilder {
|
|
|
|
|
|
public:
|
2018-09-19 09:55:43 +02:00
|
|
|
|
class ColumnData {
|
|
|
|
|
|
public:
|
|
|
|
|
|
Oid oid;
|
|
|
|
|
|
QString columnName;
|
|
|
|
|
|
QString varName; ///< either field of the struct or in loop local var name
|
|
|
|
|
|
};
|
|
|
|
|
|
using ColumnDataList = std::vector<ColumnData>;
|
|
|
|
|
|
|
|
|
|
|
|
ColumnDataList createColumnDataList(const Pgsql::Result &result) const;
|
|
|
|
|
|
|
2018-09-18 11:53:19 +02:00
|
|
|
|
void setLanguageConfig(std::shared_ptr<const LanguageConfig> config){
|
|
|
|
|
|
m_configuration = config;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GenCodeForExecutingQuery(QTextStream &q, const QString &query, const Pgsql::Result &result, QString structname);
|
2018-09-19 09:55:43 +02:00
|
|
|
|
void GenReturnStructDefinition(QTextStream &q, const ColumnDataList &columns, QString structname) const;
|
2018-09-09 18:52:32 +02:00
|
|
|
|
|
|
|
|
|
|
// Generating code for performing query and going through the result
|
|
|
|
|
|
// - Code for executing the query
|
|
|
|
|
|
// - Code for looping the result
|
|
|
|
|
|
// - Code for processing a single row
|
|
|
|
|
|
// - Declaration of struct for holding single row result
|
|
|
|
|
|
QString columnNameToVariableName(QString column_name) const;
|
|
|
|
|
|
QString getTypeName(Oid dbtype) const;
|
|
|
|
|
|
private:
|
2018-09-18 11:53:19 +02:00
|
|
|
|
|
2018-09-09 18:52:32 +02:00
|
|
|
|
std::shared_ptr<const LanguageConfig> m_configuration;
|
|
|
|
|
|
|
2018-09-19 09:55:43 +02:00
|
|
|
|
void genStructFields(QTextStream &q, const ColumnDataList &columns) const;
|
|
|
|
|
|
void genFieldRetrieval(QTextStream &q, const ColumnDataList &columns) const;
|
|
|
|
|
|
void genFieldDeclaration(QTextStream &q, const QString &format, const QString &field_name, Oid column_type) const;
|
2018-09-18 11:53:19 +02:00
|
|
|
|
|
2018-09-09 18:52:32 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CODEBUILDER_H
|