Issue Details (XML | Word | Printable)

Key: DNET-931
Type: Bug Bug
Status: Closed Closed
Resolution: Incomplete
Priority: Major Major
Assignee: Jiri Cincura
Reporter: kickinespresso
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
.NET Data provider

Cannot Receive POST_EVENT Data from FirebirdSql.Data.FirebirdClient Events

Created: 11/Mar/20 05:24 PM   Updated: 11/Mar/20 06:08 PM
Component/s: None
Affects Version/s: 7.5.0.0
Fix Version/s: None

Environment: Windows 10, FireBird 2.5, .NET Core 3.1


 Description  « Hide
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 . . .


 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order

Gerdus van Zyl added a comment - 11/Mar/20 05:41 PM
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");


Jiri Cincura added a comment - 11/Mar/20 05:57 PM
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.

kickinespresso added a comment - 11/Mar/20 06:08 PM
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;"