ePages 7.48.0 - DE_EPAGES/Database/API/DBIgalera.pm

Package DE_EPAGES::Database::API::DBIgalera

Galera specific implementation of DE_EPAGES::Database::API::DBI.

Base
DE_EPAGES::Database::API::DBImysql

Functions

lockTables
new
transaction

lockTables

Since galera does not support the lock tables operation, we try to emulate this with supported functionality. Instead of locking a table, we execute the code inside of an transaction with the isolation level 'repeatable read'. Since 'repeatable read' is the default isolation level we do not need to set it manually.

Syntax
$dbi->lockTables( $ahTables, $cCode );
Example
$dbi->lockTables( [
    { 'table' => 'test', 'mode' => 'WRITE'},
    { 'table' => 'test2', 'mode' => 'WRITE'},
], sub {
    $dbi->do('DELETE FROM test2 WHERE id = ?', $id);
    $dbi->do('DELETE FROM test WHERE id = ?', $id);
});
Input
$ahTables (ref.array.hash)
tables and locking modes. Hash keys are:
  • table - table name - string
  • mode - locking mode (READ|WRITE) - string
$cCode (code ref)
code block

new

Creates a database connection using the supplied connection parameters.

Syntax
DE_EPAGES::Database::API::DBIgalera->new( $DataSource, $User, $Password, $CacheKey );
Example
DE_EPAGES::Database::API::DBIgalera->new( 'dbi:galera:storedb', 'root', 'geheim', 'DAL' );
Input
$DataSource (string)
DBI connection string without user name/password
$User (string)
Database user or login name
$Password (string)
Database user password
$CacheKey (string)
key to identify the connection
Return
$dbi (DE_EPAGES::Database::API::DBImysql)
database handle

transaction

Executes a code block in a transaction.

Syntax
$dbi->transaction( $cCode, $cRollback );
Example
$dbi->transaction( sub {
    $dbi->do( "DELETE FROM objects WHERE classid = 25" );
    $dbi->do( "DELETE FROM classes WHERE classid = 25" );
} );
Input
$cCode (code reference)
code block
$cRollback (code reference)
roll back code block (optional)