Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SPT, updatable cursor and last identity value
Message
 
 
To
07/04/2010 13:29:00
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Vista
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01458392
Message ID:
01459203
Views:
42
Fabio,

Please read the problem defintion one more time. The SPT cursor is made updatable using technique similar to the one outlined in Vald's blog (so essentially it becomes a remote view).

After that we do simple append blank (on insert, doesn't matter) and then tableupdate.

My question is how can I get the ID in this particular scenario.

>>>>>>Hi everybody,
>>>>>>
>>>>>>We're using SPT and then a special program to make cursor updatable. I see this code to get the last inserted value
>>>>>>
>>>>>> mysqlexec("select @@identity as keyval",'csrKeyVal', program())
>>>>>>
>>>>>>which doesn't look entirely correct to me - who guarantees that by doing a separate query you'll get the value of the record you just inserted and not someone else in between?
>>>>>>
>>>>>>Is there a better way to get the latest value?
>>>>>>
>>>>>>Thanks in advance.
>>>>>
>>>>>Of course it is not correct. You cannot even guarantee it doing in the same query batch. There are other and reliable ways like:
>>>>>
>>>>>select scope_identitity()
>>>>>
>>>>>select ... from inserted
>>>>>
>>>>>output clause
>>>>>
>>>>>Cetin
>>>>
>>>>I don't understand how can we use them for the cursor made updatable using technique similar to Vlad's blog. In other words, there is no INSERT command, the changes are done in the cursor, then we do TABLEUPDATE. Then we need to get the ID back. How can we do this?
>>>
>>>1) Bind the cursor to a cursoradapter
>>>2) set BatchUpdateCount = 1
>>>
>>>3) 
>>>PROC AfterInsert
>>>LOCAL id
>>>#IF SQL 2008
>>>id = cast(null as i)
>>>SQLEXEC(m.this.DataSource,"select ?@m.id=SCOPE_IDENTITY()")
>>>#ELSE
>>>SQLEXEC(m.this.DataSource,"select id=SCOPE_IDENTITY()","DUMMY")
>>>id = DUMMY.id
>>>USE
>>>#ENDIF
>>>
>>
>>I understand that CA could have solved the problem. But this is the already written application and it uses SPT. In SPT is there any way to get the ID back correctly? I left the code alone (it is probably working OK 99%).
>
>Except for INSTEAD TRIGGER, OUTPUT and SCOPE_IDENTITY working properly.
>
>With SPT simply add ";SELECT id=SCOPE_IDENTITY()" to the "INSERT ... " string.
>
>But TABLEUPDATE thing has to do with SPT?
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform