FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour FWH 18.11: MARIAROWSET Table Replication Features
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
FWH 18.11: MARIAROWSET Table Replication Features
Posted: Tue Nov 27, 2018 02:18 PM
FWH 18.11 introduces simple means to replicate changes (edit,append and delete) effected to a table through fwmariarowset object to another remote server, without any effort from the programmer's side. This feature is useful when it is intended to replicate changes to one or more tables to the tables with the same names on another remote server.

It is necessary that the remote server already has identical tables with identical structures and records with the same names. This can be setup initially by using

Code (fw): Select all Collapse
oCn:CopyTableToServer( cTable, oRemoteServer )


Using the replication feature:

Open connections to main server and also replication server.
Code (fw): Select all Collapse
oCn := maria_connect( <mainserver>, .... )
oRemote := maria_connect( <remote server>, ... )


Open the rowset for the table to edit in the usual way.
Code (fw): Select all Collapse
oRs := oCn:RowSet( <mytable> )


The only additional work we need to do for the replication is to assign oRs:oCn2 with the connection to remote server
Code (fw): Select all Collapse
oRs:oCn2 := oRemote


This is enough.
All changes made to <mytable> through the methods of RowSet are automatically written simultaneously to the same table on the remote server also.

Conditions:
Do not change the table with your own SQL statements.
Do not directly modify the replicated tables on the remote server.

\fwh\samples\mariarpl.prg
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oMain    := FW_DemoDB()
   local oRepl    := FW_DemoDB( 6 )
   local oRsMain, oRsRepl
   local oDlg, oFont, oBold, oBrwMain, oBrwRepl

   SetGetColorFocus()

   oRsMain        := oMain:RowSet( "states" )
   oRsMain:oCn2   := oRepl
   oRsRepl        := oRepl:RowSet( "states", , .t. ) // readonly

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   oBold    := oFont:Bold()

   DEFINE DIALOG oDlg SIZE 900,500 PIXEL TRUEPIXEL FONT oFont ;
      TITLE "FWH 18.11 : TABLE REPLICATION"

   @ 20, 20 XBROWSE oBrwMain SIZE 425,-20 PIXEL OF oDlg ;
      DATASOURCE oRsMain ;
      AUTOCOLS CELL LINES NOBORDER

   @ 20,455 XBROWSE oBrwRepl SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oRsRepl ;
      AUTOCOLS CELL LINES NOBORDER

   WITH OBJECT oBrwMain
      :SetGroupHeader( "MAIN SERVER", 1, 3, oBold )
      :nEditTypes    := EDIT_GET
      :bOnChanges    := { || oRsRepl:ReSync(), oBrwRepl:RefreshCurrent() }
      :lColChangeNotify := .t.
      :bChange       := { || oBrwRepl:BookMark := oBrwMain:BookMark, ;
                             oBrwRepl:nRowSel  := oBrwMain:nRowSel,  ;
                             oBrwRepl:nColSel  := oBrwMain:nColSel,  ;
                             oBrwRepl:Refresh() }
      //
      :CreateFromCode()
   END

   WITH OBJECT oBrwRepl
      :SetGroupHeader( "REPLICATION SERVER", 1, 3, oBold )
      :bClrSel       := { || { CLR_WHITE, CLR_GREEN } }

      //
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont, oBold

   oRsMain  := nil
   oRsRepl  := nil

   oMain:Close()
   oRepl:Close()

return nil

Note: It is not necessary to open the table on the remote server. This is opened in the above sample to demonstrate simultaneous changes to the remote table.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Re: FWH 18.11: MARIAROWSET Table Replication Features
Posted: Tue Nov 27, 2018 03:44 PM

Mr. Rao,

Bravo ! :D

Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
Posts: 392
Joined: Tue Jul 29, 2008 01:55 PM
Re: FWH 18.11: MARIAROWSET Table Replication Features
Posted: Tue Nov 27, 2018 04:40 PM

Mr. Rao

Congratulations great job

currently we do it by transaction, but with this option it saves us a lot of code.

regards

Visite Chiapas, el paraiso de México.

Continue the discussion