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 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).

    JonBJ 1 Reply Last reply
    0
    • O OpenGL

      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).

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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 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.

        SGaistS 1 Reply Last reply
        0
        • O OpenGL

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

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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
          0
          • SGaistS SGaist

            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 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.

            JonBJ 1 Reply Last reply
            0
            • O OpenGL

              @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.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #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

              • Login

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