Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retrieving PKs from an inserted row (CursorAdapter)
Message
From
24/10/2003 14:27:21
 
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00841822
Message ID:
00842379
Views:
27
>Hi, George.
>
>>Are you saying that REQUERY() doesn't work? Haven't done much with CAs, so I'd be disappointed if this wasn't the case.
>
>No. It doesn't. Maybe this can be improved somehow in upcoming versions. I'm sure that Aleksey have this in mind. You can see the method he point to solve this, however, in another message on this same thread.
>
>Now I have two personal heroes: you and Aleksey. Don't be jealous. ;-)
>
>Best regards,


Hi Martin,

I am not sure what do you mean by saying that REQUERY doesn't work, but it sure works for me:
CLOSE DATABASES ALL 
CLEAR 

con=SQLSTRINGCONNECT("DRIVER=SQL Server;SERVER=(local);Trusted_Connection=Yes; ")

IF con<1
	?"Failed to connect!!!"
	AERROR(aerrs)
	DISPLAY MEMORY LIKE aerrs
	RETURN 
ENDIF

IF 1!=SQLEXEC(con,[create table #testrequery (id int IDENTITY, f2 int)])
	?"Failed to create table!!!"
	AERROR(aerrs)
	DISPLAY MEMORY LIKE aerrs
	RETURN 
ENDIF

LOCAL oCA as CursorAdapter

oCA=CREATEOBJECT("CursorAdapter")
oCA.Alias="CATest"
oCA.DataSourceType="ODBC"
oCA.DataSource=con
oCA.SelectCmd="select * from #testrequery"
oCA.Tables=[#testrequery]
oCA.KeyFieldList="id"
oCA.UpdatableFieldList = "id, f2"
oCA.UpdateNameList=[id #testrequery.id,f2 #testrequery.f2]

IF !oCA.CursorFill()
	?"CursorFill failed!!!"
	AERROR(aerrs)
	DISPLAY MEMORY LIKE aerrs
ELSE
	SELECT CATest

	INSERT INTO CATest (f2) VALUES (111)
	INSERT INTO CATest (f2) VALUES (111)
	INSERT INTO CATest (f2) VALUES (111)
	INSERT INTO CATest (f2) VALUES (111)

	IF !TABLEUPDATE(.T.)
		?"TABLEUPDATE failed!!!"
		AERROR(aerrs)
		DISPLAY MEMORY LIKE aerrs
	ENDIF
	
	LIST
	
	?REQUERY()
		
	LIST

ENDIF


RETURN 
Here is the result:
Record#           ID          F2
      1            0         111
      2            0         111
      3            0         111
      4            0         111

         1
Record#           ID          F2
      1            1         111
      2            2         111
      3            3         111
      4            4         111
Thanks,
Aleksey.
Previous
Reply
Map
View

Click here to load this message in the networking platform