Esempio n. 1
0
vector<attribs_map> Catalog::getMultipleAttributes(ObjectType obj_type, attribs_map extra_attribs)
{
    try
    {
        ResultSet res;
        attribs_map tuple;
        vector<attribs_map> obj_attribs;

        executeCatalogQuery(QUERY_ATTRIBS, obj_type, res, false, extra_attribs);
        if(res.accessTuple(ResultSet::FIRST_TUPLE))
        {
            do
            {
                tuple=changeAttributeNames(res.getTupleValues());

                /* Insert the object type as an attribute of the query result to facilitate the
                import process on the classes that uses the Catalog */
                tuple[ParsersAttributes::OBJECT_TYPE]=QString("%1").arg(obj_type);

                obj_attribs.push_back(tuple);
                tuple.clear();
            }
            while(res.accessTuple(ResultSet::NEXT_TUPLE));
        }

        return(obj_attribs);
    }
    catch(Exception &e)
    {
        throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
    }
}
Esempio n. 2
0
attribs_map Catalog::getObjectsNames(ObjectType obj_type, const QString &sch_name, const QString &tab_name, attribs_map extra_attribs)
{
    try
    {
        ResultSet res;
        attribs_map objects;

        extra_attribs[ParsersAttributes::SCHEMA]=sch_name;
        extra_attribs[ParsersAttributes::TABLE]=tab_name;
        executeCatalogQuery(QUERY_LIST, obj_type, res, false, extra_attribs);

        if(res.accessTuple(ResultSet::FIRST_TUPLE))
        {
            do
            {
                objects[res.getColumnValue(ParsersAttributes::OID)]=res.getColumnValue(ParsersAttributes::NAME);
            }
            while(res.accessTuple(ResultSet::NEXT_TUPLE));
        }

        return(objects);
    }
    catch(Exception &e)
    {
        throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
    }
}
Esempio n. 3
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);
    }
}
Esempio n. 4
0
attribs_map Catalog::getAttributes(const QString &obj_name, ObjectType obj_type, attribs_map extra_attribs)
{
    try
    {
        ResultSet res;
        attribs_map obj_attribs;

        //Add the name of the object as extra attrib in order to retrieve the data only for it
        extra_attribs[ParsersAttributes::NAME]=obj_name;
        executeCatalogQuery(QUERY_ATTRIBS, obj_type, res, true, extra_attribs);

        if(res.accessTuple(ResultSet::FIRST_TUPLE))
            obj_attribs=changeAttributeNames(res.getTupleValues());

        /* Insert the object type as an attribute of the query result to facilitate the
        import process on the classes that uses the Catalog */
        obj_attribs[ParsersAttributes::OBJECT_TYPE]=QString("%1").arg(obj_type);

        return(obj_attribs);
    }
    catch(Exception &e)
    {
        throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
    }
}
Esempio n. 5
0
void Catalog::setConnection(Connection &conn)
{
    try
    {
        ResultSet res;
        QStringList ext_obj;

        this->connection=conn;
        this->connection.connect();

        //Retrieving the last system oid
        executeCatalogQuery(QUERY_LIST, OBJ_DATABASE, res, true,
        {{ParsersAttributes::NAME, conn.getConnectionParam(Connection::PARAM_DB_NAME)}});

        if(res.accessTuple(ResultSet::FIRST_TUPLE))
        {
            attribs_map attribs=changeAttributeNames(res.getTupleValues());
            last_sys_oid=attribs[ParsersAttributes::LAST_SYS_OID].toUInt();
        }

        //Retrieving the list of objects created by extensions
        this->connection.executeDMLCommand("SELECT objid AS oid FROM pg_depend WHERE objid > 0 AND refobjid > 0 AND deptype='e'", res);
        if(res.accessTuple(ResultSet::FIRST_TUPLE))
        {
            do
            {
                ext_obj.push_back(res.getColumnValue("oid"));
            }
            while(res.accessTuple(ResultSet::NEXT_TUPLE));

            ext_obj_oids=ext_obj.join(",");
        }
    }
    catch(Exception &e)
    {
        throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
    }
}
Esempio n. 6
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);
    }
}
Esempio n. 7
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);
	}
}