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

Package DE_EPAGES::Database::API::DBImysql

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

Base
DE_EPAGES::Database::API::DBI

Functions

addTableColumnAfterColumn
addTableColumnFirst
atIsolationLevel
columnDefinition
createDatabase
createEpagesDatabase
currentDateTime
databaseName
disableForeignKeyChecks
dropAllTables
dropForeignKey
dropIndex
dropIndexesIfExist
dropPrimaryKey
dropProcedureIfExists
escapeChar
existsAnyForeignKeyOn
existsDatabase
existsForeignKey
existsForeignKeyByName
existsIndex
existsTable
existsTableColumn
getAllTableReferences
getSearchCollation
iterator
lockTables
modifyTableColumnAddAutoIncrement
modifyTableColumnDropAutoIncrement
modifyTableColumnDropDefault
modifyTableColumnReplaceDefault
new
processID
renameTable
renameTableColumn
truncateTable

addTableColumnAfterColumn

Adds a new column to an existing table $table, after a specified existing column.

Syntax
$dbi->addTableColumnAfterColumn($table, $column, $columndefinition);
Example
$dbi->addTableColumnAfterColumn('product', 'weighunitid', 'manufacturerid INT NULL');
Input
$table (string)
table name
$column (string)
column name
$columndefinition (string)
sql definiton of the column

addTableColumnFirst

Adds a new column to an existing table $table, before all existing columns.

Syntax
$dbi->addTableColumnFirst($table, $columndefinition);
Example
$dbi->addTableColumnFirst('productprice', 'currencyid CHAR(3) NULL');
Input
$table (string)
table name
$columndefinition (string)
sql definiton of the column

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

columnDefinition

Returns the column definition of a table column.

Syntax
$ColumnDef = $dbi->columnDefinition( $Table, $ColumnName );
Example
$ColumnDef = $dbi->columnDefinition( 'person', 'firstname' );
Input
$Table (string)
table name
$OldName (string)
new table column name
Return
$ColumnDef (string)
column definition string, e.g. 'firstname VARCHAR(30) NUT NULL'

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

databaseName

Returns the name of the currently used database.

Syntax
$databaseName = $dbi->databaseName
Return
$databaseName (string)
database name

disableForeignKeyChecks

Disables foreign key checks during execution of $Code.

Syntax
$dbi->disableForeignKeyChecks($Code);
Input
$Code (code)
code reference

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

dropIndexesIfExist

Drops an index from a table if the given index exists already on the table. Since dropping various indexes in a single SQL statement, an array of indexes is expected as a parameter.

Syntax
$Installer->dropIndexesIfExist( $Table, $aIndexes );
Input
$Table (string)
table name
$aIndexes (array.string)
array of index names to be dropped from $Table

dropPrimaryKey

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

Syntax
$dbi->dropPrimaryKey($table, $constraint);
Example
$dbi->dropPrimaryKey('product', 'pk_product');
Input
$table (string)
table name
$constraint (string)
constraint name (ignored)

dropProcedureIfExists

Removes a stored procedure from the database if exists

Syntax
$dbi->dropProcedureIfExists($Procedure);
Example
$dbi->dropProcedureIfExists('sp_InsertAttribute');
Input
$Procedure (string)
procedure name

escapeChar

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

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

existsAnyForeignKeyOn

Returns true if the given foreign key exists. It should be noted that this implementation currently works only if ANSI_QUOTES is not activated.

Syntax
$Exists = $dbi->existsAnyForeignKeyOn( $Table, $aColumns, $RefTable, $aRefColumns );
Example
if ($dbi->existsAnyForeignKeyOn(
  'product',
  [
    'manufacturerid'
  ],
  'productmanufacturer',
  [
    'manufacturerid'
  ]) { ... };
Input
$Table (string)
table name
$aKeys (ref.array.string)
list of columns in the table
$RefTable (string)
referenced table name
$aRefKeys (ref.array.string)
list of columns in the referenced table
Return
$Exists (boolean)
true if the given foreign key exists

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

existsForeignKeyByName

Returns true if the given foreign key exists on the table. It should be noted that this implementation currently works only if ANSI_QUOTES is not activated.

Syntax
$Exists = $dbi->existsForeignKeyByName( $Table, $ForeignKey );
Example
if ($dbi->existsForeignKeyByName('product', 'fk_product_manufacturerid') {
  ...
};
Input
$Table (string)
table name
$ForeignKey (string)
name of a foreign key 'fk__<column>'
Return
$Exists (boolean)
true if the given foreign key exists

existsIndex

Returns true if the index exists. It should be noted that only explicitly created indices can be found with the current implementation. Please have a look at the MySQL developer documentation (http://dev.mysql.com/doc/) in order to retrieve information on detecting implicit indices, which exist for primary and foreign keys. Furthermore, this implementation currently works only if ANSI_QUOTES is not activated.

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

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. It should be noted that this implementation currently works only if ANSI_QUOTES is not activated.

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

iterator

Executes an SQL statement and returns an iterator to fetch the results.

Syntax
$Iterator = $dbi->iterator( $SQL );
$Iterator = $dbi->iterator( $SQL, $aParams );
$Iterator = $dbi->iterator( $SQL, $aParams, $aDttps, $aColumnNames );
Example
$Iterator = $dbi->iterator( 'SELECT languageid, code2 FROM language WHERE isused = ?',
                            [ 1 ], ['Integer', 'String'], ['LanguageID', 'Code2'] );
while( $hLanguage = <$Iterator> ) {
    print "ID: $hLanguage->{LanguageID}, Code: $hLanguage->{Code2}\n";
}
Input
$SQL (string)
SQL statement
$aParams (ref.array.string)
(optional) list of parameters to replace '?' placeholders in
the SQL string
$aDttps (ref.array.string)
(optional) list data type position of return values
(see unquoteResultSet
$aColumnNames (ref.array.string)
(optional) list of field names in the result set
(see unquoteResultSet
Return
$Iterator (DE_EPAGES::Core::API::Iterator)
resultset iterator

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

modifyTableColumnAddAutoIncrement

Adds auto_increment of an existing column of an existing table $tablename.

Syntax
$dbi->modifyTableColumnAddAutoIncrement($table, $column );
Input
$table (string)
table name
$column (string)
column name

modifyTableColumnDropAutoIncrement

Deletes auto_increment of an existing column of an existing table $tablename.

Syntax
$dbi->modifyTableColumnDropAutoIncrement($table, $column );
Input
$table (string)
table name
$column (string)
column name

modifyTableColumnDropDefault

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

Syntax
$dbi->modifyTableColumnDropDefault($table, $column );
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
Return
$dbi (DE_EPAGES::Database::API::DBImysql)
database handle

processID

Returns the ID of the current database process.

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

renameTable

Renames a table.

Syntax
$dbi->renameTable( $OldName, $NewName );
Example
$dbi->renameTable( 'land', 'country' );
Input
$OldName (string)
old table name
$OldName (string)
new table name

renameTableColumn

Renames a table column.

Syntax
$dbi->renameTableColumn( $Table, $OldColumnName, $NewColumnName );
Example
$dbi->renameTableColumn( 'person', 'prename', 'firstname' );
Input
$Table (string)
table name
$OldColumnName (string)
old table column name
$NewColumnName (string)
new table column name

truncateTable

Delete all table rows without where clause.

Syntax
$dbi->truncateTable( $Table );
Input
$Table (string)
table name