What if the error thrown is due to some other reason?

If your app is like many applications where you're doing many more updates 
than inserts, then this approach is at best only a fraction more efficient 
than the standard

query for key
if (keyexists) then
  update record
else
  insert record

Like you say, most of the time you're going to be hitting the database 
twice anyway.  If your application were doing mostly inserts then it might 
make some sense.



----- Original Message ----- 
From: "Howie Hamlin" <[EMAIL PROTECTED]>
To: "CF-Talk" <[email protected]>
Sent: Wednesday, February 02, 2005 2:50 PM
Subject: SQL Q


>I have an application where I want to update an exising record or create 
>it if it doesn't exist (this is for keeping daily stats).  The table is 
>indexed and does not allow dupes.  I came up with something like this:
>
> <cftransaction>
> <cftry>
>   insert record
> <cfcatch type="any">
>   update record
> </cfcatch>
> </cftry>
> </cftransaction>
>
> Basically, if the insert fails then I assume that there is a key 
> violation and I update the existing record.  Does anyone see a problem 
> with this?  My thought was that if you do a select first to see if the 
> record exists and then either insert a new record or update the exising 
> record then that would still take two trips to the SQL server.
>
> Thanks,
>
> Howie


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:192829
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to