Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Solving the SQL Server Identity datatype problem
Message
From
20/07/1999 10:44:47
 
 
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00243423
Message ID:
00243590
Views:
20
Hi Mike ---

>Good idea. Have you tried doing it with one connection? As long as you have a candidate key, you ought to be able to make two queries on the same connection - or even in the same SQLEXEC() call:
>
>lcSQL = "INSERT INTO table VALUES (x,y,z); SELECT pk FROM table"
>lnResult = SQLEXEC(hConn, lcSQL)

Yeah, I have. That's what led to this whole idea, is that I was appending records to a big SQL Server table and no amount of requery on a new record would return a non-zero value for the new identity field without requerying the whole table...and this was a lag. Using this method though is very, very fast

Here's some code:
* CLIENT table = (clientid (Ident),clntlastname C(40),clntfirstname C(40))

cLast="Smith"
cFirst="John"
OPEN DATA MyDataBase
nCH=SQLCONNECT("conMyConnection")
IF nCH= -1
   WAIT WIND "Connect Error" NOWAIT
   RETURN
ENDIF
nA=SQLSETPROP(nCH,"Transactions",2)
nS=SQLEXEC(nCH,"INSERT INTO client (clntlastname,clntfirstname) VALUES ('&cLast','&cFirst')")
IF nS= -1
   WAIT WIND "Execute Error" NOWAIT
   RETURN
ENDIF
nCS=SQLCOMMIT(nCH)
IF nCS= -1
   WAIT WIND "Commit Error" NOWAIT
   RETURN
ENDIF
*** Second connection
nCH2=SQLCONNECT("conDUI")
IF nCH2= -1
   WAIT WIND "Connect Error" NOWAIT
   RETURN
ENDIF
nF=SQLEXEC(nCH2,"SELECT clientid FROM client WHERE clntlastname = '&cLast' AND clntfirstname = '&cFirst'","tabresults")
SELECT tabresults
BROWSE   && Contains the new clientid
------------------------------------------------
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
Reply
Map
View

Click here to load this message in the networking platform