PDA

View Full Version : Qt c++ - how to show a refcursor retrieving from a postgres stored procedure?



synpro85
26th June 2014, 15:04
Qt postgres stored procedures
Hello, i have a trouble, i have a postgres stored function that should retrieve a ref cursor, when i call it with this instructions:



qdb.prepare("SELECT * from myfunction('cursor'); fetch all in cursor" );
qdb.exec();


and i try to show it in a tableview:



QSqlQueryModel *model = new QSqlQueryModel;

model->setQuery(qdb1);

ui->tableView->setModel(model);


In the tableview i only see the name of the cursor instead of the table.


So where's the problem? :confused:
when i use the same SQL query in pgadmin it returns me the table, so it goes good, but does it go wrong in Qt? Where am i wrong? :confused:
Thenks for the help!! :o

panch-dima
6th March 2023, 12:05
Maybe not relevant anymore)
I will write this for those who also stumbled upon this post.
I solved it in the following way.
Postgresql database
Version Qt6.4.1


QSqlQuery *query = new QSqlQuery(db);
query->exec("call test_procedure(1, 'p_rc'); FETCH ALL p_rc;");
if(query->lastError().isValid())
{
qDebug()<<query->lastError();
}
while (query->nextResult())
{
while (query->next()) {

qDebug()<<query->value(1);
}
}

i am doing two consecutive requests
1. procedure call
2. reading the cursor.
and sequentially read the results of queries

while (query->nextResult())