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. Returning query on SQLite db from python function

Returning query on SQLite db from python function

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 568 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
    Achab61
    wrote on last edited by
    #1

    I built a python class which binds all functions of a SQLite3 db using QSqlDatabase, QSqlQuery from PyQt5. I would need to return from the 'read' method of this class a query object resulting from QSQlQuery.exec method but I'm not able to get it.

    Do you have any idea how to do it ? Thanks

    jsulmJ 1 Reply Last reply
    0
    • A Achab61

      I built a python class which binds all functions of a SQLite3 db using QSqlDatabase, QSqlQuery from PyQt5. I would need to return from the 'read' method of this class a query object resulting from QSQlQuery.exec method but I'm not able to get it.

      Do you have any idea how to do it ? Thanks

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Achab61 What is the problem?

          QSqlQuery query;
          query.prepare("INSERT INTO person (id, forename, surname)  VALUES (?, ?, ?)");
          query.addBindValue(1001);
          query.addBindValue("Bart");
          query.addBindValue("Simpson");
          query.exec();
          return query;
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Achab61
        wrote on last edited by
        #3

        It works, thanks. Just another, maybe, stupid question: in the same class there are also methods to update db (insert, update, delete). Which is the best way to returning the result of such methods to the program issuing the method ? In other words, I would need to return (e.g.) the result of the "insert" method of the class. Which is the correct way of doing it ?

        jsulmJ 1 Reply Last reply
        0
        • A Achab61

          It works, thanks. Just another, maybe, stupid question: in the same class there are also methods to update db (insert, update, delete). Which is the best way to returning the result of such methods to the program issuing the method ? In other words, I would need to return (e.g.) the result of the "insert" method of the class. Which is the correct way of doing it ?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Achab61 said in Returning query on SQLite db from python function:

          result of the "insert" method

          What would it be in your case? Success/Failure?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Achab61
            wrote on last edited by
            #5

            Yes, it would be Success / Failure feed back

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

              Hi,

              The exec method returns a Boolean value to indicate the success or failure of the call.

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

              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