FWH 18.11: DBF to MySql Replication with TDataBase

FWH 18.11: DBF to MySql Replication with TDataBase

Postby nageswaragunupudi » Tue Nov 27, 2018 11:26 pm

TDataBase class in FWH 18.11 version provides a new feature to replicate all changes (append,edit,delete) made to the DBF to a remote MariaDB server.

While we may take backups daily, we are always at the risk of losing transactions between successive backups. This feature helps backing up each transaction as and when it occurs.

Requisites:
1) The DBF should contain an AutoIncrement field.
2) Exact replicated table with the same name should exist on the replication server. Initially, this can be easily setup by calling
Code: Select all  Expand view

oCn:ImportFromDBF( cDBF )
 


How to replicate?
1) Open connection to the MySql server
Code: Select all  Expand view

oCn := maria_Connect( server, database, user, password )
 


Open DBF with TDatabase as usual and set Replication server with the new method.
Code: Select all  Expand view

oDbf := TDataBase():Open( , cDbf )
oDbf:SetReplicationServer( oCn ) // New in FWH 18.11
 

Now the replication is automatic.

fwh\samples\dbf2sql.prg
Code: Select all  Expand view

#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local oCn      := FW_DemoDB()
   local cDbf     := "DBF2SQL.DBF"
   local aStruct  := { { "ID", "+", 4, 0 }, { "FLDCHR", "C", 20, 0 }, { "FLDNUM", "N", 8, 2 } }
   local oDbf, oRs

   local oDlg, oFont, oBold, oBrwDbf, oBrwRs

   SET DELETED ON
   RDDSETDEFAULT( "DBFCDX" )

   SetGetColorFocus()

   // Check Tables
   if !File( cDbf )
      DBCREATE( cDbf, aStruct, "DBFCDX" )
      oCn:ImportFromDBF( Lower( cDbf ) )
   endif

   oDbf  := TDataBase():Open( , cDbf, "DBFCDX" )
   oDbf:SetReplicationServer( oCn )

   // We need not open MySql table.
   // But we open it in the sample to display replication
   oRs   := oCn:RowSet( oDbf:cTable,,.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 : DBF TO MYSQL REPLICATION DEMO"

   @ 60, 20 XBROWSE oBrwDBF SIZE 425,-20 PIXEL OF oDlg ;
      DATASOURCE oDbf ;
      AUTOCOLS CELL LINES NOBORDER FASTEDIT

   @ 60,455 XBROWSE oBrwRS SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oRs ;
      AUTOCOLS LINES NOBORDER

   WITH OBJECT oBrwDbf
      :SetGroupHeader( cDBF, 1, 3, oBold )
      :nEditTypes    := EDIT_GET
      :bOnChanges    := { || oRs:ReQuery(), oBrwRS:Refresh() }
      :bOnRefresh    := { || oRs:Requery(), oBrwRS:Refresh() }
      //
      :CreateFromCode()
   END

   WITH OBJECT oBrwRs
      :SetGroupHeader( "MYSQL SERVER TABLE", 1, 3, oBold )
      :nMarqueeStyle := 0
      :bGotFocus     := { || oRs:ReQuery(), oBrwRS:Refresh() }
      //
      :CreateFromCode()
   END

   @ 10, 20 BTNBMP PROMPT "New" SIZE 100,30 PIXEL OF oDlg FLAT ;
      ACTION oBrwDbf:EditSource( .t. )

   @ 10,140 BTNBMP PROMPT "Edit" SIZE 100,30 PIXEL OF oDlg FLAT ;
      ACTION ( oBrwDBF:EditSource(), oRs:Requery(), oBrwRs:Refresh() )

   @ 10,250 BTNBMP PROMPT "Delete" SIZE 100,30 PIXEL OF oDlg FLAT ;
      ACTION oBrwDBF:Delete()

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont, oBold

   oDbf:Close()
   oRs:Close()
   oCn:Close()

return nil
 


Image
Regards

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

Re: FWH 18.11: DBF to MySql Replication with TDataBase

Postby jose_murugosa » Wed Nov 28, 2018 9:17 am

And I think to my self, what a wonderful work :D

Excelent Mr. Rao
Saludos/Regards,
José Murugosa
FWH + Harbour + Bcc7. Una seda!
User avatar
jose_murugosa
 
Posts: 1144
Joined: Mon Feb 06, 2006 4:28 pm
Location: Uruguay

Re: FWH 18.11: DBF to MySql Replication with TDataBase

Postby AngelSalom » Sun Dec 02, 2018 9:24 pm

:shock: :shock: :shock: :shock: :shock:
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 708
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 90 guests