PROCEDURE gencursor
	PARAMETERS tcnume, tcalias, tcselect, tcfiltru, tcschema, tcorder, tlAfisare, tcgroup, tlModParam, tcFiltruOriginal

&& lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal
&& MODIFICAT 28.02.2005
&& tlModParam = .T. daca gencursor functioneaza fara WHERE inclus in tcSelect original
&& tcFiltruOriginal : .T. daca conditia care urmeaza dupa where este salvata si adaugata la query-urile ulterioare

	LOCAL llModParam, lcFiltruOriginal

	IF EMPTY(tlModParam) OR TYPE('tlModParam') # 'L'
		llModParam = .F.
	ELSE
		llModParam = tlModParam
	ENDIF

	IF EMPTY(tcFiltruOriginal) OR TYPE('tcFiltruOriginal') # 'C'
		lcFiltruOriginal = ''
	ELSE
		lcFiltruOriginal = ALLTRIM(tcFiltruOriginal)
	ENDIF

	&tcnume=NEWOBJECT('deca_baza')
	&tcnume..ADDOBJECT('ca_baza1','ca_baza')
	
	IF TYPE('goConn') = 'O'
		&tcNume..datasource = goConn.nHandle
	ELSE
		IF TYPE('gnHandle') = 'N'
			&tcNume..datasource = gnHandle				
		ENDIF 
	ENDIF 

	*lcSelect = TRANSFORM(UPPER(ALLTRIM(tcSelect)),[']
	
	

	LOCAL laEroare
	DECLARE laEroare[1]

	lnpCount = PCOUNT()
	llAfisare = tlAfisare

	WITH &tcnume..ca_baza1
		IF lnpCount > 6
			.lAfisare = llAfisare
		ENDIF
		.ALIAS=ALLTRIM(UPPER(tcalias))
		IF !EMPTY(tcschema)
			IF INLIST(LEFT(tcschema,1),['],["],'[')
				.CURSORSCHEMA=&tcschema
			ELSE
				IF LEN(tcschema) > 250
					lngrupe = CEILING(LEN(tcschema)/250)
					lcgrupa = tcschema
					FOR i = 1 TO lngrupe
						lcgrupat = LEFT(lcgrupa,250)
						.CURSORSCHEMA = .CURSORSCHEMA + lcGrupat
						lcgrupa = SUBSTR(lcgrupa,251)
					ENDFOR 
				ELSE 
					.CURSORSCHEMA=tcschema
				ENDIF 
			ENDIF
		ENDIF
		IF INLIST(LEFT(tcselect,1),['],["],'[')
			.SELECTCMD = &tcselect
			.cSelect = &tcselect
		ELSE 
			IF LEN(tcselect) > 250
				lngrupe = CEILING(LEN(tcSelect)/250)
				lcgrupa = tcSelect
				FOR i = 1 TO lngrupe
					lcgrupat = LEFT(lcgrupa,250)
					.SELECTCMD = .SELECTCMD + lcGrupat
					.cSelect = .cSelect + lcGrupat
					lcgrupa = SUBSTR(lcgrupa,251)
				ENDFOR 
			ELSE 
				.SELECTCMD = tcselect
				.cSelect = tcselect		
			ENDIF 
		ENDIF 
*!*			STRTOFILE(.selectcmd,[c:\selectcmd.txt])
	
		.cfiltru=ALLTRIM(UPPER(tcfiltru))
		IF !EMPTY(tcorder)
			.cOrder=ALLTRIM(UPPER(tcorder))
		ENDIF
		IF !EMPTY(tcgroup)
			.cGroup=ALLTRIM(UPPER(tcgroup))
		ENDIF
		.lModParam = llModParam
		.cFiltruOriginal = lcFiltruOriginal
	ENDWITH

	*!*		IF !USED(tcAlias)
	*!*			AERROR(laEroare)
	*!*			IF TYPE('LAEROARE')!= 'U'
	*!*				IF ALEN(laEroare) > 1
	*!*					IF TYPE('goLog')='O'

	*!*						lcLog = laEroare(3) + CHR(13) + 'SELECT: ' + tcSelect + CHR(13) + 'SCHEMA: ' + tcSchema + CHR(13) + 'FILTRU: ' + tcFiltru + CHR(13) + 'ORDINE: ' + tcOrder
	*!*						goLog.Log(lcLog,PROGRAM())
	*!*					ENDIF
	*!*					MESSAGEBOX(laEroare(3),0+16,"Eroare")

	*!*				ENDIF
	*!*			ENDIF
	*!*		ENDIF
	*!*		RELEASE laEroare
ENDPROC

PROCEDURE gencursor_hash
	PARAMETERS toHash

	LOCAL lcNume, lcAlias, lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal
	
	lcNume = toHash.GetValue('cNume')
	lcAlias = toHash.GetValue('cAlias')
	lcSelect = toHash.GetValue('cSelect')
	lcFiltru = toHash.GetValue('cFiltru')
	lcSchema = toHash.GetValue('cSchema')
	lcOrder = toHash.GetValue('cOrder')
	llAfisare = toHash.GetValue('lAfisare')	
	lcGroup = toHash.GetValue('cGroup')
	llModParam = toHash.GetValue('lModParam')		
	lcFiltruOriginal = toHash.GetValue('cFiltruOriginal')

	= gencursor(lcnume, lcalias, lcselect, lcfiltru, lcschema, lcorder, llAfisare, lcgroup, llModParam, lcFiltruOriginal)

ENDPROC && gencursor_hash