Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Create firebird database programmatically with Qt



  • Hello all!

    I am trying to create a database directly from my code in Qt, but until now I did not have success, Can anyone help me with some article or some code?

    Thanks.


  • Lifetime Qt Champion

    Hi,

    When you say create database do you mean generate/setup the tables ?



  • Hi SGaint, yhank you for the reply.

    No, I need to create a database like CREATE DATABASE 'db_name'... directly from the Qt code, like is done with manager softwares.

    Att
    Guilherme


  • Lifetime Qt Champion

    What did try (code wise) ?
    What error did you get ?
    Do you have the proper credentials on the server to create new databases ?



  • Hello SGaist!

    Yes, I have the credentials but I dont figure out how to do that once QSqlDriver does not have it statement type.

    How could I do that?


  • Lifetime Qt Champion

    Can you post the statement that you want to execute ?



  • I must execute a CREATE DATABASE because I need to create a database from the Qt code, but QSqlDriver does not have a create statement.

    @
    QString queryString;
    queryString += "CREATE DATABASE";
    queryString += " '" + path + "'";
    queryString += " USER 'sysdba'";
    queryString += " PASSWORD 'masterkey'";
    queryString += " DEFAULT CHARACTER SET UNICODE_FSS";
    @


  • Lifetime Qt Champion

    Looks like there's a \ missing after sysdba

    What error are you getting ?



  • Yes SGaist, but the error don not appear in this code. Is is just what I need to create. The error appears when I try to run the code below:

    @
    bool DB::conectarServidorFirebird(QSqlDatabase db)
    {
    bool retorno = true;

    db.setHostName("localhost");
    db.setPassword("gui080381");
    db.setUserName("sysdba");
    //db.setPort(3050);
    
    if(db.open())
    {
        retorno = true;
    }
    else
    {
        qDebug() << db.lastError();
    
        retorno = false;
    }
    
    return retorno;
    

    }
    @

    It returns me the error:
    QSqlError("-901", "Error opening database", "Can't access lock files' directory /tmp/firebird")


  • Lifetime Qt Champion

    Do you have the rights to access /tmp/firebird ?



  • No. I dont think so. But my problem is that I intend to use this database embedded and the user of my software will not have a Firebird group to be inserted in.

    There is some configuration to be made to change permissions?


  • Lifetime Qt Champion

    What's your exact target setup ?



  • I need to create a database using Qt programming with any user that uses the software in any folder it wishes.

    Is it possible?


  • Lifetime Qt Champion

    So you want standard user to be able to do privileged action ?



  • I need to be able to create a database from Qt programming. I can access databases but I cant create it directly from the code using firebird.

    It returns me this error:
    QSqlError("-902", "Error opening database", "cannot attach to password database")

    and sometimes this one:
    QSqlError(”-901”, “Error opening database”, “Can’t access lock files’ directory /tmp/firebird”)

    I am using this code:
    @
    bool DB::conectarServidorFirebird(QSqlDatabase db)
    {
    bool retorno = true;

    db.setHostName("localhost");
    db.setPassword("gui080381");
    db.setUserName("sysdba");
    //db.setPort(3050);
    
    if(db.open())
    {
        retorno = true;
    }
    else
    {
        qDebug() << db.lastError();
    
        retorno = false;
    }
    
    return retorno;
    

    }
    @


  • Lifetime Qt Champion

    Looks more like a firebird setup problem


Log in to reply