Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CursorAdapter - Stored Procedure
Message
De
27/03/2003 01:12:46
 
 
À
26/03/2003 09:58:02
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
00769990
Message ID:
00770624
Vues:
32
Hi Chuck,

>Or is there a way to get the CursorAdapter class to work like the VFPCOM.COMUTIL RStoCursor?
>

There is no need to use RsToCursor, CursorAdapter is able to do everything RsToCursor does.

> It seems that the cursoradapter was meant to query the sql table and update the table directly and not with calling stored procedures or am I missing something?
>
CursorAdapter was designed with this scenario in mind. Don't be confused by words: SelectCmd, InsertCmd, UpdateCmd and DeleteCmd. These are just property names, but you can use any command that can be handled by the backend. Here is an example with stored procedures:
CLOSE DATABASES all
CLEAR 
LOCAL con as ADODB.Connection, rs as ADODB.Recordset, com as ADODB.Command 

con=CREATEOBJECT("ADODB.Connection")
con.Open("Provider=SQLOLEDB;Server=(local);UID=;PWD=;trusted_connection=yes")

com=CREATEOBJECT("ADODB.Command")
com.ActiveConnection=con
rs=CREATEOBJECT("ADODB.Recordset")
rs.ActiveConnection=con

* create table and procedures
TEXT to cSql NOSHOW
	CREATE TABLE #test (fk int, f1 int, f2 varchar(10))
	INSERT into #test values (1,1,'old1')
	INSERT into #test values (1,2,'old2')
	INSERT into #test values (2,1,'old1')
	INSERT into #test values (2,2,'old2')
ENDTEXT

com.CommandText=cSql
com.Execute()

TEXT to cSql NOSHOW
	CREATE PROCEDURE #test_select @fk int AS
	SELECT f1,f2 from #test where fk=@fk
ENDTEXT

com.CommandText=cSql
com.Execute()

TEXT to cSql NOSHOW
	CREATE PROCEDURE #test_insert @fk int, @f1 int, @f2 varchar(10) AS
	INSERT into #test values (@fk,@f1,@f2)
ENDTEXT

com.CommandText=cSql
com.Execute()

TEXT to cSql NOSHOW
	CREATE PROCEDURE #test_update @fk int, @oldf1 int, @f1 int, @f2 varchar(10) AS
	update #test set f1=@f1, f2=@f2 where fk=@fk and f1=@oldf1
ENDTEXT

com.CommandText=cSql
com.Execute()

TEXT to cSql NOSHOW
	CREATE PROCEDURE #test_delete @fk int, @oldf1 int AS
	delete from #test where fk=@fk and f1=@oldf1
ENDTEXT

com.CommandText=cSql
com.Execute()

* set up cursor adapter to use procedures and ADO
LOCAL oCA as CursorAdapter
oCA=CREATEOBJECT("CursorAdapter")
oCA.Alias="test"
oCA.DataSourceType="ADO"
oCA.DataSource=rs
oCA.SelectCmd="exec #test_select @fk=?this.Fk"
oCA.AddProperty("Fk",1) 
oCA.InsertCmdDataSourceType="ADO"
oCA.InsertCmdDataSource=com
oCA.InsertCmd="exec #test_insert @fk=?this.Fk, @f1=?test.f1, @f2=?test.f2"
oCA.UpdateCmdDataSourceType="ADO"
oCA.UpdateCmdDataSource=com
oCA.UpdateCmd="exec #test_update @fk=?this.Fk, @oldf1=?OLDVAL('f1','test'),@f1=?test.f1, @f2=?test.f2"
oCA.DeleteCmdDataSourceType="ADO"
oCA.DeleteCmdDataSource=com
oCA.DeleteCmd="exec #test_delete @fk=?this.Fk, @oldf1=?OLDVAL('f1','test')"
oCA.BufferModeOverride= 5

rs.CursorLocation= 3  && adUseClient
oCA.CursorFill(.F.,.F.,-1,com)
SELECT (oCA.Alias)
LIST 

*insert new record
INSERT into test values (3,"inserted")
*update existing record
UPDATE test set f1=24, f2="updated" where f1=2
*delete existing record
DELETE FROM test where f1=1

IF !TABLEUPDATE(.T.)
	AERROR(aerrors)
	DISPLAY MEMORY LIKE aerrors
ENDIF	
IF REQUERY()=0
	AERROR(aerrors)
	DISPLAY MEMORY LIKE aerrors
ENDIF	
LIST

TABLEREVERT(.T.)
oCA.CursorFill(.F.,.F.,-1,com)
SELECT (oCA.Alias)
LIST 

return
Thanks,
Aleksey.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform