Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Receive POST_EVENT Data from FirebirdSql.Data.FirebirdClient Events [DNET931] #294

Closed
firebird-automations opened this issue Mar 11, 2020 · 5 comments

Comments

@firebird-automations
Copy link

Submitted by: kickinespresso (kickinespresso)

annot Receive POST_EVENT Data from FirebirdSql.Data.FirebirdClient Events

Windows 10, FireBird 2.5, .NET Core 3.1

Using the code from the example here: https://github.com/FirebirdSQL/NETProvider/blob/ccb602aa4eb373267423c37bc176ff04fba1d099/Provider/docs/events.md
I am not able to receive POST_EVENT from FireBird.

I was able to use the FirebirdSql.EntityFrameworkCore.Firebird DB Content just fine. Docs here: https://github.com/FirebirdSQL/NETProvider/blob/master/Provider/docs/entity-framework-core.md

Here is my sample Code: https://github.com/cdesch/FireBirdConsoleExample

In my setup (below), I create the database, table and trigger. I also verified that they are working by assigning a new value to FooBar inside the trigger.

When listening for the event on the FirebirdSql.Data.FirebirdClient side, nothing happens.

What am I doing wrong?

/* Here is the Script I used for creating the Database */
CREATE DATABASE 'C:\data\demo.fdb' page_size 8192
user 'SYSDBA' password 'masterkey';

CONNECT "C:\data\demo.fdb"
user 'SYSDBA' password 'masterkey';

create table demo (id int primary key, foobar varchar(20) character set utf8);
insert into demo values (6, 'FooBar');

set term !! ;
CREATE TRIGGER NEW_DEMO_RECORD_TRIGGER FOR demo
ACTIVE before insert
AS BEGIN
IF (inserting) THEN
BEGIN
new.foobar = 'NewFoobar';
POST_EVENT 'NEWFOOBARD_POSTEVENT';
END
END!!
set term ; !!

insert into demo values (7, 'FooBar');

select * from demo;

insert into demo values (8, 'FooBar');

/* Results */
Use CONNECT or CREATE DATABASE to specify a database
SQL> CREATE DATABASE 'C:\data\demo.fdb' page_size 8192
CON> user 'SYSDBA' password 'masterkey';
SQL> CONNECT "C:\data\demo.fdb"
CON> user 'SYSDBA' password 'masterkey';
Commit current transaction (y/n)?y
Committing.
Database: "C:\data\demo.fdb", User: SYSDBA
SQL> create table demo (id int primary key, foobar varchar(20) character set utf8);
SQL> insert into demo values (6, 'FooBar');
SQL> commit;
SQL>
SQL> set term !! ;
SQL> CREATE TRIGGER NEW_DEMO_RECORD_TRIGGER FOR demo
CON> ACTIVE before insert
CON> AS BEGIN
CON> IF (inserting) THEN
CON> BEGIN
CON> new.foobar = 'NewFoobar';
CON> POST_EVENT 'NEWFOOBARD_POSTEVENT';
CON> END
CON> END!!
SQL> set term ; !!
SQL> insert into demo values (7, 'FooBar');
SQL> select * from demo;

      ID FOOBAR

============ ===============================================================================
6 FooBar
7 NewFoobar

SQL> insert into demo values (8, 'FooBar');
SQL> commit;
SQL> select * from demo;

      ID FOOBAR

============ ===============================================================================
6 FooBar
7 NewFoobar
8 NewFoobar

SQL>

/* Output of the console */

Hello World!
Listening...

info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.1.2-rtm-30932 initialized 'MyContext' using provider 'EntityFrameworkCore.FirebirdSql' with options: None
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (6ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "d"."ID", "d"."FOOBAR"
FROM "DEMO" "d"
678
C:\Users\chris\source\repos\FireBirdConsoleExample\FireBirdConsoleExample\bin\Debug\netcoreapp3.1\FireBirdConsoleExample.exe (process 27392) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

@firebird-automations
Copy link
Author

Commented by: kickinespresso (kickinespresso)

SQL Script and Results Gist: https://gist.github.com/cdesch/fe6fc068642265e26aaa8c5f71e9f9d2
Console output Gist: https://gist.github.com/cdesch/c21b6d52dff4a0472fe87a2530ecaf8b

@firebird-automations
Copy link
Author

Commented by: Gerdus van Zyl (angelblaze)

In your code there the QueueEvents call is commented out...
<//events.QueueEvents>("EVENT1", "EVENT2", "EVENT3", "EVENT4");

you need to listen to the specific event name
events.QueueEvents("NEWFOOBARD_POSTEVENT");

@firebird-automations
Copy link
Author

Commented by: @cincuranet

Gerdus is right. You need to call `QueueEvents`. And also in your code, after the `ReadLine` in `FirebirdEventListener`, you dispose the object and hence listening will stop.

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => Closed [ 6 ]

resolution: Incomplete [ 4 ]

@firebird-automations
Copy link
Author

Commented by: kickinespresso (kickinespresso)

Yes. This fixed the issue.

I tried it with and without QueueEvents and didn't have any luck. What i was missing was to call 'commit' in the isql.exe console after the query. like this: "insert into demo values (10, 'FooBar'); commit;"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants