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. Use two or more SQLite database at the same time
QtWS25 Last Chance

Use two or more SQLite database at the same time

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 3.3k 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.
  • JulianJ Offline
    JulianJ Offline
    Julian
    wrote on last edited by
    #1

    Hello people I have this compiler's ouput


    QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
    QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.


    It's because I use a database:

        db= QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName(nombre);
        db.open();
        createTablaSemaforos();
    

    And then I need to use other one (That depends on an event )

    
            fallas= QSqlDatabase::addDatabase("QSQLITE");
            fallas.setDatabaseName(texto);
            fallas.open();
    
    
        QString consulta;
        consulta.append("CREATE TABLE IF NOT EXISTS ");
        consulta.push_back(ui->lineEdit_interseccion->text().remove(" "));
    
    
        consulta.push_back("(a TEXT primary key, j TEXT);");
    
        QSqlQuery crear(fallas);
        crear.prepare(consulta);
        crear.exec();
    

    And I never close db.

    The problem it's that I will always have to use db, and there is a lot of fallas database and it' will open deppends of an event.

    Is there any way to not have to close db to open other database ? to use both

    regards

    jsulmJ 1 Reply Last reply
    1
    • JulianJ Julian

      Hello people I have this compiler's ouput


      QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
      QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.


      It's because I use a database:

          db= QSqlDatabase::addDatabase("QSQLITE");
          db.setDatabaseName(nombre);
          db.open();
          createTablaSemaforos();
      

      And then I need to use other one (That depends on an event )

      
              fallas= QSqlDatabase::addDatabase("QSQLITE");
              fallas.setDatabaseName(texto);
              fallas.open();
      
      
          QString consulta;
          consulta.append("CREATE TABLE IF NOT EXISTS ");
          consulta.push_back(ui->lineEdit_interseccion->text().remove(" "));
      
      
          consulta.push_back("(a TEXT primary key, j TEXT);");
      
          QSqlQuery crear(fallas);
          crear.prepare(consulta);
          crear.exec();
      

      And I never close db.

      The problem it's that I will always have to use db, and there is a lot of fallas database and it' will open deppends of an event.

      Is there any way to not have to close db to open other database ? to use both

      regards

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

      @Julian You are adding connections with same name:

      QSqlDatabase::addDatabase("QSQLITE");
      

      This uses default connection name, see http://doc.qt.io/qt-5/qsqldatabase.html#addDatabase
      Just specify connection names as

      db= QSqlDatabase::addDatabase("QSQLITE", "first_connection");
      fallas= QSqlDatabase::addDatabase("QSQLITE", "second_connection");
      

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

      1 Reply Last reply
      8
      • V Offline
        V Offline
        vouchermedia
        Banned
        wrote on last edited by
        #3
        This post is deleted!
        jsulmJ 1 Reply Last reply
        0
        • V vouchermedia

          This post is deleted!

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

          @vouchermedia I already explained how it should be done above.
          So, what exactly is the problem?
          Is your question related to Qt (you're talking about a website)?
          "If i want to open one db when another data base is open is not possible" - this is not a problem description at all. What exactly does not work? Any errors/warnings? How do you open both databases? Can you show your code?

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

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

            @jsulm That was spam message.

            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
            1

            • Login

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