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. PostgreSQL SELECT after INSERT... where are my data?
Qt 6.11 is out! See what's new in the release blog

PostgreSQL SELECT after INSERT... where are my data?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.6k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    addebito
    wrote on last edited by addebito
    #1

    Hi at all,
    I'mg working with PostgreSql (I never it used before).

    I have a problem after inserting a record.
    Eg:

        QSqlDatabase::database().transaction();
        QSqlQuery q;
        q.prepare("INSERT INTO myTable (name, x, y) VALUES (:name, :x, :y);");
        q.bindValue(":name", "myname");
        q.bindValue(":x", 10);
        q.bindValue(":y", 20);
        bool ok = q.exec();
        if (ok)
        {
            QSqlDatabase::database().commit();
        }
        else
        {
            qDebug() << q.lastError().text();
            QSqlDatabase::database().rollback();
        }
    

    The query works fine and I don't get any error.
    With pgAdmin I can see the data but not on my application.
    I've created a button to requery the table but no way...

    If I restart the application I can see the inserted records!
    What I'm missing ?!?

    Thank you!

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @addebito said in PostgreSQL SELECT after INSERT... where are my data?:

      not on my application.

      How do you check? If you see it with psql/pgadmin then it was successfully inserted.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 3 Replies Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @addebito said in PostgreSQL SELECT after INSERT... where are my data?:

        not on my application.

        How do you check? If you see it with psql/pgadmin then it was successfully inserted.

        A Offline
        A Offline
        addebito
        wrote on last edited by
        #3

        @Christian-Ehrlicher yes, you are right. It's successfully inserted but why in my application I don't see these inserted records after a new query like this?

        SELECT * FROM myTable;

        As mentionend before, I see these records If I close and restart the application.
        There isn't an option on the connection... or inside QSqlDatabase?

        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @addebito said in PostgreSQL SELECT after INSERT... where are my data?:

          not on my application.

          How do you check? If you see it with psql/pgadmin then it was successfully inserted.

          A Offline
          A Offline
          addebito
          wrote on last edited by
          #4

          @Christian-Ehrlicher I'm sorry, the problem could be on visualization data.I've introduce the QSortFilterProxyModel.

          1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @addebito said in PostgreSQL SELECT after INSERT... where are my data?:

            not on my application.

            How do you check? If you see it with psql/pgadmin then it was successfully inserted.

            A Offline
            A Offline
            addebito
            wrote on last edited by
            #5

            @Christian-Ehrlicher I found the problem.
            On my subclass I'd forgotten the "beginRemoveRows" ... "endRemoveRows".
            Anyway, thank you for your reply.

            1 Reply Last reply
            1

            • Login

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