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. QSqlDatabase sqlite and tracing
Forum Updated to NodeBB v4.3 + New Features

QSqlDatabase sqlite and tracing

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.0k 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
    andruj
    wrote on last edited by
    #1

    Hallo all,

    I am developing an QT application that stores data in a Sqlite database. For data retreaval and manipulation I am using the QSqlRelationalTableModel and the QSqlDatabase with "QSQLITE" driver.

    I would like to know if there is any way to implement tracing in qt, since sqlite doesn't have any profiler. So I would like to know what queryies are sent to the database.

    Thank you for your answer

    1 Reply Last reply
    0
    • C Offline
      C Offline
      clochydd
      wrote on last edited by
      #2

      Hi andruj, you may finde a perfect solution for this in:
      "getLastExecutedQuery":http://stackoverflow.com/questions/5777409/how-to-get-last-prepared-and-executed-query-using-qsqlquery/10641002#10641002

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DBoosalis
        wrote on last edited by
        #3

        I woud suggest not using the QSqlRelationalTableModel. In the past I have created a Database class which has all the methods for interacting with the database using QSqlQuery. I think it much more rohbust to do it this way. Granted there is more code to write, But it allows you to know programatically what's going on with the database. Below is a tiny example of what I mean.

        class Database
        {
        public:
        typedef enum { People, Pets, Food, NumOfTables} TableType;
        // database methods
        bool open(QString &name);
        bool close();
        bool createTable(TableType);
        bool validateTable(TableType);
        QString getLastError();

        // People Methods
        People *getPeople();
        bool addPerson(Person *);
        bool removePerson(int PersonID);
        .
        .
        .
        private:
        static QString tableNames[NumOfTables];
        static QString schemas[NumOfTables];
        QSqlDatabase *handle;
        QString errorMessage;
        QString name;
        QString description;
        QSqlError sqlError;
        };

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andruj
          wrote on last edited by
          #4

          thank you for the replays.

          I will try the solution of stackoverflow.

          @DBoosalis: I will try to stick with the qsqlrelationaltablemodel, since the application isn't too complex. If I will have a more complex app I will certanly use your solution.

          thank you

          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