SQLite3: Rollback only if in a transaction.

SQLite3 may rollback a transaction on its own and callers should check
whether the transaction is active on errors.

Fixes: #13638