Re: simple procedure question by Dan
Dan
Tue Feb 03 12:11:11 CST 2004
See below.
John wrote:
> The comments below indicate what I want to do. Please help me with
> the syntax::
> I have a table called customer with fields: id, firstname, lastname,
> userlock
> I want to write the name of the username parameter to the userlock
> field if I can lock it, and if it is null.
> I want to the procedure to always return the record including the
> userlock field whether the user is successful in locking the record
> to my ADO.Net client. If unsuccessful, my GUI will treat the data as
> read-only.
>
> procedure
> parameters customerId, username
> lparameters alreadyLocked
>
> ** lookup record
> select * from customer where id = customerId
This does not "look up a record". This extracts a record to a separate
recordset. Try Seek() or Locate instead.
>
> ** make sure we found this record (not sure how to do this)
Found() or NOT Eof()
> ** try to lock the record
> if( RLOCK() )
If you are working on a recordset, this will NOT lock the original record.
It will lock the copy in the temporary recordset.
> ** check the userlock field of the customer record to see if
> it's null (not sure how to do this)
If Empty(userlock)
> ** set the userlock field in this record to the username
> of the caller (is this most efficient?)
> update customer set userlock = username where id =
> customerId endif
This would be the least efficient way. Instead...
Replace userlock WITH username
> endif
Endif
>
> ** return the record to the ado.net caller (not sure how to do
> this) endproc
You cannot return a VFP recordset. You can return individual field values,
or you could create and return an ADO recordset.
>
> Thanks in advance.
>
> John
>
>
> "John" <john@nospam.com> wrote in message
> news:OgoLZMg6DHA.1592@TK2MSFTNGP10.phx.gbl...
>> I see your point - thanks for the advice. Getting back to stored
>> procedures - I'm curious. Is there a way to return records from one
>> in FoxPro to an ado.net client?
>>
>> Thanks,
>>
>> John