soci
soci copied to clipboard
Oracle - can't catch exception
I'm using Oracle, with GCC/C++17 and SOCI build from master. Probably related to https://github.com/SOCI/soci/issues/256
Calling below function:
bool Store::AddUser(User user){
// if(users.count(user.Login) > 0){
// return false;
// }
// users[user.Login] = user;
// return true;
try{
std::cout << "login: " << user.Id << std::endl;
std::cout << "password: " << user.HashedPassword << std::endl;
session.sql << "INSERT INTO users(id, hashedpassword,salt) VALUES(:id, :hashedpassword, :salt)", use(user.Id), use(user.HashedPassword), use(user.Salt);
return true;
}
catch (soci::oracle_soci_error const & e)
{
std::cerr << e.what() << std::endl;
return false;
}
catch (...)
{
std::cerr << "Some other error: " << std::endl;
return false;
}
}
Results in crash:
terminate called after throwing an instance of 'soci::oracle_soci_error'
what(): ORA-00001: unique constraint (SYSTEM.USER_PK) violated
while executing
soci is compiled by default with -std=gnu++98
on gcc. You can force SOCI_CXX_C11
to ON
in your cmake file to allow exceptions in the soci::details::once_temp_type::~once_temp_type
destructor. Otherwise in your case std::terminate
is called.
I had the same problem. Enable C++11
by default seems a good thing. What do you think @mloskot?
@Adiqq @Wescoeur Could you please provide version you're using? Thank you.
No problem, the master branch.
Master branch as well.
So something like cmake -G "Unix Makefiles" -DWITH_BOOST=ON -DWITH_ORACLE=ON -DSOCI_CXX_C11=ON .
should fix it? I was just playing around with SOCI for university project and this issue was troublesome, so it would be nice to at least mention about this flag in documentation.
@Adiqq Thanks for spotting SOCI_CXX_C11
is missing from the docs. It should be there now. See the latest here http://soci.sourceforge.net/doc/master/installation/ (auto-generated on every commit).
@Wescoeur C++11 by default has been discussed a few times and the overall consensus was
- we don't want to require C++11 (or later)
- we want to allow C++11 (or later)
This may change in future though.
mysql insert a record that already exists soci::mysql_soci_error not receive an exception Error SIGABRT (Aborted) soci commit f4927b27a cmake -G "Unix Makefiles" -DWITH_BOOST=ON -DWITH_MYSQL=ON -DSOCI_CXX_C11=ON .. mysql v5.7
@rise-worlds such incomplete nonsense makes useless issue reports
Why SOCI_CXX_C11? You should use CMAKE_CXX_STANDARD
@5cript because of
https://github.com/SOCI/soci/blob/601a89227d844e279fae3edfde85739067d382b3/CMakeLists.txt#L13
And what about optionally checking against __cplusplus if existant/supported, secondarily using the special soci cmake option? In principal this allows for CMAKE_CXX_STANDARD where supported.
@5cript I moved the discussion to specific thread in #752