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. QSQLDriver and Microsoft Access: Crash on insert statement?
Forum Updated to NodeBB v4.3 + New Features

QSQLDriver and Microsoft Access: Crash on insert statement?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 283 Views
  • 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.
  • M Offline
    M Offline
    MGirgis
    wrote on 27 Oct 2020, 20:34 last edited by
    #1

    Whenever I execute an insert statement from QtC++ I get an unhandled exception from the ODBC driver resulting in a crash. :frowning: Code is this:

    DBAccess::m_db = QSqlDatabase::addDatabase("QODBC");
           DBAccess::m_db.setHostName("localhost");
           DBAccess::m_db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=" + elLoc + "");//C:\\Dev\\AccessDB\\SVLearn_MNIST.accdb");
           DBAccess::m_db.setConnectOptions("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");
    
           bool  ok = DBAccess::m_db.open();
           qDebug() << m_db.driverName();
           if(ok)
               qDebug()<<"ok";
           else
               qDebug()<<"not ok"<< m_db.lastError().text();
    

    Which is successful (ok)

    query.prepare("INSERT INTO t_MNIST ( str64Data, blnTest, intLabel, intGroup ) VALUES ('Get a life', False, 0, 0);");
            if (!query.next()) {
                qDebug() << (query).lastError();
                LOG_FAILED_QUERY(query);
                return;
            }
    

    Which crashes with a hidden exception thrown.

    J 1 Reply Last reply 27 Oct 2020, 20:42
    0
    • M MGirgis
      27 Oct 2020, 20:34

      Whenever I execute an insert statement from QtC++ I get an unhandled exception from the ODBC driver resulting in a crash. :frowning: Code is this:

      DBAccess::m_db = QSqlDatabase::addDatabase("QODBC");
             DBAccess::m_db.setHostName("localhost");
             DBAccess::m_db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=" + elLoc + "");//C:\\Dev\\AccessDB\\SVLearn_MNIST.accdb");
             DBAccess::m_db.setConnectOptions("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");
      
             bool  ok = DBAccess::m_db.open();
             qDebug() << m_db.driverName();
             if(ok)
                 qDebug()<<"ok";
             else
                 qDebug()<<"not ok"<< m_db.lastError().text();
      

      Which is successful (ok)

      query.prepare("INSERT INTO t_MNIST ( str64Data, blnTest, intLabel, intGroup ) VALUES ('Get a life', False, 0, 0);");
              if (!query.next()) {
                  qDebug() << (query).lastError();
                  LOG_FAILED_QUERY(query);
                  return;
              }
      

      Which crashes with a hidden exception thrown.

      J Offline
      J Offline
      JonB
      wrote on 27 Oct 2020, 20:42 last edited by JonB
      #2

      @MGirgis
      Hi and welcome.

      You're supposed to go https://doc.qt.io/qt-5/qsqlquery.html#exec-1 :

      query.prepare();
      query.exec();
      query.next();
      
      1 Reply Last reply
      1
      • M Offline
        M Offline
        MGirgis
        wrote on 27 Oct 2020, 21:07 last edited by MGirgis
        #3

        @JonB said in QSQLDriver and Microsoft Access: Crash on insert statement?:

        query.prepare();
        query.exec();
        query.next();

        Hello,

        I tried the above fix by inserting query.exec(); and it still throws an exception when it gets to that line.

        b7dafe42-ab93-471e-a09e-1e6e3f76330d-image.png

        J 1 Reply Last reply 27 Oct 2020, 22:04
        0
        • M MGirgis
          27 Oct 2020, 21:07

          @JonB said in QSQLDriver and Microsoft Access: Crash on insert statement?:

          query.prepare();
          query.exec();
          query.next();

          Hello,

          I tried the above fix by inserting query.exec(); and it still throws an exception when it gets to that line.

          b7dafe42-ab93-471e-a09e-1e6e3f76330d-image.png

          J Offline
          J Offline
          JonB
          wrote on 27 Oct 2020, 22:04 last edited by
          #4

          @MGirgis
          Show code --- we still don't know for example where you declared query, m_db looks like a member variable, yet DBAccess::m_db looks static.

          Better still, run this code under debugger. Look at the stack trace at the exception. I don't know which "that line" is among the lines you have.

          Having said that, I know nothing about QSQLDriver and Microsoft Access.

          1 Reply Last reply
          2

          4/4

          27 Oct 2020, 22:04

          • Login

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