Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Of @@identity and surrogate keys - HELP!
Message
From
09/12/1999 23:43:49
 
 
To
09/12/1999 21:45:06
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00301334
Message ID:
00301537
Views:
29
Hi Bob,

IMHO Identity fields are a pain in the ass. As someone else here (maybe you?) pointed out, Oracle Sequences make much more sense.

>>If I now (after the initial tableupdate to do the insert) change a field and try to update again, it fails because the code generated by TableUpdate() still looks for "where keyfield = 0" I can see this in SQL Profiler. Now - even IF I REPLACE the keyfield in the cursor with the correct identity#, tableupdate STILL uses "where keyfield = 0" in its update statement!! Refresh() doesn't have any effect either.
>>
>
>OK... I ran through this scenerio... and, you can put this in your book of Stupid FoxPro Tricks (others call it a bug)... For some reason, the non-updatable field is retaining a field state of 2 after you do the replace. Changing the record pointer seems to eleviate this problem... so, if after you did your replace MyView_PK with SQLRESULT.EXP you moved to another record, and then back, make a change, your tableupdate would work... at least my testing showed this.
>
>Here is the 'trick'... after you do the replace issue this line of code...
>
>goto recno()
>
>HA!... don't laugh... it worked for me. Here is the code I tested with... I added an Identity field to the Authors Table of the PUBS sample data...
>
>
>select PUBS_AUTHORS
>
>Append Blank
>Replace ;
>	Au_ID with '999-99-'+left(tran(seconds()),4),;
>	Au_Lname with 'LastName',;
>	Au_FName with 'FirstName',;
>	Phone with '999 555-7878',;
>	Address with '1 First Street',;
>	City with 'Tampa',;
>	State with 'FL',;
>	ZIP with '33624',;
>	Contract with .t.
>	
>If TableUpdate()
>	Wait Window 'Record Added'
>else
>	local aErrors[1]
>	aError( aErrors )
>	wait window aErrors[2]
>	return
>endif
>
>Local nConn
>
>nConn = CursorGetProp("ConnectHandle")
>
>If SQLExec( nConn, "Select @@Identity") = 1
>	wait window 'Got Identity Value'
>	local iIdentity
>	iIdentity = SQLRESULT.EXP
>	use in SQLRESULT
>else
>	Wait Window 'Unable to get Identity'
>	return
>EndIf
>
>select PUBS_AUTHORS
>replace Author_PK with iIdentity
>? getfldstate(-1)
>goto recno()
>? getfldstate(-1)
>
>replace Address with 'New Address for this record.'
>
>If TableUpdate()
>	wait window 'Updated Change of new record!'
>Else
>	local aErrors[1]
>	aError( aErrors )
>	wait window aErrors[2]
>EndIf
>
>
>
>>Any help is GREATLY appreciated.
>
>HTH,
>
>BOb
------------------------------------------------
John Koziol, ex-MVP, ex-MS, ex-FoxTeam. Just call me "X"
"When the going gets weird, the weird turn pro" - Hunter Thompson (Gonzo) RIP 2/19/05
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform