Em minha aplicação faço o uso de BEGIN;
, COMMIT;
, ROLLBACK;
, Try
, Catch
:
Exemplo:
try{
$this->execute('BEGIN;');
// CODIGO COM VALIDAÇÕES
$this->execute('COMMIT;');
}catch(Exception $e){
$this->execute('ROLLBACK;');
}
Acontece que para fins de teste eu seto uma flag que ativa o BEGIN;
, ROLLBACK;
Global
Exemplo
function __construct(){
if($this->transaction_rollback === true){
$this->Execute('BEGIN;');
}
}
function __destruct(){
if($this->transaction_rollback === true){
$this->Execute('ROLLBACK;');
}
}
Resumo
BEGIN;
BEGIN; //there is already a transaction in progress
// INSERT
COMMIT;
ROLLBACK; //there is no transaction in progress
Situação
Eu utilizo postgreSql
e pelos testes ele não tem suporte a multi BEGIN;
,
pesquisando um pouso também não encontrei outros bancos que teriam suporte a esta situação.
Questão
Teria alguma outra maneira de proteger o banco para fins de testes?