Re: implement LETODB
Posted: Wed Apr 21, 2021 3:32 pm
how I can connect simultaneously to two LETODB servers from a workstation on the same application
thanks in advance
thanks in advance
Exclusive forum for HMG, a Free / Open Source xBase WIN32/64 Bits / GUI Development System
http://mail.hmgforum.com/
Code: Select all
*******************************************************************************
#include "hmg.ch"
#include "dbinfo.ch"
//#include "leto_std.ch"
REQUEST LETO
//RDDSETDEFAULT( "DBFCDX" )
REQUEST HB_GT_WIN_DEFAULT
REQUEST HB_LANG_PL852
request HB_CODEPAGE_PL852
*----------------------------------------------------------------------------------*
Function Main
*----------------------------------------------------------------------------------*
Local i, plikDBF1, plikNTX1, plikDBF2, plikNTX2, lCreate, pola, plik
public cRDDDriver := "DBFNTX"
public cLocalRDDDriver := "DBFNTX"
public cLetoSerwer1 := "192.168.1.18"
public nLetoSerwerPort1 := 2812
public cLetoSerwer2 := "192.168.1.52"
public nLetoSerwerPort2 := 2812
public nHotbuf := 100
public nTimeOut := 6000
public lUseSerwerLeto1 := .F.
public nStatusLETO1 := -1
public cLetoSerwerPath1 := ""
public lAllowWorkWithoutLetoSerwer := .T.
Public cPath1 := ""
public lUseSerwerLeto2 := .F.
public nStatusLETO2 := -1
public cLetoSerwerPath2 := ""
Public cPath2 := ""
Public cLetoUser := ""
Public cLetoPass := ""
SET LANGUAGE TO POLISH
SET CODEPAGE TO POLISH
SET MULTIPLE OFF WARNING
set( _SET_CODEPAGE, "PL852" )
hb_LangSelect( 'PL852')
************************************
SETBLINK(.F.)
SETCANCEL(.F.)
SET MARGIN TO 0
SET SCOREBOARD OFF
SET WRAP ON
SET CONFIRM ON
SET DATE ANSI
SET ESCAPE OFF
@0,0 CLEA
if !( Empty( cLetoSerwer1 ) .OR. Empty(nLetoSerwerPort1) )
cLetoSerwerPath1 := "//" + Alltrim ( cLetoSerwer1 ) + ":" + Alltrim( Str( nLetoSerwerPort1 ) ) + "/"
lUseSerwerLeto1 := (( nStatusLETO1 := LETO_CONNECT( cLetoSerwerPath1, cLetoUser /*user*/, cLetoPass /*pass*/, nTimeOut /*timeout*/, nHotBuf /*hot buffer*/ )) >= 0)
? "nStatusLETO1", nStatusLETO1
if lUseSerwerLeto1
RDDSETDEFAULT( "LETO" )
cRDDDriver := "LETO"
cPath1 := cLetoSerwerPath1
? "1", LETO_GetServerVersion(), " at address: ", Leto_getLocalIP( .T. )
? "DBF DATABASE DRIVER :", LETO_DBDRIVER()[ 1 ], "MEMOTYPE:", LETO_DBDRIVER()[ 2 ]
? "CurrentConnection: ", LETO_GETCURRENTCONNECTION()
else
if lAllowWorkWithoutLetoSerwer
? "Brak połączenia z serwerem LETO1 ", cLetoSerwerPath1, leto_Connect_Err( .T. )
else
? "Brak połączenia z serwerem LETO1 ", cLetoSerwerPath1, leto_Connect_Err( .T. ), "Program zatrzymany!"
quit
endif
RDDSETDEFAULT( "DBFNTX" )
cRDDDriver := "DBFNTX"
endif
else
lUseSerwerLeto1 := .F.
endif
if !( Empty( cLetoSerwer2 ) .OR. Empty(nLetoSerwerPort2) )
cLetoSerwerPath2 := "//" + Alltrim ( cLetoSerwer2 ) + ":" + Alltrim( Str( nLetoSerwerPort2 ) ) + "/"
lUseSerwerLeto2 := (( nStatusLETO2 := LETO_CONNECT( cLetoSerwerPath2, cLetoUser /*user*/, cLetoPass /*pass*/, nTimeOut /*timeout*/, nHotBuf /*hot buffer*/ )) >= 0)
? "nStatusLETO2", nStatusLETO2
if lUseSerwerLeto2
RDDSETDEFAULT( "LETO" )
cRDDDriver := "LETO"
cPath2 := cLetoSerwerPath2
? "2", LETO_GetServerVersion(), " at address: ", Leto_getLocalIP( .T. )
? "DBF DATABASE DRIVER :", LETO_DBDRIVER()[ 1 ], "MEMOTYPE:", LETO_DBDRIVER()[ 2 ]
? "CurrentConnection: ", LETO_GETCURRENTCONNECTION()
else
if lAllowWorkWithoutLetoSerwer
? "Brak połączenia z serwerem LETO2 ", cLetoSerwerPath2, leto_Connect_Err( .T. )
else
? "Brak połączenia z serwerem LETO2 ", cLetoSerwerPath2, leto_Connect_Err( .T. ), "Program zatrzymany!"
quit
endif
RDDSETDEFAULT( "DBFNTX" )
cRDDDriver := "DBFNTX"
endif
else
lUseSerwerLeto2 := .F.
endif
? "UseLetoSerwer1", lUseSerwerLeto1
? "UseLetoSerwer2", lUseSerwerLeto2
? "RDD: ", RddSetDefault(), " , DBF EXTENSION:", hb_rddInfo( RDDI_TABLEEXT )
inkey ( 5 )
plikDBF1 := cPath1 + "MyFile1.DBF"
plikNTX1 := cPath1 + "Indeksy1.NTX"
lCreate := .F.
if !lUseSerwerLeto1
lCreate := !File( plikDBF1 )
else
lCreate := !Leto_file( plikDBF1 )
endif
? "Create file ", plikDBF1, lCreate
inkey (1)
if lCreate
pola := {}
AADD(pola, {'REGON','N',13,0})
AADD(pola, {'AKT','C',2,0})
AADD(pola, {'DATA','D',8,0})
//file on Leto server #1
DBCREATE( F_DBF (plikDBF1), pola )
DBUseArea(.T., cRDDDriver, F_DBF (plikDBF1), .f., .f.)
INDEX ON regon TO &plikNTX1
FOR i:=1 TO 10
APPEND BLANK
REPLACE regon WITH i
REPLACE akt WITH CHR(i+64)
REPLACE data WITH hb_date() - i
NEXT i
USE
endif
SELECT 1 //file on Leto server #1
plik := F_DBF ( plikDBF1 )
USE &plik INDEX &plikNTX1
? ALIAS()
go top
do while !eof()
? recno()
?? regon
?? akt
?? data
inkey(1)
skip
enddo
plikDBF2 := cPath2 + "MyFile2.DBF"
plikNTX2 := cPath2 + "Indeksy2.NTX"
lCreate := .F.
if !lUseSerwerLeto2
lCreate := !File( plikDBF2 )
else
lCreate := !Leto_file( plikDBF2 )
endif
? "Create file ", plikDBF2, lCreate
inkey (1)
if lCreate
pola := {}
AADD(pola, {'REGON','N',13,0})
AADD(pola, {'AKT','C',2,0})
AADD(pola, {'DATA','D',8,0})
//file on Leto server #2
DBCREATE( F_DBF (plikDBF2), pola )
DBUseArea(.T., cRDDDriver, F_DBF (plikDBF2), .f., .f.)
INDEX ON regon TO &plikNTX2
USE
endif
SELECT 2 //file on Leto server #2
plik := F_DBF ( plikDBF2 )
USE &plik INDEX &plikNTX2
SELECT 1 //file on Leto server #1
GO TOP
DO WHILE !EOF()
SELECT 2 //file on Leto server #2
APPEND BLANK
REPLACE 2->regon WITH 1->regon
REPLACE 2->akt WITH 1->akt
REPLACE 2->data WITH 1->data
SELECT 1 //file on Leto server #1
SKIP
ENDDO
SELECT 2 //file on Leto server #2
? ALIAS()
go top
do while !eof()
? recno()
?? regon
?? akt
?? data
inkey(1)
skip
enddo
close data
Leto_Disconnect( cLetoSerwerPath1 )
Leto_Disconnect( cLetoSerwerPath2 )
? "press any key to exit...."
inkey(0)
QUIT
RETURN
*********************************************
FUNCTION F_DBF ( cFileName )
RETURN hb_FNameExtSet(cFileName, "")