#DEFINE crlf CHR(13) + CHR(10)
************************	inceput conecteaza ***************************
*** foloseste gnHandle
***************************************************************************
PROCEDURE conecteaza 
	LPARAMETERS tcHost, tcUser, tcPassword

	LOCAL laEroare[1]
	*:Global gnHandle

	gnHandle = SQLCONNECT(tcHost, tcUser, tcPassword)
	IF gnHandle < 1
		AERROR(laEroare)
		eroaresql(@laEroare, "Conectare " + tcUser + '@' + tcHost)
	ENDIF

	RETURN m.gnHandle
ENDPROC

************************	inceput conecteazaH ***************************
*** foloseste gnHandle
***************************************************************************
PROCEDURE conecteazaH 
	LPARAMETERS tcHost, tcUser, tcPassword

	LOCAL laEroare[1], lnHandle
	lnHandle = SQLCONNECT(tcHost, tcUser, tcPassword)
	IF lnHandle < 1
		AERROR(laEroare)
		eroaresql(@laEroare, "Conectare " + tcUser + '@' + tcHost)
	ENDIF

	RETURN m.lnHandle
ENDPROC


**************************** inceput executaSql ***************************
*** foloseste gnHandle
***************************************************************************
FUNCTION executaSql
	LPARAMETERS tcSql, tcCursor, tlShowErr

	LOCAL laEroare[1], lcCursor, lcSql, llShowErr, lnHandle, lnSucces
	lnSucces = -1

	lcCursor = iif(!empty(m.tcCursor), m.tcCursor, "")
	lnHandle = m.gnHandle
	lcSql = m.tcSql
	llShowErr = m.tlShowErr
	
	IF m.lnHandle > 0
		lnSucces = SQLEXEC(m.lnHandle, m.lcSql, m.lcCursor)

		IF m.lnSucces < 0 AND m.llShowErr
			AERROR(laEroare)
			eroaresql(@laEroare, m.lcSql)
		ENDIF
	ENDIF

	RETURN m.lnSucces
ENDFUNC

**************************** inceput executaSqlH ***************************
*** foloseste tnHandle
***************************************************************************
FUNCTION executaSqlH
	LPARAMETERS tnHandle, tcSql, tcCursor, tlShowErr, taEroare
	
	EXTERNAL ARRAY taEroare
	LOCAL laEroare[1], lcCursor, lcSql, llShowErr, lnHandle, lnSucces
	lnSucces = -1

	lcCursor = iif(!empty(m.tcCursor), m.tcCursor, "")
	lnHandle = m.tnHandle
	lcSql = m.tcSql
	llShowErr = m.tlShowErr
	
	IF m.lnHandle > 0
		lnSucces = SQLEXEC(m.lnHandle, m.lcSql, m.lcCursor)

		IF m.lnSucces < 0 
			AERROR(taEroare)
			IF m.llShowErr
				eroaresql(@taEroare, m.lcSql)
			ENDIF 	
		ENDIF
	ENDIF

	RETURN m.lnSucces
endfunc

*************************	inceput deconecteaza ************************
*** foloseste gnHandle
***************************************************************************
FUNCTION  deconecteaza
	
	LOCAL lnHandle, lnSucces
	lnHandle = m.gnHandle
	lnSucces = -1
	IF m.lnHandle > 0
		lnSucces = SQLDISCONNECT(m.lnHandle)
	else 
		AERROR(laEroare)
		eroaresql(@laEroare, "Deconectare Handle = " + alltrim(str(m.lnHandle)))		
	ENDIF

	RETURN m.lnSucces
ENDFUNC

*************************	inceput deconecteaza ************************
*** foloseste gnHandle
***************************************************************************
FUNCTION  deconecteazaH
	LPARAMETERS tnHandle

	LOCAL lnHandle, lnSucces
	
	lnHandle = m.tnHandle
	lnSucces = -1
	IF m.lnHandle > 0
		lnSucces = SQLDISCONNECT(m.lnHandle)
	else 
		AERROR(laEroare)
		eroaresql(@laEroare, "Deconectare Handle = " + alltrim(str(m.lnHandle)))		
	ENDIF

	RETURN m.lnSucces
ENDFUNC
*******************************	inceput eroareSql **********************************
PROCEDURE eroaresql
	LPARAMETERS laErr, lcsql

	LOCAL lcMesaj
	EXTERNAL ARRAY laErr

	lcMesaj = [Eroare # : ] + ALLTRIM(STR(laErr(1))) + crlf + ;
		[Mesajul : ] + laErr(2) + ;
		IIF(!EMPTY(laErr(3)), [Eroare OLE : ] + laErr(3) ,[]) + ;
		[Aplicatie : ] + laErr(4) + ;
		IIF(PCOUNT() = 2, crlf + lcsql, [])
	MESSAGEBOX(lcMesaj,0+16)

ENDPROC
               