FWH 18.11: MARIAROWSET Table Replication Features

FWH 18.11: MARIAROWSET Table Replication Features

Postby nageswaragunupudi » Tue Nov 27, 2018 2: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: Select all  Expand view

oCn:CopyTableToServer( cTable, oRemoteServer )
 


Using the replication feature:

Open connections to main server and also replication server.
Code: Select all  Expand view

oCn := maria_connect( <mainserver>, .... )
oRemote := maria_connect( <remote server>, ... )
 


Open the rowset for the table to edit in the usual way.
Code: Select all  Expand view

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: Select all  Expand view

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: Select all  Expand view
#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.
Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: FWH 18.11: MARIAROWSET Table Replication Features

Postby Carles » Tue Nov 27, 2018 3: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
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Carles
 
Posts: 1137
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona

Re: FWH 18.11: MARIAROWSET Table Replication Features

Postby devtuxtla » Tue Nov 27, 2018 4: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.
devtuxtla
 
Posts: 392
Joined: Tue Jul 29, 2008 1:55 pm


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 60 guests