<% include( '/elements/header.html', 'Developer Documentation' ) %> <& /elements/menubar.html, 'Freeside Perl Modules' => $fsurl.'docs/library/FS.html', 'Complete Index' => $fsurl.'docs/library/index.html', &>

FS::Misc::Savepoint

NAME

FS::Misc::Savepoint - Provides methods for SQL Savepoints

SYNOPSIS

  use FS::Misc::Savepoint;
  
  # Only valid within a transaction
  local $FS::UID::AutoCommit = 0;
  
  savepoint_create( 'savepoint_label' );
  
  my $error_msg = do_some_things();
  
  if ( $error_msg ) {
    savepoint_rollback_and_release( 'savepoint_label' );
  } else {
    savepoint_release( 'savepoint_label' );
  }

DESCRIPTION

Provides methods for SQL Savepoints

Using a savepoint allows for a partial roll-back of SQL statements without forcing a rollback of the entire enclosing transaction.

METHODS

savepoint_create LABEL
savepoint_create { label => LABEL, dbh => DBH }

Executes SQL to create a savepoint named LABEL.

Savepoints cannot work while AutoCommit is enabled.

Savepoint labels must be valid sql identifiers. If your choice of label would not make a valid column name, it probably will not make a valid label.

Savepoint labels must be unique within the transaction.

savepoint_release LABEL
savepoint_release { label => LABEL, dbh => DBH }

Release the savepoint - preserves the SQL statements issued since the savepoint was created, but does not commit the transaction.

The savepoint label is freed for future use.

savepoint_rollback LABEL
savepoint_rollback { label => LABEL, dbh => DBH }

Roll back the savepoint - forgets all SQL statements issues since the savepoint was created, but does not commit or roll back the transaction.

The savepoint still exists. Additional statements may be executed, and savepoint_rollback called again.

savepoint_rollback_and_release LABEL
savepoint_rollback_and_release { label => LABEL, dbh => DBH }

Rollback and release the savepoint

METHODS - Internal

_parse_params

Create %params from function input

Basic savepoint label validation

Complain when trying to use savepoints without disabling AutoCommit

BUGS

SEE ALSO

<% include ('/elements/footer.html' ) %>