![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a piece of C++ code in which I try to update a record for a primary key. If the record does not exist, an exception is raised and the data is treated as an insert by hitting the exception logic. Someone pointed out that this is expensive because of the stack unwind on the exception logic, but I argue that it is still faster because finding out if an primary record exists takes time. Others argue that exception logic should be used for exceptional events rather than as a kludge which happens by circumstance. Is this acceptable? ----------example ---------------- int foo::Upate(string stIn){ try{ m_Conn.sql = "update tab1 set foo=" + stIn.c_str() +" where some=cond "; m_Conn.exec(); catch(SQLException ex){ m_Conn.sql = "insert into tab1 values(" + stIn.c_str() +" , cond) "; m_Conn.exec(); } } |
#3
| |||
| |||
|
|
On 2011-02-23 21:34, Deodiaus wrote: I have a piece of C++ code in which I try to update a record for a primary key. If the record does not exist, an exception is raised and the data is treated as an insert by hitting the exception logic. Someone pointed out that this is expensive because of the stack unwind on the exception logic, but I argue that it is still faster because finding out if an primary record exists takes time. Others argue that exception logic should be used for exceptional events rather than as a kludge which happens by circumstance. Is this acceptable? ----------example ---------------- int foo::Upate(string stIn){ try{ m_Conn.sql = "update tab1 set foo=" + stIn.c_str() +" where some=cond "; m_Conn.exec(); catch(SQLException ex){ m_Conn.sql = "insert into tab1 values(" + stIn.c_str() +" , cond) "; m_Conn.exec(); } } You don't mention what version of db2 you are using, but I recommend that you have a look at MERGE: http://publib.boulder.ibm.com/infoce...c/r0010873.htm |
![]() |
| Thread Tools | |
| Display Modes | |
| |