Using Qt Stored Procedure in Firebird

Good afternoon, I am starting in the world of Qt and the Firebird database. And we complete the driver installation process and perform the operations of inserting, updating and consulting in the database. When I started doing stored procedures and running them from Qt, it didn't work. We always fail, that everything was perfect, but the database does not work. I program on Linux using Qt 2.0.1 and Firebird 2.1. I create a simple stored procedure test that makes it paste into a table. It works by starting the console, but when trying to start fromQt it does not work and does not give me any errors. SQL code:

SET TERM ^ ;CREATE PROCEDURE AGREEGAR_UNO AS BEGIN insert into JUEGO(CODIGO,ESCRUTINIO,ESTADO,FECHA,HORAINICIO) values (next value for GNECODIGOJUEGO,'111,123,154,169,178','Hi', current_date, current_time);END^SET TERM ; ^
GRANT EXECUTE ON PROCEDURE AGREEGAR_UNO TO SYSDBA;

The following code will be used to connect to firebird from Qt

bool VentanaPrueba::conectar()
{
this->db= QSqlDatabase::addDatabase("QIBASE","Data");
this->db.setDatabaseName("./BD/Data.fdb");
this->db.setPassword("password");
this->db.setUserName("SYSDBA");
if(!db.open())
{
return false;
}
else
return true;
}

And this is the code that is responsible for calling the procedure

void VentanaPrueba::procedimiento()
{
if (!this->db.isOpen()) this->conectar();
if(this->db.isOpen())
{ QSqlQuery procedimiento = QSqlQuery::QSqlQuery(this->db);
bool bandera = procedimiento.prepare("EXECUTE PROCEDURE AGREEGAR_UNO");
QString err = procedimiento.lastError().text();
bool respuesta= procedimiento.exec();
//this->db.commit();
if(!respuesta)
{
this->db.close();
}else
{
procedimiento.finish();
this->db.commit();
this->db.close();
}


}else{
//error
}


}

Many thanks for your help.

+3
3

, firebird, :

procedimiento.prepare("BEGIN EXECUTE PROCEDURE AGREEGAR_UNO; END;");

PL/SQL

BEGIN
  EXECUTE PROCEDURE AGREEGAR_UNO;
END;

Oracle Qt "BEGIN" "END"; . " " , Firebird.
, Qt 4, .

0

There is an easier way, albeit a bit strange.

Create a stored procedure in firebird with some output variable to pause and a VARCHAR input variable (1024) to pass the procedure call.

And call it in Qt with the procedure call as a string parameter.

       SET TERM ^ ;
create PROCEDURE SP_EXECUTE (STMNT varchar(1024) )
    RETURNS (
        INRETURN integer )
    AS
    BEGIN
        execute statement stmnt;
    inReturn=1;
    suspend;
    END^
    SET TERM ; ^
    }

Then in Qt,

procedimiento.prepare("SELECT INRETURN FROM SP_EXECUTE('EXECUTE PROCEDURE AGREEGAR_UNO')");
0
source

All Articles