ePages 6.10 - DE_EPAGES/Database/API/DBImysql.pm

Package DE_EPAGES::Database::API::DBImysql

Functions

atIsolationLevel
createDatabase
createEpagesDatabase
currentDateTime
dropAllTables
dropForeignKey
dropIndex
escapeChar
existsDatabase
existsForeignKey
existsIndex
existsTable
existsTableColumn
getAllTableReferences
getSearchCollation
lockTables
modifyTableColumnDropDefault
modifyTableColumnReplaceDefault
new
processID

atIsolationLevel

executes the function sub at specified transaction isolation level.

Syntax
$dbi->atIsolationLevel($IsolationLevel, $Sub);
Input
$IsolationLevel (string)
values (
READ UNCOMMITTED|
READ COMMITTED|
REPEATABLE READ|
SERIALIZABLE
)
$Sub (ref.code)
function to execute select statement

createDatabase

Creates a new database; sets the charset to utf-8

Syntax
$dbi->createDatabase($DBName);
Example
$dbi->createDatabase('storedb');
Input
$DBName (string)
database name

createEpagesDatabase

Creates a database with epages default sizes and names.

Syntax
$dbi->createEpagesDatabase($DBName, $DBLogin, $hOptions);
Example
$dbi->createEpagesDatabase('sitedb', 'usr_sitedb');
$dbi->createEpagesDatabase('storedb');
Input
$DBName (string)
database name
$DBLogin (string)
database login (default: current user)
$hOptions (ref.hash)
  • DBPassword - password for user $DBLogin (default: 'epages') - string

currentDateTime

Returns the current time of the database server.

Syntax
$DatabaseTime = $dbi->currentDateTime();
Return
$DatabaseTime (DateTime)
current datetime of database server

dropAllTables

Removes all user tables from the database (deleting all data, of cause).

Syntax
$dbi->dropAllTables();

dropForeignKey

Drops constaint (foreign key) $constraint from a table $tablename.

Syntax
$dbi->dropForeignKey($table, $constraint);
Example
$table = 'tablename';
$constraint = 'fk_tablename_reftablename';
Input
$table (string)
table name
$constraint (string)
constraint name

dropIndex

Drops index $indexname from table $tablename.

Syntax
$dbi->dropIndex($table, $indexname);
Example
$table = 'tablename';
$indexname = 'indexname';
Input
$table (string)
table name
$indexname (string)
index name

escapeChar

Returns the escape character '\' to escape like parameter.

Syntax
$escapeChar = $dbi->escapeChar;
Return
$escapeChar (string)
back slash

existsDatabase

Returns true if the database exists.

Syntax
$Exists = $dbi->existsDatabase($DBName);
Input
$DBName (string)
database name
Return
$Exists (boolean)
database exists

existsForeignKey

Returns true if the foreign key exists.

Syntax
$Exists = $dbi->existsForeignKey( $Name );
Example
if( $dbi->existsForeignKey( 'sp_InsertAttribute' ) ) { ... };
Input
$ForeignKey (string)
foreign key name
Return
$Exists (boolean)
true if the foreign key exists

existsIndex

Returns true if the index exists.

Syntax
$exists = $dbi->existsIndex($Table, $IndexName);
Example
if( $dbi->existsIndex('product', 'i_product_super') ) { ... }
Input
$Table (string)
table name
$IndexName (string)
index name

existsTable

Returns true if the database table exists.

Syntax
$Exists = $DBI->existsTable( $Table );
Example
if( $DBI->existsTable( 'sysobjects' ) ) { ... };
Input
$Table (string)
table name
Return
$Exists (boolean)
true if the table exists

existsTableColumn

Returns true if the database table column exists.

Syntax
$Exists = $dbi->existsTableColumn( $Table, $Column );
Example
if( $dbi->existsTableColumn( 'sysobjects', 'name' ) ) { ... };
Input
$Table (string)
table name
$Column (string)
column name
Return
$Exists (boolean)
true if the column exists

getAllTableReferences

Determines all table references

Syntax
$aaReferences = $dbi->getAllTableReferences();
Return
$aaReferences (ref.array.array.string)
list of table references
each list element is a pair of tables [ table => master_table ].
If master_table is undef, then the table does not depend on other
tables

getSearchCollation

Returns additional SQL syntax for specification of collations for searches. This is ususally used for mysql to return 'COLLATE utf8_general_ci'

Syntax
$SearchCollation = $dbi->getSearchCollation;
Return
$SearchCollation (string)
empty string for standard

lockTables

Locks the specified tables during execution of a code block.

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

modifyTableColumnDropDefault

Deletes a Default of an existing column of an existing table $tablename.

Syntax
$dbi->modifyTableColumnDropDefault($table, $column );
Example
$table = 'tablename';
$column = 'columnname';
Input
$table (string)
table name
$column (string)
column name

modifyTableColumnReplaceDefault

Modifies a default of an existing column $column of an existing table $tablename.

Syntax
$dbi->modifyTableColumnReplaceDefault($table, $column ,$defaultvalue);
Example
$table = 'tablename';
$column = 'columnname';
$defaultvalue = 0 use functions quote* to quote the value before
Input
$table (string)
table name
$column (string)
column name
$defaultvalue (string)
default value of the column

new

Creates a database connection using the supplied connection parameters.

Syntax
DE_EPAGES::Database::API::DBImysql->new( $DataSource, $User, $Password, $CacheKey );
Example
DE_EPAGES::Database::API::DBImysql->new( 'dbi:mysql: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

processID

Returns the ID of the current database process.

Syntax
my $ProcessID = $dbi->processID;
Input
$ProcessID (integer)
process id