2017-12-09 14:16:47 +01:00
|
|
|
|
#include "QueryParamListController.h"
|
|
|
|
|
|
#include "OpenDatabase.h"
|
2018-12-16 10:17:59 +01:00
|
|
|
|
#include "catalog/PgDatabaseCatalog.h"
|
|
|
|
|
|
#include "catalog/PgTypeContainer.h"
|
2017-12-09 14:16:47 +01:00
|
|
|
|
#include <QTableView>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QueryParamListController::QueryParamListController(QTableView *tv,
|
2017-12-25 10:31:58 +01:00
|
|
|
|
std::shared_ptr<OpenDatabase> opendb, QWidget *parent)
|
2017-12-09 14:16:47 +01:00
|
|
|
|
: QObject(parent)
|
|
|
|
|
|
, paramTableView(tv)
|
|
|
|
|
|
, m_openDatabase(opendb)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (opendb) {
|
|
|
|
|
|
m_typeDelegate.setTypeSelectionModel(opendb->typeSelectionModel());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
paramTableView->setModel(&m_paramList);
|
|
|
|
|
|
paramTableView->setItemDelegateForColumn(1, &m_typeDelegate);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Pgsql::Params QueryParamListController::params() const
|
|
|
|
|
|
{
|
|
|
|
|
|
Pgsql::Params params;
|
2018-11-25 09:05:01 +01:00
|
|
|
|
auto types = m_openDatabase->catalog()->types();
|
2017-12-09 15:46:33 +01:00
|
|
|
|
for (auto e : m_paramList.GetParams()) {
|
2018-12-16 09:24:27 +01:00
|
|
|
|
// some types have two names that are in seperate fields
|
|
|
|
|
|
// this function only checks one field currently :(
|
|
|
|
|
|
// for example integer vs int4, bigint vs int8
|
2019-09-26 20:14:35 +02:00
|
|
|
|
auto type = types->getByName(e.type);
|
|
|
|
|
|
if (type) {
|
|
|
|
|
|
Oid oid = type->oid();
|
|
|
|
|
|
params.add(e.value, oid);
|
|
|
|
|
|
}
|
|
|
|
|
|
throw std::runtime_error("missing type in parameter list");
|
2017-12-09 14:16:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
return params;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool QueryParamListController::empty() const
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
return m_paramList.rowCount() == 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QueryParamListController::on_addParam()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_paramList.insertRows(m_paramList.rowCount(), 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QueryParamListController::on_removeParam()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto rc = m_paramList.rowCount();
|
|
|
|
|
|
if (rc > 0)
|
|
|
|
|
|
m_paramList.removeRows(rc-1, 1);
|
|
|
|
|
|
}
|