Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I get value of inout parameter from PostgreSQL procedure call?

How can I get value of inout parameter from PostgreSQL procedure call?

Scheduled Pinned Locked Moved Unsolved General and Desktop
postgresql
6 Posts 3 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    OpenGL
    wrote on 28 Nov 2020, 23:03 last edited by
    #1

    I have code like this

    QString my_str = "call my_proc(null,null);";
    QSqlQuery my_query(d);
    my_query.exec(my_str);
    

    And it works, it calls the postgresql procedure

    procedure my_proc(value int, return_value INOUT int);
    

    But how can I get the value of the return_value parameter?
    When I try to get the value from

    query.record 
    

    it seems the value is always 0.
    So I guess I'm missing something important here.

    Is there an example of how to do this for Postgresql?

    (note: it seems I can not call procedures with bind variables, else I would have tried that).

    J 1 Reply Last reply 29 Nov 2020, 08:52
    0
    • O OpenGL
      28 Nov 2020, 23:03

      I have code like this

      QString my_str = "call my_proc(null,null);";
      QSqlQuery my_query(d);
      my_query.exec(my_str);
      

      And it works, it calls the postgresql procedure

      procedure my_proc(value int, return_value INOUT int);
      

      But how can I get the value of the return_value parameter?
      When I try to get the value from

      query.record 
      

      it seems the value is always 0.
      So I guess I'm missing something important here.

      Is there an example of how to do this for Postgresql?

      (note: it seems I can not call procedures with bind variables, else I would have tried that).

      J Offline
      J Offline
      JonB
      wrote on 29 Nov 2020, 08:52 last edited by JonB
      #2

      @OpenGL said in How can I get value of inout parameter from PostgreSQL procedure call?:

      (note: it seems I can not call procedures with bind variables, else I would have tried that).

      I don't know anything about PostgreSQL/procedure calls. But as far as I know you must bind to a variable to get an OUT parameter back. So show what you tried for the prepare/bind()?

      1 Reply Last reply
      3
      • O Offline
        O Offline
        OpenGL
        wrote on 30 Nov 2020, 21:37 last edited by
        #3

        Prepare/bind does not work with postgres procedures, so I have to do it some other way. And I have no idea how.

        S 1 Reply Last reply 1 Dec 2020, 19:21
        0
        • O OpenGL
          30 Nov 2020, 21:37

          Prepare/bind does not work with postgres procedures, so I have to do it some other way. And I have no idea how.

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 1 Dec 2020, 19:21 last edited by
          #4

          Hi,

          @OpenGL said in How can I get value of inout parameter from PostgreSQL procedure call?:

          Prepare/bind does not work with postgres procedures, so I have to do it some other way. And I have no idea how.

          Can you provide more information about that ?
          Do you have a simple example of procedure that can be tested ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          O 1 Reply Last reply 2 Dec 2020, 22:11
          0
          • S SGaist
            1 Dec 2020, 19:21

            Hi,

            @OpenGL said in How can I get value of inout parameter from PostgreSQL procedure call?:

            Prepare/bind does not work with postgres procedures, so I have to do it some other way. And I have no idea how.

            Can you provide more information about that ?
            Do you have a simple example of procedure that can be tested ?

            O Offline
            O Offline
            OpenGL
            wrote on 2 Dec 2020, 22:11 last edited by
            #5

            @SGaist said in How can I get value of inout parameter from PostgreSQL procedure call?:

            Hi,

            @OpenGL said in How can I get value of inout parameter from PostgreSQL procedure call?:

            Prepare/bind does not work with postgres procedures, so I have to do it some other way. And I have no idea how.

            Can you provide more information about that ?
            Do you have a simple example of procedure that can be tested ?

            Hello, sorry for late reply.
            I had a discussion about it here https://forum.qt.io/topic/120460/minimal-sql-program-that-fails-what-is-wrong-with-it/2
            An minimal example is included there with a procedure that failes to be prepared with the prepare command.

            J 1 Reply Last reply 3 Dec 2020, 07:40
            0
            • O OpenGL
              2 Dec 2020, 22:11

              @SGaist said in How can I get value of inout parameter from PostgreSQL procedure call?:

              Hi,

              @OpenGL said in How can I get value of inout parameter from PostgreSQL procedure call?:

              Prepare/bind does not work with postgres procedures, so I have to do it some other way. And I have no idea how.

              Can you provide more information about that ?
              Do you have a simple example of procedure that can be tested ?

              Hello, sorry for late reply.
              I had a discussion about it here https://forum.qt.io/topic/120460/minimal-sql-program-that-fails-what-is-wrong-with-it/2
              An minimal example is included there with a procedure that failes to be prepared with the prepare command.

              J Offline
              J Offline
              JonB
              wrote on 3 Dec 2020, 07:40 last edited by JonB 12 Mar 2020, 07:41
              #6

              @OpenGL
              I'm not defending this other than as a nasty hack. But if what you say is true, and you are stuck looking for a workaround: you can pass input parameters by interpolating them literally into the call() statement, and you can receive output parameters by returning them via a SELECT statement at the end of a call()ed procedure. Assuming you get a result set back from the call() which the driver can retrieve.

              1 Reply Last reply
              0

              1/6

              28 Nov 2020, 23:03

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved