>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.
>
I am just starting an n-tier design with the cursor adatper as ny data object. I am using the Native databse and have set this up in my object. If I try to run a cursorrefresh() after an insert the record that was inserted isn't loaded. How did you do it.
I can get the Update and insert to work, but without manually setting the ID before the insert and changing my SQL command to coincide with the new primary key id, I can't seem to get my data back.
Below is how I got it to work. Can some one help or did I get it right?
DEFINE CLASS opersistentdataobject AS ocursoradapter
idprimarykey = 0
Name = "opersistentdataobject"
lnew = .F.
*-- Adds a new record to the cursor.
PROCEDURE add
LPARAMETERS eItem, cKey, eBefore, eAfter
SELECT (this.Alias)
APPEND BLANK
*!* This.lnew = .T.
ENDPROC
*-- Deletes the record.
PROCEDURE delete
SELECT (this.Alias)
DELETE
ENDPROC
*-- sets the primary id
PROCEDURE setprimaryid
LPARAMETERS tnidPrimaryKey
IF PCOUNT() = 1 AND VARTYPE(tnidPrimaryKey) = 'N'
this.idprimarykey = tnidPrimaryKey
ENDIF
ENDPROC
*-- returns the primary id
PROCEDURE getprimaryid
RETURN this.idprimarykey
ENDPROC
*-- runs a table update to the cursor
PROCEDURE update
LOCAL llReturn
WITH THIS
IF this.lnew
*// If we are inserting a record we will need
.setprimaryid(GETKEY(ALLTRIM(UPPER(.TABLES))))
SELECT (.alias)
REPLACE (.KEYFIELDLIST) WITH .getprimaryid()
*// update the sql statement to match new id.
.SetSQLStatement()
ENDIF
llReturn = TABLEUPDATE(1,.T.,.ALIAS)
IF llReturn
IF !this.lnew
.CURSORREFRESH()
ELSE
.CursorFill
.lnew = .F.
ENDIF
ENDIF
ENDWITH
RETURN llReturn
ENDPROC
*-- resets changes to the cursur since the last change.
PROCEDURE revert
TABLEREVERT(.T,this.Alias)
ENDPROC
PROCEDURE Init
LPARAMETERS tnidPrimaryKey, tcUniqueQueryName
IF PCOUNT() >= 1 AND VARTYPE(tnidPrimaryKey) = 'N'
this.idprimarykey = tnidPrimaryKey
ENDIF
IF PCOUNT() >= 2 AND VARTYPE(tcUniqueQueryName) = 'C'
This.Alias = tcUniqueQueryName
ENDIF
This.InsertCmdDataSourceType ="NATIVE"
This.UpdateCmdDataSourceType ="NATIVE"
This.InsertCmdDataSourceType ="NATIVE"
this.WhereType = 2
ENDPROC
PROCEDURE BeforeInsert
LPARAMETERS cFldState, lForce, cInsertCmd
WITH THIS
DO t
ENDWITH
DODEFAULT( cFldState, lForce, cInsertCmd)
ENDPROC
ENDDEFINE
*
*-- EndDefine: opersistentdataobject
**************************************************
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only