Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Refreshing a CA cursor after an Insert
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00890969
Message ID:
00891532
Vues:
16
This looks really confusing and I ahve no idea what purpose the CA is providing because you are using the table directly to insert the records into. What is lBankUnit [view? table?] and why do you need to ALTER it every time? Do you have some insert trigger that is populating the UnitID field when you add a record to lBankUnit? I do not understand how the UnitID field is being populated when you add a record and how this all relates to the cUnit cursor created by the CA which, in turn, is just a query on the lBankUnit table.

Usually, you would insert data into the cUnit cursor, issue a tableupdate to post the data back to the source table, the do a loCursorAdapterObjectName.CursorRefresh() to "requery" the CA cursor to get back you inserted data to get any ID value. You should have some WHERE clause in the SelectCmd property. Otherwise, you are retrieving EVERY record from the source table.

>Hi,
>
>When I use a CursorAdapter to insert records into a mySQL table, the new records do not show in the cursor but do get inserted into the database.
>
>I think I need to see these records in order to get the last ID inserted into the table unless there is a better way I can do this.
>
>The First Part of my code:
>
>LPARAMETERS lCloseAll
>TRY
>	IF lCloseAll = .T.
>		CLOSE DATABASES ALL
>	ENDIF
>	IF VARTYPE(oVar) # 'O'
>&&Creation of Empty Object to store Variable Values
>		MakeoVar(SYS(16))  &&Adding a reference to the calling program for log purposes
>	ENDIF
>	PUBLIC lo
>	lo = NEWOBJECT("caUnit")
>	OPEN DATABASE webbanking
>	USE lBankUnit EXCLUSIVE
>	ALTER TABLE lBankUnit ALTER COLUMN UnitID i(4)
>	SELECT lBankUnit
>	SCAN
>		INSERT INTO cUnit (UnitNumber, ;
>			UnitName,;
>			TranDate, ACTIVE) ;
>			VALUES (lBankUnit.UnitNumber, ;
>			PADR(lBankUnit.UnitName,60),
>                        TTOD(lBankUnit.TranDate),1)
>
>It is at this point that I would like to get the value of the UnitID from cUnit . UnitID is a auto_incremented integer field in the mySQL database. When I look at cUnit the record I just inserted is not there.
>
>My code to create the CA:
>
>DEFINE CLASS caUnit AS CURSORADAPTER
>	TAG = "dsn=WebBanking;uid=root;trusted_connection=no;"
>	HEIGHT = 22
>	WIDTH = 23
>	SELECTCMD = "See Init"
>	CURSORSCHEMA = "UNITID I, UNITNUMBER I,
>UNITNAME C(60), TRANDATE D, ACTIVE I, USERID I"
>	ALIAS = "cUnit"
>	DATASOURCETYPE = "ODBC"
>	FLAGS = 0
>	KEYFIELDLIST = "See Init"
>	TABLES = "lbankunit"
>	UPDATABLEFIELDLIST = "See Init"
>	UPDATENAMELIST = "See Init"
>	NAME = "caUnit"
>	PROCEDURE INIT
>		LOCAL llReturn
>		DO CASE
>			CASE NOT pemstatus(THIS, '__VFPSetup', 5)
>				THIS.ADDPROPERTY('__VFPSetup', 0)
>			CASE THIS.__VFPSetup = 2
>				THIS.__VFPSetup = 0
>				RETURN
>		ENDCASE
>		llReturn = DODEFAULT()
>		*** Select connection code: DO NOT REMOVE
>		SET MULTILOCKS ON
>		***<DataSource>
>		THIS.DATASOURCE = SQLSTRINGCONNECT([dsn=WebBanking;uid=root;trusted_connection=no;])
>		***</DataSource>
>		*** End of Select connection code: DO NOT REMOVE
>		*** Setup code: DO NOT REMOVE
>		***<SelectCmd>
>		TEXT to This.SelectCmd noshow
>		select lbankunit.UNITID, lbankunit.UNITNUMBER,
>lbankunit.UNITNAME, lbankunit.TRANDATE,
>lbankunit.ACTIVE, lbankunit.USERID from lbankunit
>		ENDTEXT
>				***</SelectCmd>
>				***<KeyFieldList>
>		TEXT to This.KeyFieldList noshow
>		UNITID
>		ENDTEXT
>				***</KeyFieldList>
>				***<UpdateNameList>
>		TEXT to This.UpdateNameList noshow
>		UNITID lbankunit.UNITID, UNITNUMBER lbankunit.UNITNUMBER, UNITNAME
> lbankunit.UNITNAME, TRANDATE lbankunit.TRANDATE,
>ACTIVE lbankunit.ACTIVE, USERID lbankunit.USERID
>		ENDTEXT
>				***</UpdateNameList>
>				***<UpdatableFieldList>
>		TEXT to This.UpdatableFieldList noshow
>		UNITNUMBER, UNITNAME, TRANDATE, ACTIVE, USERID
>		ENDTEXT
>		***</UpdatableFieldList>
>		*** End of Setup code: DO NOT REMOVE
>		THIS.ALIAS = 'cUnit'
>		THIS.CURSORFILL()
>		IF THIS.__VFPSetup = 1
>			THIS.__VFPSetup = 2
>		ENDIF
>		RETURN llReturn
>
>	ENDPROC
>	PROCEDURE AUTOOPEN
>		*** Setup code: DO NOT REMOVE
>		IF NOT pemstatus(THIS, '__VFPSetup', 5)
>			THIS.ADDPROPERTY('__VFPSetup', 1)
>			THIS.INIT()
>		ENDIF
>		*** End of Setup code: DO NOT REMOVE
>
>	ENDPROC
>
>ENDDEFINE
>
>
>I'm sure it is something stupid I am forgetting. I appreciate any assistance you can provide.
>
>Michael
Mark McCasland
Midlothian, TX USA
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform