Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Use two or more SQLite database at the same time

    General and Desktop
    4
    5
    2811
    Loading More Posts
    • 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.
    • Julian
      Julian last edited by

      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

      jsulm 1 Reply Last reply Reply Quote 1
      • jsulm
        jsulm Lifetime Qt Champion @Julian last edited by

        @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 Reply Quote 8
        • V
          vouchermedia Banned last edited by

          This post is deleted!
          jsulm 1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @vouchermedia last edited by

            @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 Reply Quote 1
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              @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 Reply Quote 1
              • First post
                Last post