FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour FWH 18.11: DBF to MySql Replication with TDataBase
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
FWH 18.11: DBF to MySql Replication with TDataBase
Posted: 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 (fw): Select all Collapse
oCn:ImportFromDBF( cDBF )


How to replicate?
1) Open connection to the MySql server
Code (fw): Select all Collapse
oCn := maria_Connect( server, database, user, password )


Open DBF with TDatabase as usual and set Replication server with the new method.
Code (fw): Select all Collapse
oDbf := TDataBase():Open( , cDbf )
oDbf:SetReplicationServer( oCn ) // New in FWH 18.11

Now the replication is automatic.

fwh\samples\dbf2sql.prg
Code (fw): Select all Collapse
#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


Regards



G. N. Rao.

Hyderabad, India
Posts: 1279
Joined: Mon Feb 06, 2006 04:28 PM
Re: FWH 18.11: DBF to MySql Replication with TDataBase
Posted: Wed Nov 28, 2018 09:17 AM

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

Excelent Mr. Rao

Saludos/Regards,

José Murugosa

"Los errores en programación, siempre están entre la silla, el teclado y la IA!!"
Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM
Re: FWH 18.11: DBF to MySql Replication with TDataBase
Posted: Sun Dec 02, 2018 09:24 PM

:shock::shock::shock::shock::shock:

Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4

Continue the discussion