在 Firebird 中使用 Qt 存储过程

发布于 2024-11-14 19:00:32 字数 1415 浏览 5 评论 0原文

下午好, 我从Qt和Firebird数据库的世界开始,完成驱动程序安装过程并执行数据库插入、更新和咨询操作。 当我开始制作存储过程并从 Qt 运行它们时,它不起作用。不会失败,并且总是认为一切都很完美,但数据库不运行。 我正在使用 Qt 2.0.1 和 Firebird 2.1 在 Linux 中编程 我创建了一个简单的存储过程测试,使其插入到表中。它通过运行控制台来工作,但是当尝试运行 fromQt 时不起作用并且不会给我任何错误。 SQL 代码是:

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;

以下代码将用于从 Qt 连接到 firebird

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;
}

这是负责调用过程的代码

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
}


}

谢谢非常感谢您的帮助。

Good Afternoon,
I'm starting in the world of Qt and a Firebird database.And finish the driver installation process and perform operations onthe database insert, update and consultation.
When I started to make stored procedures and run them from Qt did not work. Does not fail and always us that everything was made ​​perfect, but the database does not run.
I am programming in Linux using Qt 2.0.1 and Firebird 2.1
I create a simple stored procedure test which makes it an insert into a table. It works by running the console but when trying to run fromQt does not work and gives me no errors.The SQL code is:

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 use 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
}


}

Thank you very much for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

久随 2024-11-21 19:00:32

IBPP 或 InterBase Plus Plus 是一个客户端接口项目,它将 Qt 与 Interbase 数据库系统(如 firebird)连接。使用它您可以轻松使用您的 firebird 数据库。从 http://sourceforge.net/projects/ibpp/files/ 或 ibpp 官方网站,并解压。将 core 文件夹复制到您的项目文件夹中。并将这些文件添加到您的 Qt 项目中。
阅读完整指南:
https://rongsheng007.wordpress .com/2010/08/23/make-qt-applications-work-with-firebird-database/

IBPP or InterBase Plus Plus is a client interface project which connects for Qt with Interbase database system like firebird. Using it you can easily use your firebird database. Download its source code package from http://sourceforge.net/projects/ibpp/files/ or ibpp official site, and unpack. Copy the core folder into your project folder. And add these files in your Qt project.
Read complete guide at
https://rongsheng007.wordpress.com/2010/08/23/make-qt-applications-work-with-firebird-database/

怀念你的温柔 2024-11-21 19:00:32

我不知道这是否适用于 firebird,但您可以尝试以下操作:

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

这类似于

BEGIN
  EXECUTE PROCEDURE AGREEGAR_UNO;
END;

我使用 Qt 访问 Oracle 数据库的 PL/SQL 段落,并且必须包含“BEGIN”和“END;”那里有命令。您在 oracle 中没有“EXECUTE PROCEDURE”,但 Firebird 可能需要它。
另外,我使用的是 Qt 4,所以也可能存在差异。

I can't tell if this works for firebird, but you could try the following:

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

This is similar to the PL/SQL passage

BEGIN
  EXECUTE PROCEDURE AGREEGAR_UNO;
END;

I am accessing Oracle databases with Qt and had to include the "BEGIN" and "END;" commands there. You don't have the "EXECUTE PROCEDURE" in oracle, but it might be required for Firebird.
Also, I am using Qt 4 so there might be a difference as well.

塔塔猫 2024-11-21 19:00:32

有一种更简单的方法,尽管有点奇怪。

在 firebird 中创建一个存储过程,其中包含一些要挂起的输出变量,以及一个 VARCHAR(1024) 输入变量来传递过程调用。

并在 Qt 中以过程调用作为字符串参数来调用它。

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

然后在Qt中,

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

There is a simpler way, even though little bit weird.

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

And call it in Qt with 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')");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文