Use two or more SQLite database at the same time



  • 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


  • Moderators

    @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");
    

  • Banned

    This post is deleted!

  • Moderators

    @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?


  • Lifetime Qt Champion

    @jsulm That was spam message.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.