예제 #1
0
void SQLExecutionWidget::fillResultsTable(ResultSet &res)
{
	try
	{
    Catalog catalog;
    Connection aux_conn=sql_cmd_conn;

		row_cnt_lbl->setText(QString::number(res.getTupleCount()));
		export_tb->setEnabled(res.getTupleCount() > 0);

		catalog.setConnection(aux_conn);
    fillResultsTable(catalog, res, results_tbw);
	}
	catch(Exception &e)
	{
		throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
  }
}
예제 #2
0
void SQLToolWidget::fillResultsTable(ResultSet &res)
{
    try
    {
        int col=0, row=0, row_cnt=res.getTupleCount(), col_cnt=res.getColumnCount();
        QTableWidgetItem *item=nullptr;

        row_cnt_lbl->setText(QString::number(row_cnt));
        export_tb->setEnabled(row_cnt > 0);
        results_tbw->setRowCount(0);
        results_tbw->setColumnCount(col_cnt);

        //Configuring the grid columns with the names of retrived table columns
        for(col=0; col < col_cnt; col++)
            results_tbw->setHorizontalHeaderItem(col, new QTableWidgetItem(res.getColumnName(col)));

        if(res.accessTuple(ResultSet::FIRST_TUPLE))
        {
            results_tbw->setRowCount(row_cnt);

            do
            {
                //Fills the current row with the values of current tuple
                for(col=0; col < col_cnt; col++)
                {
                    item=new QTableWidgetItem;

                    if(res.isColumnBinaryFormat(col))
                        item->setText(trUtf8("[binary data]"));
                    else
                        item->setText(res.getColumnValue(col));

                    results_tbw->setItem(row, col, item);
                }

                //Configure the vertical header to show the current tuple id
                results_tbw->setVerticalHeaderItem(row, new QTableWidgetItem(QString::number(row + 1)));
                row++;
            }
            while(res.accessTuple(ResultSet::NEXT_TUPLE));
        }

        results_tbw->resizeColumnsToContents();
    }
    catch(Exception &e)
    {
        throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
    }
}
예제 #3
0
unsigned Catalog::getObjectCount(ObjectType obj_type, const QString &sch_name, const QString &tab_name, attribs_map extra_attribs)
{
    try
    {
        ResultSet res;

        extra_attribs[ParsersAttributes::SCHEMA]=sch_name;
        extra_attribs[ParsersAttributes::TABLE]=tab_name;

        executeCatalogQuery(QUERY_LIST, obj_type, res, false, extra_attribs);
        res.accessTuple(ResultSet::FIRST_TUPLE);
        return(res.getTupleCount());
    }
    catch(Exception &e)
    {
        throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
    }
}
예제 #4
0
void SQLToolWidget::runSQLCommand(void)
{
    try
    {
        ResultSet res;
        QString cmd=sql_cmd_txt->textCursor().selectedText();

        if(cmd.isEmpty())
            cmd=sql_cmd_txt->toPlainText();

        sql_cmd_conn.executeDMLCommand(cmd, res);
        registerSQLCommand(cmd);

        results_parent->setVisible(!res.isEmpty());
        export_tb->setEnabled(!res.isEmpty());
        msgoutput_lst->setVisible(res.isEmpty());

        if(results_tbw->isVisible())
            fillResultsTable(res);
        else
        {
            QLabel *label=new QLabel(trUtf8("SQL command successfully executed. <em>Rows affected <strong>%1</strong></em>").arg(res.getTupleCount()));
            QListWidgetItem *item=new QListWidgetItem;

            item->setIcon(QIcon(":/icones/icones/msgbox_info.png"));
            msgoutput_lst->clear();
            msgoutput_lst->addItem(item);
            msgoutput_lst->setItemWidget(item, label);
        }
    }
    catch(Exception &e)
    {
        showError(e);
    }
}
예제 #5
0
void SQLExecutionWidget::fillResultsTable(Catalog &catalog, ResultSet &res, QTableWidget *results_tbw, bool store_data)
{
	if(!results_tbw)
		throw Exception(ERR_OPR_NOT_ALOC_OBJECT ,__PRETTY_FUNCTION__,__FILE__,__LINE__);

	try
	{
		int col=0, row=0, col_cnt=res.getColumnCount();
		QTableWidgetItem *item=nullptr;
		vector<unsigned> type_ids;
		vector<attribs_map> types;
		map<unsigned, QString> type_names;
		unsigned orig_filter=catalog.getFilter();

		results_tbw->setRowCount(0);
		results_tbw->setColumnCount(col_cnt);
		results_tbw->verticalHeader()->setVisible(true);
		results_tbw->blockSignals(true);

		//Configuring the grid columns with the names of retrived table columns
		for(col=0; col < col_cnt; col++)
		{
			type_ids.push_back(res.getColumnTypeId(col));
			results_tbw->setHorizontalHeaderItem(col, new QTableWidgetItem(res.getColumnName(col)));
		}

		//Retrieving the data type names for each column
		catalog.setFilter(Catalog::LIST_ALL_OBJS);
		std::unique(type_ids.begin(), type_ids.end());
    types=catalog.getObjectsAttributes(OBJ_TYPE, QString(), QString(), type_ids);

    for(auto &tp : types)
			type_names[tp[ParsersAttributes::OID].toUInt()]=tp[ParsersAttributes::NAME];

		catalog.setFilter(orig_filter);

		//Assinging the type names as tooltip on header items
		for(col=0; col < col_cnt; col++)
		{
			item=results_tbw->horizontalHeaderItem(col);
			item->setToolTip(type_names[res.getColumnTypeId(col)]);
			item->setData(Qt::UserRole, type_names[res.getColumnTypeId(col)]);
		}

		if(res.accessTuple(ResultSet::FIRST_TUPLE))
		{
			results_tbw->setRowCount(res.getTupleCount());

			do
			{
				//Fills the current row with the values of current tuple
				for(col=0; col < col_cnt; col++)
				{
					item=new QTableWidgetItem;

					if(res.isColumnBinaryFormat(col))
					{
						//Binary columns can't be edited by user
						item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
						item->setText(trUtf8("[binary data]"));
					}
					else
					{
						item->setText(res.getColumnValue(col));

						if(store_data)
							item->setData(Qt::UserRole, item->text());
					}

					results_tbw->setItem(row, col, item);
				}

				//Configure the vertical header to show the current tuple id
				results_tbw->setVerticalHeaderItem(row, new QTableWidgetItem(QString::number(row + 1)));
				row++;
			}
			while(res.accessTuple(ResultSet::NEXT_TUPLE));
		}

		results_tbw->blockSignals(false);
		results_tbw->resizeColumnsToContents();
		results_tbw->resizeRowsToContents();
	}
	catch(Exception &e)
	{
		throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
	}
}