Results 1 to 13 of 13

Thread: QSqlQueryModel doesnt hold results

  1. #1
    Join Date
    Jul 2012
    Posts
    17
    Thanks
    2
    Platforms
    Unix/X11 Windows

    Default QSqlQueryModel doesnt hold results

    Hello community,

    Im trying to access an intersystems Caché database and every statements besides select statements are working fine.
    I just don't get a result in my QSqlQueryModel and I can't figure out why.

    Has anyone ever worked with caché and QSql and got select statements returning results?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlQueryModel doesnt hold results

    Why not share the error message you are probably getting from QSqlQueryModel::lastError()? If other statements are getting executed then the underlying database interface is clearly functional.

  3. The following user says thank you to ChrisW67 for this useful post:

    Edder (17th September 2012)

  4. #3
    Join Date
    Jul 2012
    Posts
    17
    Thanks
    2
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQueryModel doesnt hold results

    Thats actually a pretty good idea thank you, haven't thought of this.

    LasError is: QSqlError(-1, "Forward-only queries cannot be used in a data model", "")
    Using setForwardOnly() doesnt work, is there another way solve this problem?

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlQueryModel doesnt hold results

    Can you post a minimal compilable example reproducing the problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlQueryModel doesnt hold results

    You don't say how you are accessing the Cache database from Qt. Which driver? I notice, for example, that CacheDataReader provides forward-only access, so using this in the underlying driver will probably not work.

  7. #6
    Join Date
    Jul 2012
    Posts
    17
    Thanks
    2
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQueryModel doesnt hold results

    Quote Originally Posted by ChrisW67 View Post
    You don't say how you are accessing the Cache database from Qt. Which driver?
    I'm using the QODBC driver and the DSN driver is "InterSystems ODBC35" driver and Driver Version = 2012.1.2.702.0.

    An how I fetch the result:
    Qt Code:
    1. void ExecuteQuery()
    2. {
    3. QSqlDatabase m_db = QSqlDatabase::addDatabase("QODBC3", "test");
    4. m_db.setDatabaseName("InterSystems Caché DSN");
    5. m_db.open();
    6.  
    7. QSqlQuery *m_pQuery = new QSqlQuery(m_db);
    8. if (!m_pQuery->exec("select * from Aviation.Aircraft")) // table of the SAMPLES database of an caché instance
    9. {
    10. QString sError = m_pQuery->lastError().text();
    11. //m_sLogText = QString("<table><tr><td><b>%1</b></td><td><font color='#FF0000'>%2</font></td></tr></table>").arg(QDateTime::currentDateTime().toString("(hh:mm:ss)"), sError.replace('<', "&lt;").replace('>', "&gt;"));
    12. //ODBC_Logging::getInstance()->WriteLog(ERROR, sError);
    13. qDebug() << sError;
    14. }
    15. else
    16. {
    17. m_pSqlQueryModel = new QSqlQueryModel();
    18. m_pSqlQueryModel->setQuery(*m_pQuery);
    19. QAbstractItemModel *m_pSQLResultTable = m_pSqlQueryModel;
    20. qDebug() << m_pSqlQueryModel->lastError();
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

    I'm sorry I didn't provided these infos directly, I thought someone already worked with qt and the caché database and knows the problems when working with caché.

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlQueryModel doesnt hold results

    And which of these calls returns the error you mentioned earlier?

    BTW. don't create QSqlQuery using the new operator, you are leaking memory there.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #8
    Join Date
    Jul 2012
    Posts
    17
    Thanks
    2
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQueryModel doesnt hold results

    Quote Originally Posted by wysota View Post
    And which of these calls returns the error you mentioned earlier?
    m_pSqlQueryModel->setQuery(*m_pQuery); does that.
    lastError() holds the error in this case I posted above.

    Quote Originally Posted by wysota View Post
    BTW. don't create QSqlQuery using the new operator, you are leaking memory there.
    Yea I know, I'm deleting QSqlQuery in my ConnectionClosed() function, I made up these function to show a quick example.

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlQueryModel doesnt hold results

    Quote Originally Posted by Edder View Post
    m_pSqlQueryModel->setQuery(*m_pQuery); does that.
    lastError() holds the error in this case I posted above.
    So the original query works but it fails if you set it to the model?

    How about this:

    Qt Code:
    1. void ExecuteQuery()
    2. {
    3. QSqlDatabase m_db = QSqlDatabase::addDatabase("QODBC3", "test");
    4. m_db.setDatabaseName("InterSystems Caché DSN");
    5. m_db.open();
    6.  
    7. m_pSqlQueryModel = new QSqlQueryModel(this);
    8. m_pSqlQueryModel->setQuery("select * from Aviation.Aircraft", m_db);
    9. QAbstractItemModel *m_pSQLResultTable = m_pSqlQueryModel;
    10. qDebug() << m_pSqlQueryModel->lastError().text();
    11. }
    To copy to clipboard, switch view to plain text mode 

    Yea I know, I'm deleting QSqlQuery in my ConnectionClosed() function, I made up these function to show a quick example.
    Just create the query on the stack, that's quicker than writing "new"
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #10
    Join Date
    Jul 2012
    Posts
    17
    Thanks
    2
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQueryModel doesnt hold results

    I tested your code and the query in the QSqlQueryModel doesn't properly execute since I'm getting this error on trying: Forward-only queries cannot be used in a data model
    And this without even using a QSqlQuery.

  12. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlQueryModel doesnt hold results

    It is possible that your Odbc driver does not support bi-directional cursors. It may also be an issue with the driver when told to act as a version 2.0 ODBC. See http://doc.qt.io/qt-4.8/sql-driver.html#qodbc

  13. #12
    Join Date
    Jul 2012
    Posts
    17
    Thanks
    2
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQueryModel doesnt hold results

    Thanks Chris, I think its the bidirectional cursor issue.
    I tried setting the driver to a version 3.0 ODBC driver and that also doesn't work.

    Is there another way to fetch the results from the QSqlQuery w/o using a data model?

  14. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlQueryModel doesnt hold results

    Quote Originally Posted by Edder View Post
    Is there another way to fetch the results from the QSqlQuery w/o using a data model?
    Yes, of course. You can use QSqlQuery::hasNext(), QSqlQuery::next() and QSqlQuery::value().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to make a QSet hold structs?
    By wayfaerer in forum Newbie
    Replies: 2
    Last Post: 4th March 2012, 22:18
  2. SQLite - results of QSqlQueryModel
    By Tomasz in forum Newbie
    Replies: 0
    Last Post: 6th September 2010, 00:03
  3. Can QVector hold objects?
    By N3wb in forum Newbie
    Replies: 6
    Last Post: 14th April 2010, 20:29
  4. checkable QAction shortcut hold
    By winder in forum Qt Programming
    Replies: 7
    Last Post: 18th February 2010, 15:48
  5. QTextEdit does not hold Object Id behind
    By validator in forum Qt Programming
    Replies: 3
    Last Post: 19th April 2008, 00:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.