Board index » cppbuilder » Porting application containing IBEventAlerter to BCB6
Anatoli M. Dounaevski
![]() CBuilder Developer |
Anatoli M. Dounaevski
![]() CBuilder Developer |
Porting application containing IBEventAlerter to BCB62005-04-21 02:54:22 AM cppbuilder112 I am porting the Interbase application from BCB1 to BCB6. Application contains many BCB1 Data Access and Data Controls VCs. It also uses IBEventAlerter. IBEventAlerter is the problem, because this VC moved to the InterBase group, IBEvents in BCB6. It requires now another way of connection to interbase. Does anybody know the portable solution? Any help is highly appreciated. |
JD
![]() CBuilder Developer |
2005-04-22 11:07:57 AM
Re:Porting application containing IBEventAlerter to BCB6
"Anatoli M. Dounaevski" < XXXX@XXXXX.COM >wrote:
Quote
one of the last things that I learned about IBX). The most important concept to understand is that the IBEvent is performed on the server side and the response to the event is performed on the client side. IOW, the database executes code in response to an event and your application responds to what ever the database might tell it to do as a result of the event. That means that you have to program the database (the server) as well as your application (the client). To program the server, you need to add a stored proc to the database (which you later link into your application using a TIBStoredProc). The stored proc is added to the database by using SQL. There is a utility that allows you to run a script file (.sql) against the database (I don't know the name ... you have to find it). The script file should look like: /* CONNECT TO THE DATABASE */ CONNECT 'C:\SomeThing\SomeThingElse.gdb' USER 'User name' PASSWORD 'a password' ; /* Create Procedure */ SET TERM !! ; CREATE PROCEDURE Event_Alert (Event VARCHAR(20)) AS BEGIN POST_EVENT :Event; END !! SET TERM ; !! /***************************************/ /* Commit the work so far so that */ /* the GRANT will see the PROCS */ /* */ /***************************************/ COMMIT; /* Allow others to execute the proc */ GRANT EXECUTE ON PROCEDURE Event_Alert TO PUBLIC; To explain the above, Event_Alert is the name of the stored proc. It takes, as input, a string (named Event) of 20 max characters that is passed to the built-in database function POST_EVENT. POST_EVENT will pass that string to every user connected to the database. This string becomes the EventName parameter for the TIBEvent OnEventAlert event. This string is how you know what has happened. To raise the event, you simply execute the stored proc when appropriate. For example, if you want to tell the users that you are going to power down, you would execute the proc using a string like 'PowerDown'. Then all clients get IBEvent::OnEventAlert with a string of 'PowerDown'. Before you execute the stored proc, you have to set the string (Event parameter): TIBStoredProc1->ParamByName("Event")->AsString = "PowerDown"; TIBStoredProc1->ExecProc(); Don't forget to call TIBEvent::Register/UnRegisterEvents. ~ JD |
Anatoli M. Dounaevski
![]() CBuilder Developer |
2005-04-23 09:31:53 AM
Re:Porting application containing IBEventAlerter to BCB6
Thanks a lot for the reply. However, my problem is different. Of course, I
implemented both the triggers on the sever and the client C++ code. I belive I did not make myself clear. The problem is in the client C++ code when porting it to BCB6. In the BCB1 I have to say (for simplicity I give the run-time example) TIBEventAlerter* ibEvent1 = new TIBEventAlerter; // construct the alerter ibEvent1->Database = <ptr to TDatabase object>; // connect to the database using BDE ibEvent1->Events->Add( "eventName1"); // add event names... ibEvent1->Events->Add( "eventName2"); ..... ibEvent1->Registered = true; // register the interest In BCB6: IBEvents* ibEvent6 = new TIBEvents; // construct the alerter ibEvent6->Database = <ptr to TIBDatabase object>; // connect to the database. THIS LINE IS NOT PORTABLE ibEvent6->Events->Add( "eventName1"); // add event names... ibEvent6->Events->Add( "eventName2"); ..... ibEvent6->Registered = true; // register the interest In order to connect the alerter to the database, TDatabase object is used in BCB1. In BCB6, TIBEvents must connect to the database via TIBDatabase. This is the problem when porting the legacy code. VCs of these two groups (BDE and Interbase specific) cannot be combined in the code, and the legacy code uses, of course, BDE approach (TDatabase, TSession, TTable, TQuery, etc), because previously BDE was the only way to connect to database (ODBC is too slow). Currently, BCB6 has also the Interbase specific interface: TIBDatabase, TIBTransaction, TIBTable, TIBQuery, etc. When porting I cannot connect TIBEvents to the TDatabase; instead I have to connect it to TIBDatabase. Thus, I have to use the BCB6 TIBeverything instead of Teverything in BCB1, and this is the huge job, because, for example, TQuery to TIBQuery are very different. Does anybody know how to connect TIBEvents to TDatabase or use BCB1 TIBEventAlerter (or its modifications) in BCB6 in order to connect it to TDatabase? Otherwise, each application has to have one more connection (TIBDatabase) exclusively for the TIBEvents. The system I am porting consists of about 10 applications....Too many extra connections to the database... Thanks, everybody. "JD" < XXXX@XXXXX.COM >wrote in message Quote
{smallsort} |
JD
![]() CBuilder Developer |
2005-04-24 01:31:44 AM
Re:Porting application containing IBEventAlerter to BCB6
"Anatoli M. Dounaevski" < XXXX@XXXXX.COM >wrote:
Quote
but a quick check of the hierarchy wasn't helpful. I suspect that you'll need to convert the db. Firebird (SourceForge.net) is an open source clone of IBX (well it started that way but has diverged a bit since then). However, it's reported to work well with the TIBComponents. I would suggest that you post to the InterBase group first. Jeff Overcash, the author of IB, monitors that group so if there is a way, he'll be able to tell you how to do it. ~ JD |