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 to create postgresql subscription with qsqlquery?

How to create postgresql subscription with qsqlquery?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 736 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.
  • August WienerA Offline
    August WienerA Offline
    August Wiener
    wrote on last edited by
    #1

    I am trying to create postgres subscription using qsqlquery, but getting :

    "LINE 1:EXCECUTE ('zumbeispiel_slot', TRUE)

    42601 QPSQL: Unable to create query"
    here is the code

    local_query.prepare("CREATE SUBSCRIPTION :sub_name"
                        "CONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'"
                        "PUBLICATION public_realdent_db"
                        "WITH"
                        "slot_name = :slot_name,"
                        "create_slot = :create_slot,"
                        "synchronous_commit = on");
    local_query.bindValue(":sub_name", subscription);
    local_query.bindValue(":create_slot", create_slot);
    local_query.bindValue(":slot_name", slot_name);
    slots_connected = local_query.exec();
    
    
    if (!slots_connected)
    {
        emit database_failed(QUERY_ERROR_HEADER, QUERY_ERROR_PRETEXT + 
                             local_query.lastError().text());
    
        return slots_connected;
    }
    

    What I am doing wrong?
    Connection string seems to be correct, many other queries to this database works fine.

    JonBJ 1 Reply Last reply
    0
    • August WienerA August Wiener

      I am trying to create postgres subscription using qsqlquery, but getting :

      "LINE 1:EXCECUTE ('zumbeispiel_slot', TRUE)

      42601 QPSQL: Unable to create query"
      here is the code

      local_query.prepare("CREATE SUBSCRIPTION :sub_name"
                          "CONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'"
                          "PUBLICATION public_realdent_db"
                          "WITH"
                          "slot_name = :slot_name,"
                          "create_slot = :create_slot,"
                          "synchronous_commit = on");
      local_query.bindValue(":sub_name", subscription);
      local_query.bindValue(":create_slot", create_slot);
      local_query.bindValue(":slot_name", slot_name);
      slots_connected = local_query.exec();
      
      
      if (!slots_connected)
      {
          emit database_failed(QUERY_ERROR_HEADER, QUERY_ERROR_PRETEXT + 
                               local_query.lastError().text());
      
          return slots_connected;
      }
      

      What I am doing wrong?
      Connection string seems to be correct, many other queries to this database works fine.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @August-Wiener
      I'm not a practicing C++-er. But isn't your multiline string literal going to join without any whitespace character? Isn't

                  "CREATE SUBSCRIPTION :sub_name"
                  "CONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'"
                  "..."
      

      going to generate:

      "CREATE SUBSCRIPTION :sub_nameCONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'..."
      

      i.e. you need a space at the end/start of each of your literals (inside the quotes), so at present your query won't parse??

      August WienerA 1 Reply Last reply
      2
      • JonBJ JonB

        @August-Wiener
        I'm not a practicing C++-er. But isn't your multiline string literal going to join without any whitespace character? Isn't

                    "CREATE SUBSCRIPTION :sub_name"
                    "CONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'"
                    "..."
        

        going to generate:

        "CREATE SUBSCRIPTION :sub_nameCONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'..."
        

        i.e. you need a space at the end/start of each of your literals (inside the quotes), so at present your query won't parse??

        August WienerA Offline
        August WienerA Offline
        August Wiener
        wrote on last edited by August Wiener
        #3

        @JonB
        Yeah, it is even funny how I missed that. Now my code looks like

        local_query.prepare("CREATE SUBSCRIPTION :sub_name "
                                "CONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'"
                                "PUBLICATION public_dealmed_db "
                                "WITH "
                                "(slot_name = :slot_name, "
                                "create_slot = :create_slot, "
                                "synchronous_commit = on)");
            local_query.bindValue(":sub_name", subscription);
            local_query.bindValue(":create_slot", create_slot);
            local_query.bindValue(":slot_name", slot_name);
            slots_connected = local_query.exec();
        

        Unfortunately, I keep getting just the same error :(

        JonBJ 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi and welcome to devnet,

          Did you check the content of QSqlQuery::executedQuery to see if there's anything wrong in there ?

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

          August WienerA 1 Reply Last reply
          0
          • August WienerA August Wiener

            @JonB
            Yeah, it is even funny how I missed that. Now my code looks like

            local_query.prepare("CREATE SUBSCRIPTION :sub_name "
                                    "CONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'"
                                    "PUBLICATION public_dealmed_db "
                                    "WITH "
                                    "(slot_name = :slot_name, "
                                    "create_slot = :create_slot, "
                                    "synchronous_commit = on)");
                local_query.bindValue(":sub_name", subscription);
                local_query.bindValue(":create_slot", create_slot);
                local_query.bindValue(":slot_name", slot_name);
                slots_connected = local_query.exec();
            

            Unfortunately, I keep getting just the same error :(

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @August-Wiener
            If it's as you've pasted it, you still have

                                    "CONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'"
                                    "PUBLICATION public_dealmed_db "
            

            ->

                                    "CONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'PUBLICATION public_dealmed_db "
            

            ?

            1 Reply Last reply
            0
            • SGaistS SGaist

              Hi and welcome to devnet,

              Did you check the content of QSqlQuery::executedQuery to see if there's anything wrong in there ?

              August WienerA Offline
              August WienerA Offline
              August Wiener
              wrote on last edited by
              #6

              @SGaist
              It is just the same but with '?' symbols instead of parameter values.

              @JonB
              No, things not that bad. I failed last space when editing, in code it is with white spaces at the ends of every row except th last one.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                I'm not sure whether bindValue works with that kind of query.

                Does it also fail if you use QString to build the query using arg method ?

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

                August WienerA 1 Reply Last reply
                2
                • SGaistS SGaist

                  I'm not sure whether bindValue works with that kind of query.

                  Does it also fail if you use QString to build the query using arg method ?

                  August WienerA Offline
                  August WienerA Offline
                  August Wiener
                  wrote on last edited by August Wiener
                  #8
                  This post is deleted!
                  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