Identifying changed rows in an Interbase table from a Delphi app -


i know can use tibevents object in application receive events posted interbase server using post_event.

by setting triggers on ib database, can use mechanism notifications when rows updated, inserted or deleted, not rows involved. prevents identifying rows fact event name needs known in advance ibevents object. there simple way identification despite limitation of ibevents object (or, more likely, of post_event mechanism)?

coincidentally, i've been looking topic recently, , today stumbled upon native interbase solution, using relatively new feature known change views (see stephen ball's blog introduction @ https://delphiaball.co.uk/2015/02/06/interbase-change-views-part-1/.

essentially, involves setting on server "subscription" defines tables , kinds of operation of interest (updates inserts , deletes), granting users right subscribe subscription, , setting client application utilize information subscription.

a nice thing change views can used traditional ibx components few lines of code - see example below. haven't tried, can't see reason why couldn't used dbexpress or firedac long support setting transaction type "snapshot".

a couple of wrinkles:

  • unless rollback transaction retrieves changes (as per code below), next time view subscription, won't see changes saw last time. if want see subsequent changes next time, call commit instead of rollback on select query.

  • the subscription implementation hides changes table(s) made under own log-in id, set-up , testing, need use different logins, 1 make changes , other view them.

code:

procedure tform1.openquery; var   sql : string; begin   //  note vital select return desired results   //  transaction type set "snapshot", can done in ide   //  using transaction editor or in code follows    ibtransaction1.params.clear;   ibtransaction1.params.add('concurrency');   ibtransaction1.params.add('nowait');    //  next, activate subscription   sql := 'set subscription "table1changes" active;';   ibquery1.sql.text := sql;   ibquery1.execsql;    //  can retrieve changed rows.  note "where" clause   sql := 'select id, aname, avalue table1 aname changed';  // or "is updated",    //  inserted, or deleted   ibquery1.sql.text := sql;   ibquery1.open;  end; 

as ever dynamic sql in delphi apps application, beware of sql injection.

update: apparently interbase express (ibx) component library has been updated support subscriptions, assume in seattle (which have don't use).


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -