Results 1 to 2 of 2

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

  1. #1
    Join Date
    May 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Qt c++ - how to show a refcursor retrieving from a postgres stored procedure?

    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:

    Qt Code:
    1. qdb.prepare("SELECT * from myfunction('cursor'); fetch all in cursor" );
    2. qdb.exec();
    To copy to clipboard, switch view to plain text mode 

    and i try to show it in a tableview:

    Qt Code:
    1.  
    2. model->setQuery(qdb1);
    3.  
    4. ui->tableView->setModel(model);
    To copy to clipboard, switch view to plain text mode 

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


    So where's the problem?
    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?
    Thenks for the help!!

  2. #2
    Join Date
    Nov 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Qt c++ - how to show a refcursor retrieving from a postgres stored procedure?

    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

    Qt Code:
    1. QSqlQuery *query = new QSqlQuery(db);
    2. query->exec("call test_procedure(1, 'p_rc'); FETCH ALL p_rc;");
    3. if(query->lastError().isValid())
    4. {
    5. qDebug()<<query->lastError();
    6. }
    7. while (query->nextResult())
    8. {
    9. while (query->next()) {
    10.  
    11. qDebug()<<query->value(1);
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    i am doing two consecutive requests
    1. procedure call
    2. reading the cursor.
    and sequentially read the results of queries
    Qt Code:
    1. while (query->nextResult())
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Stored procedure in Firebird
    By ozplc in forum Qt Programming
    Replies: 0
    Last Post: 9th June 2011, 23:40
  2. Qt4 Mysql stored procedure
    By lynnH in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2010, 09:05
  3. Stored procedure and ODBC
    By filya in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2010, 09:40
  4. problem in using stored procedure
    By zolfaghari in forum Qt Programming
    Replies: 0
    Last Post: 15th March 2010, 09:25
  5. qt how get out parameter of Stored Procedure?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 23rd March 2009, 13:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.