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. Driver not loaded QSQlite when I give connection name
Forum Updated to NodeBB v4.3 + New Features

Driver not loaded QSQlite when I give connection name

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 594 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.
  • P Offline
    P Offline
    philxxx609
    wrote on last edited by
    #1

    Hello,

    When I use QSQlite with

    databaseManager::databaseManager()
    {
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(db_URL);
    }
    void databaseManager::dbinitmagUrl()
    {
        {
            db.open();
            QSqlQuery query(db);
            if(!query.exec("CREATE TABLE IF NOT EXISTS dbMagasin_log (ligne_id INTEGER PRIMARY KEY AUTOINCREMENT, url TEXT)"))
            {
                qDebug() << "query return error at line:"<<QString::number(__LINE__)<<query.lastError().text();
            }
        }
        QSqlDatabase::removeDatabase("QSQLITE");
    }
    

    My app is working.

    But when I try to use connection name, I receive error

    QSqlDatabasePrivate::removeDatabase: connection 'test' is still in use, all queries will cease to work.
    QSqlQuery::exec: database not open
    "query return null at line:561" QSqlError("", "Driver not loaded", "Driver not loaded")

    databaseManager::databaseManager()
    {
    db = QSqlDatabase::addDatabase("QSQLITE", "test");
    db.setDatabaseName(db_URL);
    }
    void databaseManager::dbinitmagUrl()
    {
        {
            db.open();
            QSqlQuery query(QSqlDatabase::database("test"));
            if(!query.exec("CREATE TABLE IF NOT EXISTS dbMagasin_log (ligne_id INTEGER PRIMARY KEY AUTOINCREMENT, url TEXT)"))
            {
                qDebug() << "query return error at line:"<<QString::number(__LINE__)<<query.lastError().text();
            }
        }
        QSqlDatabase::removeDatabase("test");
    }
    

    Could you help me?

    Thanks a lot

    jsulmJ 1 Reply Last reply
    0
    • P philxxx609

      Hello,

      When I use QSQlite with

      databaseManager::databaseManager()
      {
      db = QSqlDatabase::addDatabase("QSQLITE");
      db.setDatabaseName(db_URL);
      }
      void databaseManager::dbinitmagUrl()
      {
          {
              db.open();
              QSqlQuery query(db);
              if(!query.exec("CREATE TABLE IF NOT EXISTS dbMagasin_log (ligne_id INTEGER PRIMARY KEY AUTOINCREMENT, url TEXT)"))
              {
                  qDebug() << "query return error at line:"<<QString::number(__LINE__)<<query.lastError().text();
              }
          }
          QSqlDatabase::removeDatabase("QSQLITE");
      }
      

      My app is working.

      But when I try to use connection name, I receive error

      QSqlDatabasePrivate::removeDatabase: connection 'test' is still in use, all queries will cease to work.
      QSqlQuery::exec: database not open
      "query return null at line:561" QSqlError("", "Driver not loaded", "Driver not loaded")

      databaseManager::databaseManager()
      {
      db = QSqlDatabase::addDatabase("QSQLITE", "test");
      db.setDatabaseName(db_URL);
      }
      void databaseManager::dbinitmagUrl()
      {
          {
              db.open();
              QSqlQuery query(QSqlDatabase::database("test"));
              if(!query.exec("CREATE TABLE IF NOT EXISTS dbMagasin_log (ligne_id INTEGER PRIMARY KEY AUTOINCREMENT, url TEXT)"))
              {
                  qDebug() << "query return error at line:"<<QString::number(__LINE__)<<query.lastError().text();
              }
          }
          QSqlDatabase::removeDatabase("test");
      }
      

      Could you help me?

      Thanks a lot

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

      @philxxx609 said in Driver not loaded QSQlite when I give connection name:

      db = QSqlDatabase::addDatabase("QSQLITE", "test");
      db.setDatabaseName(db_URL);

      Do NOT store QSqlDatabase instances in variables!
      This is explained in the documentation.

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

      1 Reply Last reply
      2
      • P Offline
        P Offline
        philxxx609
        wrote on last edited by
        #3

        I just saw that, thank you.

        Do you know the best practice to use sqlite in multi users connection?

        jsulmJ 1 Reply Last reply
        0
        • P philxxx609

          I just saw that, thank you.

          Do you know the best practice to use sqlite in multi users connection?

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

          @philxxx609 said in Driver not loaded QSQlite when I give connection name:

          Do you know the best practice to use sqlite in multi users connection?

          Not sure what you mean with "best practice".
          SQlite supports parallel accesses, but if one process is writing the DB will be locked until writing has finished.

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

          P 1 Reply Last reply
          0
          • jsulmJ jsulm

            @philxxx609 said in Driver not loaded QSQlite when I give connection name:

            Do you know the best practice to use sqlite in multi users connection?

            Not sure what you mean with "best practice".
            SQlite supports parallel accesses, but if one process is writing the DB will be locked until writing has finished.

            P Offline
            P Offline
            philxxx609
            wrote on last edited by
            #5

            @jsulm yes that is my problem, so I can not do any thing to avoid the app blocked until the other access finish to write on it

            jsulmJ 1 Reply Last reply
            0
            • P philxxx609

              @jsulm yes that is my problem, so I can not do any thing to avoid the app blocked until the other access finish to write on it

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

              @philxxx609 I'm not sure your app will block. Never used SQLitein such configuration. Try it out and see what happens, maybe your query will fail as long as the database is blocken, in this case your app will not be blocked.

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

              P 1 Reply Last reply
              0
              • jsulmJ jsulm

                @philxxx609 I'm not sure your app will block. Never used SQLitein such configuration. Try it out and see what happens, maybe your query will fail as long as the database is blocken, in this case your app will not be blocked.

                P Offline
                P Offline
                philxxx609
                wrote on last edited by
                #7

                @jsulm yes it 's what is happening

                jsulmJ 1 Reply Last reply
                0
                • P philxxx609

                  @jsulm yes it 's what is happening

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

                  @philxxx609 Then SQLite is not the right database for your use case

                  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