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 RUN
oCn:ImportFromDBF( cDBF )
How to replicate?
1) Open connection to the MySql server
- Code: Select all Expand view RUN
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 RUN
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 RUN
#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