> From: Daniel Vallejos <chi...@gm...>
>
> Hello.
>
> I need catch common sql errors in cppdb, such as duplicate key insert
> error or other constraint errors.
>
> How to accomplish this in a portable way with cppdb?
>
Just catch cppdb_error exception.
There is no portable way to get specific error.
Also it is better to check the constraints before you execute
something and not relay on them in normal flow.
i.e.:
cppdb::translation tr(sql);
cppdb::result r;
sql << "SELECT id FROM foo where id=?" << id >> cppdb::row >> r;
if(r.empty()) {
sql << "INSERT ... " ... ;
tr.commit();
}
else {
tr.rollback();
// Handle error.
}
Artyom
|