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. QSqlQueryModel with Open Cypher query issue

QSqlQueryModel with Open Cypher query issue

Scheduled Pinned Locked Moved Solved General and Desktop
10 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.
  • Alex MirgorodskiyA Offline
    Alex MirgorodskiyA Offline
    Alex Mirgorodskiy
    wrote on last edited by
    #1

    Hi all!
    I implemented simple model-view program which work with AgensGraph (fork of the PostgreSQL) base .
    View part work on QML code. Model implemented on C++.
    It is class inherited from QSqlQueryModel . Code was written by Qt Docs Example with one difference - query use OpenCypher instead SQL.
    It's pretty well work with Qt 5.5.1 but not work with Qt 5.11.2

    code for query:

     const char* ProjectBaseModel::SQL_SELECT =
    "SET graph_path = prod; "
    " match (n:task) return properties(n) AS n, n.task_type as t ;";
    

    Application connectedto the base but query not executed. It seems like empty query.
    As you can see below it implemented in a refresh() method

    void ProjectBaseModel::refresh()
    {
        this->setQuery(SQL_SELECT);
    }  
    

    The OpenCypher code is work in console connected with base and even in the Pgadmin.
    Result of the query is:

    n                           |  t
    ----------------------------+-------------
    {"task_type": "Modeling"}   | "Modeling"
    {"task_type": "Texturing"}  | "Texturing"
    {"task_type": "Rig"}        | "Rig"
    {"task_type": "Shading"}    | "Shading"    
    

    I want to note also : the application work if I use SQL query to the tables from my base.
    Have somebody same issues?

    Thanks,
    Alex

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

      Hi and welcome to devnet,

      Did you check if you get any errors from the query and it's execution ?

      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
      0
      • Alex MirgorodskiyA Offline
        Alex MirgorodskiyA Offline
        Alex Mirgorodskiy
        wrote on last edited by
        #3

        Hi SGaist.
        My application don't generate any errors.
        I had insert qDebug() calls for catch some states of some elements of the program
        When I am compile it in the Qt5.5.1 application work and show my ListView with model data. I attached pic bellow.

        0_1539880250774_AgensGraph_Listview.jpg

        And application output is:

        --Data Base Info after connection------------------------
        db.tables() =  ("testTable", "world", "projects", "prod.ag_edge", "prod.ag_vertex", "prod.task", "prod.dependency", "pg_catalog.ag_graph", "pg_catalog.ag_label")
        db.databaseName() =  "atmosphere_db"
        db.connectionName() =  "qt_sql_default_connection"
        db.driverName() =  "QPSQL"
        --End Data Base Info ------------------------- 
        
        --- Start roleNames() ---------
        ------------
        roleName idx =  0 "n"
        ------------
        roleName idx =  1 "t"
        --- End roleNames() ---------
        this->roleNames() =  QHash((258, "t")(257, "n"))
        this->rowCount() =  4
        QueryText =  SET graph_path = prod;  match (n:task) return properties(n) AS n, n.task_type as t ;
        query.lastError() =  QSqlError("", "", "")
        this->rowCount() =  4
        --- Start roleNames() ---------
        ------------
        roleName idx =  0 "n"
        ------------
        roleName idx =  1 "t"
        --- End roleNames() ---------
        QModelIndex modelIndex =  QModelIndex(0,0,0x0,ProjectBaseModel(0x7fff3a984130))
        QModelIndex modelIndex =  QModelIndex(0,1,0x0,ProjectBaseModel(0x7fff3a984130))
        QModelIndex modelIndex =  QModelIndex(1,0,0x0,ProjectBaseModel(0x7fff3a984130))
        QModelIndex modelIndex =  QModelIndex(1,1,0x0,ProjectBaseModel(0x7fff3a984130))
        QModelIndex modelIndex =  QModelIndex(2,0,0x0,ProjectBaseModel(0x7fff3a984130))
        QModelIndex modelIndex =  QModelIndex(2,1,0x0,ProjectBaseModel(0x7fff3a984130))
        QModelIndex modelIndex =  QModelIndex(3,0,0x0,ProjectBaseModel(0x7fff3a984130))
        QModelIndex modelIndex =  QModelIndex(3,1,0x0,ProjectBaseModel(0x7fff3a984130))
        

        When I compile the application in the Qt5.11.2 output is:

        --Data Base Info after connection------------------------
        db.tables() =  ("testTable", "world", "projects", "prod.ag_edge", "prod.ag_vertex", "prod.task", "prod.dependency", "pg_catalog.ag_graph", "pg_catalog.ag_label")
        db.databaseName() =  "atmosphere_db"
        db.connectionName() =  "qt_sql_default_connection"
        db.driverName() =  "QPSQL"
        --End Data Base Info ------------------------- 
        
        --- Start roleNames() ---------
        ------------
        roleName idx =  0 "n"
        ------------
        roleName idx =  1 "t"
        --- End roleNames() ---------
        this->roleNames() =  QHash((257, "n")(258, "t"))
        this->rowCount() =  0
        QueryText =  SET graph_path = prod;  match (n:task) return properties(n) AS n, n.task_type as t ;
        query.lastError() =  QSqlError("", "", "")
        this->rowCount() =  0
        

        Alex

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

          Would it be possible for you to provide a minimal compilable example that creates a dummy database to reproduce this behaviour ?

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

          Alex MirgorodskiyA 1 Reply Last reply
          0
          • SGaistS SGaist

            Would it be possible for you to provide a minimal compilable example that creates a dummy database to reproduce this behaviour ?

            Alex MirgorodskiyA Offline
            Alex MirgorodskiyA Offline
            Alex Mirgorodskiy
            wrote on last edited by Alex Mirgorodskiy
            #5

            @SGaist Are you mean exapmle of OpenCypher commands for creating database or my Qt code for reading from base? I can share both.

            SGaistS 1 Reply Last reply
            0
            • Alex MirgorodskiyA Offline
              Alex MirgorodskiyA Offline
              Alex Mirgorodskiy
              wrote on last edited by
              #6

              This is my OpenSypher code for creation the graph:

              atmosphere_db=# CREATE GRAPH prod;
              CREATE GRAPH
              atmosphere_db=# 
              SET graph_path = prod;
              CREATE VLABEL task;
              CREATE ELABEL dependency;
              CREATE (:task {task_type: 'Modeling'})-[:dependency {dep_type:'FS'}]->(:task {task_type: 'Texturing'});
              CREATE (:task {task_type: 'Rig'})-[:dependency {dep_type:'FS'}]->(:task {task_type: 'Shading'});
              
              1 Reply Last reply
              0
              • Alex MirgorodskiyA Alex Mirgorodskiy

                @SGaist Are you mean exapmle of OpenCypher commands for creating database or my Qt code for reading from base? I can share both.

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Alex-Mirgorodskiy said in QSqlQueryModel with Open Cypher query issue:

                @SGaist Are you mean exapmle of OpenCypher commands for creating database or my Qt code for reading from base? I can share both.

                I meant a minimal application that would create the DB and do the access that are now failing.

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

                Alex MirgorodskiyA 1 Reply Last reply
                0
                • SGaistS SGaist

                  @Alex-Mirgorodskiy said in QSqlQueryModel with Open Cypher query issue:

                  @SGaist Are you mean exapmle of OpenCypher commands for creating database or my Qt code for reading from base? I can share both.

                  I meant a minimal application that would create the DB and do the access that are now failing.

                  Alex MirgorodskiyA Offline
                  Alex MirgorodskiyA Offline
                  Alex Mirgorodskiy
                  wrote on last edited by
                  #8

                  @SGaist Hi. But I created the base from console in Agens app (like psql). It was my first testing of Qt with Agens graph.
                  I wrote simplest code for catching the source of issue. But not found something yet. It work in the Qt5.5 and nor work in the Qt5.11.2

                  int main(int argc, char *argv[])
                  {
                      QCoreApplication a(argc, argv);
                  
                      QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
                      //QSqlDatabase db = QSqlDatabase::database();
                      db.setDatabaseName("atmosphere_db");
                      db.setUserName("atmosphere_user");
                      db.setHostName("localhost");
                      db.setPassword("atmosphere");
                      if (!db.open()) {
                          qDebug() << "Cannot open database:";
                          return 1;
                      }
                  
                      qDebug() << "--Data Base Info after connection--------------";
                      qDebug() << "db.tables() = " << db.tables();
                      qDebug() << "db.databaseName() = " << db.databaseName();
                      qDebug() << "db.connectionName() = " << db.connectionName();
                      qDebug() << "db.driverName() = " << db.driverName();
                      qDebug() << "--End Data Base Info -------------------------" << "\n";
                  
                      QSqlQuery q(db);
                      qDebug() << q.lastError();
                     
                     q.exec("SET graph_path = prod; match (n:task) return properties(n) AS n, n.task_type as t ;");
                     
                     qDebug() << q.lastError();
                  
                      while (q.next()) {
                              qDebug() <<  q.value(0).toString() << "|" << q.value(1).toString() ;
                  
                          }
                  
                      return a.exec();
                  }
                  
                  1 Reply Last reply
                  0
                  • Alex MirgorodskiyA Offline
                    Alex MirgorodskiyA Offline
                    Alex Mirgorodskiy
                    wrote on last edited by Alex Mirgorodskiy
                    #9

                    Finally I solved this issue. The queries pretty works if it do through separate "exec" calls. I wrote an example below

                    query = QSqlQuery(db);
                    query.exec("SET graph_path = some_graph; ");
                    query.exec("MATCH some OpenCypher match RETURN some Match variable;");
                    
                    1 Reply Last reply
                    1
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Sorry, I lost track on this one.

                      Glad you found out and thanks for sharing !

                      Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

                      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
                      0

                      • Login

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