SQL:SELECT Name, Birthday, Birthplace, IDFROM tPersonsWHEREAge > 30ANDName LIKE 'Алекс%'DFD: SqlBatch batch; batch.addSource("tPersons"); batch << SqlField("Name", fv_visible, fr_none, "Имя", 100) << SqlField("Birthday", fv_visible, fr_none, "Дата рождения", 80) << SqlField("Birthplace", fv_visible, fr_none, "Место рождения", 120) << SqlField("ID", fv_invisible, fr_id) << SqlField("Age", SqlValue(30, fo_greater), fp_where) << SqlField("Name", SqlValue("Алекс", fo_like, fb_right), fp_where);
SqlGen gen;QString query = gen.query(batch, sql_select);
#include "abstractmodelhandler.h"using namespace Sql;const QString GLOBAL_PARAMETERS_SOURCE = "ParamS";const int GLOBAL_PARAMETERS = 3335;const int GLOBAL_PARAMETER_CLOSE_PROC = 41;class h_GlobalParametersHandler : public AbstractModelHandler{public: h_GlobalParametersHandler(); bool updateParameter(const SqlValue &oldId, const SqlValue &name, const SqlValue &stringValue, const SqlValue &intValue, const SqlValue &floatValue, const SqlValue &description, const SqlValue &dateBegin, const SqlValue &dateEnd);private: virtual SqlQueryDescriptor _selector(const SqlQueryModelTypes &modelType = mt_plain, const int &queryNumber = 0) const; virtual SqlQueryDescriptor _inserter(const int &queryNumber = 0) const; virtual SqlQueryDescriptor _updater(const int &queryNumber = 0) const; virtual SqlQueryDescriptor _deleter(const int &queryNumber = 0) const; virtual SqlQueryDescriptor _executor(const int &queryNumber = 0) const;};[code]И определение класса:[code]bool h_GlobalParametersHandler::updateParameter(const SqlValue &oldId, const SqlValue &name, const SqlValue &stringValue, const SqlValue &intValue, const SqlValue &floatValue, const SqlValue &description, const SqlValue dateBegin, const SqlValue dateEnd){ h_GlobalParametersHandler th; th.setValue(ID_VALUE, oldId); th.setValue("DateAfter", dateBegin); bool res = th.Exec(GLOBAL_PARAMETER_CLOSE_PROC); Q_ASSERT(res); th.clearValues(); th.setValue("Name", name); th.setValue("StringValue", stringValue); th.setValue("IntValue", intValue); th.setValue("FloatValue", floatValue); th.setValue("Description", description); th.setValue("DateBegin", dateBegin); th.setValue("DateEnd", dateEnd); res = th.Insert(); return res;}SqlQueryDescriptor h_GlobalParametersHandler::_selector(const SqlQueryModelTypes &modelType, const int &queryNumber) const{ SqlBatch batch; batch.addSource("vGlobalParams"); if (queryNumber == GLOBAL_PARAMETERS) { batch << SqlField("ID", fv_invisible, fr_id) << SqlField("Name", fv_visible, fr_none, "Название", 100) << SqlField("StringValue", fv_visible, fr_none, "Строка", 120) << SqlField("IntValue", fv_visible, fr_none, "Целое", 50) << SqlField("FloatValue", fv_visible, fr_none, "Действит.", 70) << SqlField("Description", fv_visible, fr_none, "Описание", 120) << SqlField("vcDateBegin", fv_visible, fr_none, "Начало действия", 100) << SqlField("vcDateEnd", fv_visible, fr_none, "Конец действия", 100) << SqlField("vcIsUsed", fv_visible, fr_none, "Актив.?", 60) << SqlField("DateBegin", fv_invisible) << SqlField("DateEnd", fv_invisible) << SqlField("ID", value(ID_VALUE), fp_where) << SqlField("Name", value("Name"), fp_where) << SqlField("IsUsed", value("IsUsed"), fp_where) << SqlField("DateBegin", value("DateBegin"), fp_where) << SqlField("DateEnd", value("DateEnd"), fp_where); } else if (queryNumber == LAST_ID) { batch << SqlField(MAX_ID, fv_visible, fr_none); } else { Q_ASSERT(false); } return SqlQueryDescriptor(batch, sql_select, queryNumber);}SqlQueryDescriptor h_GlobalParametersHandler::_inserter(const int &queryNumber) const{ SqlBatch batch; batch.addSource("tGlobalParams"); batch << SqlField("Name", value("Name"), fp_insert) << SqlField("StringValue", value("StringValue"), fp_insert) << SqlField("IntValue", value("IntValue"), fp_insert) << SqlField("FloatValue", value("FloatValue"), fp_insert) << SqlField("Description", value("Description"), fp_insert) << SqlField("DateBegin", value("DateBegin"), fp_insert) << SqlField("DateEnd", value("DateEnd"), fp_insert); return SqlQueryDescriptor(batch, sql_insert, queryNumber);}SqlQueryDescriptor h_GlobalParametersHandler::_updater(const int &queryNumber) const{ SqlBatch batch; batch.addSource("tGlobalParams"); batch << SqlField("Name", value("Name"), fp_update) << SqlField("StringValue", value("StringValue"), fp_update) << SqlField("IntValue", value("IntValue"), fp_update) << SqlField("FloatValue", value("FloatValue"), fp_update) << SqlField("Description", value("Description"), fp_update) << SqlField("DateBegin", value("DateBegin"), fp_update) << SqlField("DateEnd", value("DateEnd"), fp_update) << SqlField("ID", value(ID_VALUE, SqlValue(nt_null)), fp_where); return SqlQueryDescriptor(batch, sql_update, queryNumber);}SqlQueryDescriptor h_GlobalParametersHandler::_deleter(const int &queryNumber) const{ SqlBatch batch; batch.addSource("tGlobalParams"); batch << SqlField("ID", value(ID_VALUE, SqlValue(nt_null)), fp_where); return SqlQueryDescriptor(batch, sql_delete, queryNumber);}SqlQueryDescriptor h_GlobalParametersHandler::_executor(const int &queryNumber) const{ SqlBatch batch; if (queryNumber == GLOBAL_PARAMETER_CLOSE_PROC) { batch.addSource("pCloseGlobalParameter"); batch << SqlValue(value(ID_VALUE, SqlValue(nt_null))) << SqlValue(value("DateAfter")); } else { Q_ASSERT(false); } return SqlQueryDescriptor(batch, sql_execute, queryNumber);}
h_GlobalParametersHandler _handlerSqlQueryModel _model;
void f_GlobalParametersForm::loadParameters(){// Загружаем источник данных. Берем select-запрос из h_GlobalParametersHandler::_selector() с номером GLOBAL_PARAMETERS. _handler.reloadSource(GLOBAL_PARAMETERS_SOURCE, GLOBAL_PARAMETERS, &_model);// Настраиваем tableView на источник данных. Названия колонок, их ширина, ориентация, - все берется из описателя DFD, сформированного функцией _selector с номером запроса GLOBAL_PARAMETERS и типом модели mt_plain (если бы использовался TreeView, тип модели был бы mt_tree). _handler.setTableView(GLOBAL_PARAMETERS_SOURCE, ui->tv_Parameters);}SqlValue f_GlobalParametersForm::parameterID() const{// Ключевое значение текущей строки во view. return _handler.keyValueOfView(GLOBAL_PARAMETERS_SOURCE);}// Удаление текущей строки во view из БД.void f_GlobalParametersForm::deleteParameter(){ d_ConfirmDialog dlg; if (dlg.exec() == QDialog::Accepted) { _handler.DeleteCurrent(GLOBAL_PARAMETERS_SOURCE, ui->tv_Parameters); loadParameters(); }}