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
Forum Update on Monday, May 27th 2025

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.
  • J Offline
    J Offline
    Julian
    wrote on 2 Mar 2017, 23:40 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

    J 1 Reply Last reply 3 Mar 2017, 05:26
    1
    • J Julian
      2 Mar 2017, 23:40

      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

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 3 Mar 2017, 05:26 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 6 Mar 2017, 08:20 last edited by
        #3
        This post is deleted!
        J 1 Reply Last reply 6 Mar 2017, 08:54
        0
        • V vouchermedia
          6 Mar 2017, 08:20

          This post is deleted!

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 6 Mar 2017, 08:54 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
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 6 Mar 2017, 23:24 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

            1/5

            2 Mar 2017, 23:40

            • Login

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