- Code: Select all
try
{
*pSession << "UPDATE ...", now;
}
catch (...)
{
*pSession << "INSERT INTO ...", now;
}
Then I tried to obtain the number of affected records by creating a Statement object and calling the execute()-method. But in my case on MySQL the result of Statement::execute() was always 0 when the statement was UPDATE, even if the UPDATE was indeed executed and affected a row. This seems to be a bug. On SQLite this worked always as expected.
So I changed the order of the statements - first INSERT then UPDATE:
- Code: Select all
try
{
*pSession << "INSERT INTO ...", now;
}
catch (...)
{
*pSession << "UPDATE ...", now;
}
- make a (superfluous) transaction around all that, the commit will then either INSERT or UPDATE safely
- avoid "now", use a Statement object instead and execute() this, this will also be safe
And finally, what would be a recommended, portable algorithm to implement this UPDATE/INSERT thing?
POCO 1.5.1 on Arch Linux x86_64





