Newbie question.
I am using Web connection and wwBusinessObject with data in sql server.
Is web connection able to work with primary keys that are autoincremented identity fields or is it required that the value of the pk be calculated with the provided stored procedure sp_ww_newid?
If web connection is able to use an auto-incremented pk, how do you find out the just generated pk?
Thank you very much,
Alex
Yes - we covered how you can override NewId()
and just have it do nothing.
You can retrieve the identity key with the @@identity value from SQL Server which returns the last identity value that was created.
if (!loBus.Save())
? loBus.cErrorMsg
RETURN
endif
loBus.Execute("select @@identity as Id","TQuery")
loBus.oData.id = TQuery.Id
use in TQuery
You can override the Save()
method of your business object - call DoDefault()
and then run that and assign the value to the entity.
FUNCTION Save()
IF (!DoDefault())
RETURN .F.
ENDIF
lcAlias = Alias()
*** If Id is not set yet (ie. save) try to retrieve it
IF THIS.oData.id < 1 AND ;
THIS.Execute("select @@identity AS id","TQuery") = 1
this.oData.id = TQuery.Id
ENDIF
use in TQuery
IF !EMPTY(lcAlias)
select (lcAlias)
ENDIF
ENDFUNC
+++ Rick ---