Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Another CursorAdapter Problem
Message
 
To
16/05/2005 13:18:18
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01014610
Message ID:
01014620
Views:
31
I figured it out.

The goal was to attach a cursor to a CA class and use it to
update backend data.

Here's the updated code that now works:
CLOSE DATABASES all
local oCursor as CursorAdapter

SELECT 0
use	d:\projects\testdata\smts\syserrors

SELECT 0
use	Temp
cursorsetprop("buffering", 5)

oCursor = CREATEOBJECT("CursorAdapter")

with oCursor

	.Alias              = "Temp"
	.BufferModeOverride = 5
	.DataSourceType     = "Native"
	.KeyFieldList       = "recordid"
	.Tables             = "syserrors"
	.UpdatableFieldList = "recordid, error, line"
	.UpdateNameList     = "recordid syserrors.recordid, error syserrors.error, line syserrors.line"

	** Add a record
	SELECT Temp
	SCATTER NAME oRecord
	oRecord.Recordid = "TEST"
	oRecord.Error = 999
	oRecord.Line = 555
	APPEND BLANK
	GATHER NAME oRecord


	** Attach to the CA
	.CursorAttach("Temp")

	** Save changes
	=TABLEUPDATE(1)

endwith

RETURN
>Kevin,
>
>>Can I open a table, create a CA, and update the base tables using it, even
>>if I didn't get the data through the CA?
>
>Yes, you should be able to do that. The update mechanisms are not tied to the way the data was put into the cursor and depend entirely on the CA properties related to updating and the buffered contents of the cursor currently attached.
>
>>Here's my code, which doesn't work:
>
>In your code, I don't see where you are putting anything INTO the temp table AFTER you set the buffering on it, which is the only way to get it automatically updated into the syserrors table. CursorAdapter will create update, insert or delete statements for any records that have changed in the attached buffered cursor (whether they were changed while attached or not), but only for those records added, updated or deleted in the cursor AFTER you turned on the buffering on the table/cursor.
>
>It looks like what you want to do is initialize the CursorAdapter and configure it to write to the syserrors table, then get an initial "errdata" cursor with no data in it with .CursorFill(.F., .T.) -- the second parameters says get me an empty cursor -- then SELECT errdata and APPEND FROM temp (where presumably you have some records you want to get into syserror, then TABLEUPDATE(1) to write the newly appended records from the errdata cursor back to the syserrors table.
>
>...unless I'm completely misunderstanding what you want to accomplish. :-)
>
>
>>
>>
>>
>>CLOSE DATABASES all
>>local oCursor as CursorAdapter, aErrors[1]
>>
>>SELECT 0
>>use	d:\projects\testdata\smts\syserrors
>>
>>SELECT 0
>>use	Temp
>>cursorsetprop("buffering", 5)
>>
>>oCursor = CREATEOBJECT("CursorAdapter")
>>
>>with oCursor
>>
>>   .Alias              = "errdata"
>>   .BufferModeOverride = 5
>>   .DataSourceType     = "Native"
>>   .SelectCmd          = "select * from syserrors"
>>   .KeyFieldList       = "recordid"
>>   .Tables             = "syserrors"
>>   .UpdatableFieldList = "recordid, error, line"
>>   .UpdateNameList     = "recordid syserrors.recordid, error syserrors.error, line syserrors.line"
>>
>>   if .CursorFill()
>>
>>		.CursorAttach("Temp", .T.)
>>		
>>		SELECT Temp
>>     TABLEUPDATE(1)
>>
>>   else
>>
>>     aerror(aErrors)
>>     messagebox(aErrors[2])
>>
>>   endif
>>
>>endwith
>>
>>RETURN
>>
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Reply
Map
View

Click here to load this message in the networking platform