Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CursorAdapter Performance Issue
Message
De
16/03/2003 13:40:49
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00765148
Message ID:
00766347
Vues:
18
Here is the code:
CLOSE DATABASES all
CLEAR
SET MULTILOCKS ON 

CREATE CURSOR foo (f1 I, f2 I)
INDEX ON f1 TAG f1

INSERT INTO foo values(1,1)
INSERT INTO foo values(1,2)
INSERT INTO foo values(2,3)
INSERT INTO foo values(2,4)
INSERT INTO foo values(2,5)
INSERT INTO foo values(2,6)

LOCAL oCA as CursorAdapter
oCA=CREATEOBJECT("CATest1")

IF !oCA.CursorFill(.F.,.T.)
	AERROR(aerrors)
	DISPLAY MEMORY LIKE aerrors
ENDIF

SELECT(oCA.Alias)
?ALIAS()
LIST

REQUERY()
?ALIAS()
LIST

oCA.CurrentKey=2
REQUERY()
?ALIAS()
LIST

* add new record
INSERT INTO (oCA.Alias) values(2,7)
TABLEUPDATE(.F.)
?ALIAS()
LIST

SELECT foo
?ALIAS()
LIST


DEFINE CLASS CATest1 AS CursorAdapter
	DataSourceType="NATIVE"
	Alias="test"
	SendUpdates=.F.

	* custom properties
	BaseTable=DBF("foo") 
	Order="f1"
	CurrentKey=1
	NoDataKey=0

	FUNCTION CursorFill(luseCursorSchema, lNoData, nOptions, Source)
		NODEFAULT && this is important
		LOCAL lRetVal
		lRetVal=.T.
		TRY
	    	IF(this.CursorStatus!=0)
    	    	USE IN (this.Alias)
	    	ENDIF

	    	USE (this.BaseTable) IN 0 AGAIN ALIAS (this.Alias)
		    SET ORDER TO (this.Order) IN (this.Alias)
		    if(lNoData)
		    	SET KEY TO this.NoDataKey IN (this.Alias)
		    ELSE
		    	SET KEY TO this.CurrentKey IN (this.Alias)
		    ENDIF
    		lRetVal=this.CursorAttach(this.Alias)
    		IF lRetVal
			    SELECT (this.Alias)
			    GO TOP
			ENDIF    
		Catch 
			lRetVal=.F.
		ENDTRY
	    RETURN lRetVal
	ENDFUNC

	FUNCTION CursorRefresh ()
		NODEFAULT && this is important
		LOCAL lRetVal
		lRetVal=.T.

		TRY
			IF(this.CursorStatus!=0)
			    SET ORDER TO (this.Order) IN (this.Alias)
		    	SET KEY TO this.CurrentKey IN (this.Alias)
            	GO TOP
        	ELSE
    	        ERROR("There is no cursor to refresh!")        
	        ENDIF
		Catch 
			lRetVal=.F.
		ENDTRY
	    RETURN lRetVal
	ENDFUNC
	
	FUNCTION CursorAttach(cAlias, lInheritCursorProperties)
		NODEFAULT && this is important
		LOCAL lRetVal
		lRetVal=.T.

		TRY
			IF DBF(cAlias)!=this.BaseTable
				ERROR("Can not attach cursor (wrong base table)")
			ENDIF
	        lRetVal=DODEFAULT(cAlias,.F.)
		Catch 
			lRetVal=.F.
		ENDTRY
	    RETURN lRetVal
	ENDFUNC
ENDDEFINE
Thanks,
Aleksey Tsingauz.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform