Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cursor Adapter Question
Message
From
06/05/2004 09:02:30
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Cursor Adapter Question
Miscellaneous
Thread ID:
00901531
Message ID:
00901531
Views:
54
Hello all,

I'm trying to start to develop an n-tier application and I was going to use the cursor adapter for my data tier.
I have developed a cursor adapter class which works great except when I am working with an insert. I have a problem getting the record set back if I use an auto increment. To solve this problem I set the PK value before inserting the record. I them update the SQL cmd to reflect the new PK and call the cursorFill() instead of the CursorRefresh. Isn't there an easier way to accomplish this?
**I added the class code below**

**************************************************
*-- Class: opersistentdataobject (c:\onicon\classlib\dataobjects.vcx)
*-- ParentClass: ocursoradapter (c:\onicon\classlib\dataobjects.vcx)
*-- BaseClass: cursoradapter
*-- Time Stamp: 05/05/04 04:26:11 PM
*
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
*// to create the id and update it before adding the record.
.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

ENDWITH
DODEFAULT( cFldState, lForce, cInsertCmd)
ENDPROC


ENDDEFINE
*
*-- EndDefine: opersistentdataobject
**************************************************
Next
Reply
Map
View

Click here to load this message in the networking platform