implement LETODB

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
fouednoomen
Posts: 188
Joined: Sun Oct 14, 2012 8:33 am
DBs Used: DBF, MySQL, MariaDB, SQLite, PostgreSQL, Oracle, ODBC
Location: Tunisia

Re: implement LETODB

Post by fouednoomen »

how I can connect simultaneously to two LETODB servers from a workstation on the same application

thanks in advance
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: implement LETODB

Post by mol »

I dind't try.
Really interesting
User avatar
fouednoomen
Posts: 188
Joined: Sun Oct 14, 2012 8:33 am
DBs Used: DBF, MySQL, MariaDB, SQLite, PostgreSQL, Oracle, ODBC
Location: Tunisia

Re: implement LETODB

Post by fouednoomen »

I just found this article on a site which confirms the possibility of simultaneously connecting to several servers from a single application but I cannot deploy the solution.
i need your help

Image
Attachments
image.jpg
image.jpg (238.27 KiB) Viewed 6496 times
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: implement LETODB

Post by edk »

Try this:

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, "")
Note: Unlike to RDD "DBFNTX" when referencing DBF files in "LETO" (eg USE, DBCREATE) the default file extension ".DBF" cannot be used, causes error 1010 invalid characters in Alias.
JRGEMS
Posts: 8
Joined: Wed Apr 27, 2016 1:58 pm
Location: Cochin-India

Re: implement LETODB

Post by JRGEMS »

After I add the following line in my main prg, error occurs while compiling.

REQUEST leto
error on compiling:
hbmk2: Error: Referenced, missing, but unknown function(s): LETO()

Regards,
Ramesh Bhat.
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: implement LETODB

Post by edk »

1. Download the package from Marek containing the library "librddleto_20190517.a" (link: http://hmgforum.com/viewtopic.php?p=65987#p65987)

2. Place the downloaded file librddleto_20190517.a in the folder c:\hmg.3.4.4\lib\

3. If you are using the IDE, in the project's * .hbc configuration file enter: libs=rddleto_20190517
or
3. If you are using build.bat: your command line should look like this: call c:\hmg.3.4.4\build.bat project.hbp -lrddleto_20190517
JRGEMS
Posts: 8
Joined: Wed Apr 27, 2016 1:58 pm
Location: Cochin-India

Re: implement LETODB

Post by JRGEMS »

Thank you EDK.
Now it is compiling OK using IDE.
Build.bat still giving same error.
my command prompt build command is:
build.bat jt.hbp jt.hbc
jt.hbc given below:
incpaths=
libpaths=
libs=rddleto_20190517
gt=
mt=yes

Regards,
Bhat.
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: implement LETODB

Post by edk »

Try:
build.bat jt.hbp -lrddleto_20190517
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: implement LETODB

Post by mol »

Hi!
I want to refresh this topic.
Now, I need to connect to read and write data from php application.
Sample attached to leto is working,but it shows only a few information.
Did anybody realize change data from PHP to DBF and vice versa?
User avatar
dragancesu
Posts: 921
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: implement LETODB

Post by dragancesu »

Post Reply