ultimix

- Main Page
- Data Structures
- Files
- Examples

- Data Structures
- Data Structure Index
- Data Fields

Public Member Functions | Data Fields
database_algorithms_1_0_0 Class Reference

## Public Member Functions
| __construct ()
| set ($Field, $Value)
| execute_query_set ($SetOfQueries)
| try_connect ()
| select_condition ($Start=false, $Limit=false, $Field=false, $Order=false, $Condition= '1=1', $NativeTable=false)
| add_security_fields ($Fields, $Values, $AddFields=0)
| add_special_fields ($Fields, $Values, $AddFields=0)
| compile_fields_values (&$Record, $AddFields=0)
| create ($TableName, &$Fields, &$Values)
| count_of_records ($TableName, $Condition= '1=1')
| record_exists ($TableName, $Condition= '1=1')
| get_list_of_tables ()
| get_list_of_fields ($TableName)

## Data Fields
| $Database = false
| $Security = false
| $UserAlgorithms = false

## Detailed Description

Class providees routine for database manipulation.

Author
  Dodonov A.A.

Definition at line 31 of file database_algorithms.php.

## Constructor & Destructor Documentation

__construct | ( |  | ) |

Constructor.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 61 of file database_algorithms.php.

{
try
{
$this->Database = get_package( 'database' , 'last' , __FILE__ );
$this->Security = get_package( 'security' , 'last' , __FILE__ );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

## Member Function Documentation

add_security_fields | ( |  | $Fields,
|  |  | $Values,
|  |  | $AddFields = `0`
| ) |  |

Function adds security fields.

Parameters

  $Fields | - Fields.
  $Values | - Values.
  $AddFields | - Additional fields.

Returns
  array( $Fields , $Values ).

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 272 of file database_algorithms.php.

{
try
{
if( $AddFields & OWNER )
{
$UserAlgorithms = get_package( 'user::user_algorithms' , 'last' , __FILE__ );
$Fields [] = 'owner';
$Values [] = $UserAlgorithms->get_id();
}
return( array( $Fields , $Values ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

add_special_fields | ( |  | $Fields,
|  |  | $Values,
|  |  | $AddFields = `0`
| ) |  |

Function adds special fields.

Parameters

  $Fields | - Fields.
  $Values | - Values.
  $AddFields | - Additional fields.

Returns
  array( $Fields , $Values ).

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 321 of file database_algorithms.php.

{
try
{
if( $AddFields & CREATION_DATE )
{
$Fields [] = 'creation_date';
$Values [] = 'NOW()';
}
if( $AddFields & MODIFICATION_DATE )
{
$Fields [] = 'modification_date';
$Values [] = 'NOW()';
}
if( $AddFields & PUBLICATION_DATE )
{
$Fields [] = 'publication_date';
$Values [] = 'NOW()';
}
return( $this->add_security_fields( $Fields , $Values , $AddFields ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

compile_fields_values | ( | & | $Record,
|  |  | $AddFields = `0`
| ) |  |

Function fetches fields and values.

Parameters

  $Record | - Record to insert.
  $AddFields | - Additional fields.

Returns
  array( $Fields , $Values ).

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 375 of file database_algorithms.php.

{
try
{
$Fields = array();
$Values = array();
foreach( $Record as $f => $v )
{
if( $v !== '_no_update' && $f !== 'master_id' && $f !== 'master_type' )
{
$Fields [] = $f;
if( is_array( $v ) || is_object( $v ) )
{
$Values [] = "'".serialize( $v )."'";
}
else
{
$Values [] = "'".$v."'";
}
}
}
return( $this->add_special_fields( $Fields , $Values , $AddFields ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

count_of_records | ( |  | $TableName,
|  |  | $Condition = `'1 = 1'`
| ) |  |

Function count of tables in the query.

Parameters

  $TableName | - Name of the table.
  $Condition | - Records selection condition.

Returns
  Count of records.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 485 of file database_algorithms.php.

{
try
{
$CountOfRecords = $this->Database->select( 'COUNT( * ) AS count_of_records' , $TableName , $Condition );
$CountOfRecords = get_field( $CountOfRecords[ 0 ] , 'count_of_records' );
return( $CountOfRecords );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

create | ( |  | $TableName,
|  | & | $Fields,
|  | & | $Values
| ) |  |

Function validates can we connect to the database.

Parameters

  $TableName | - Name of the table.
  $Fields | - Fields.
  $Values | - Values.

Returns
  Id of the created record.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 437 of file database_algorithms.php.

{
try
{
$this->Database->lock( array( $TableName ) , array( 'WRITE' ) );
$this->Database->insert( $TableName , implode( ',' , $Fields ) , implode( ',' , $Values ) );
$this->Database->commit();
$id = $this->Database->select( '*' , $TableName , '1 = 1 ORDER by id DESC LIMIT 0 , 1' );
$id = get_field( $id[ 0 ] , 'id' );
$this->Database->unlock();
return( $id );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

execute_query_set | ( |  | $SetOfQueries | ) |

Execute SQL queries from $SetOfQueries.

Parameters

  $SetOfQueries | - set of SQL queries;

Note
  SQL instructions are separated by ";\r\n".

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 119 of file database_algorithms.php.

{
try
{
$SetOfQueries = explode( ";\n" , $SetOfQueries );
foreach( $SetOfQueries as $Query )
{
$this->Database->query( $Query );
$this->Database->commit();
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

get_list_of_fields | ( |  | $TableName | ) |

Function returns a list of table's columns.

Parameters

  $TableName | - Table name.

Returns
  List of table's columns names.

Exceptions

  Exception | - An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 600 of file database_algorithms.php.

{
try
{
$TableName = $this->Security->get( $TableName , 'command' );
$this->Database->query_as( DB_OBJECT );
$Result = $this->Database->query( "SHOW FIELDS FROM `$TableName`" );
return( $this->Database->fetch_results( $Result ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

get_list_of_tables | ( |  | ) |

Function returns a list of tables.

Returns
  A list of tables.

Exceptions

  Exception | - An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 557 of file database_algorithms.php.

{
try
{
$this->Database->query_as( DB_ARRAY );
$Result = $this->Database->query( 'SHOW TABLES' );
$ListOfTables = $this->Database->fetch_results( $Result );
foreach( $ListOfTables as $i => $TableInfo )
{
$ListOfTables[ $i ] = $TableInfo[ 0 ];
}
return( $ListOfTables );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

record_exists | ( |  | $TableName,
|  |  | $Condition = `'1 = 1'`
| ) |  |

Function checks fo record exists.

Parameters

  $TableName | - Name of the table.
  $Condition | - Records selection condition.

Returns
  true/false.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 527 of file database_algorithms.php.

{
try
{
return( $this->count_of_records( $TableName , $Condition ) > 0 );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

select_condition | ( |  | $Start = `false`,
|  |  | $Limit = `false`,
|  |  | $Field = `false`,
|  |  | $Order = `false`,
|  |  | $Condition = `'1 = 1'`,
|  |  | $NativeTable = `false`
| ) |  |

Function returns condition of records selection.

Parameters

  $Start | - Number of the first record.
  $Limit | - Count of records limitation.
  $Field | - Field to sort by.
  $Order | - Sorting order.
  $Condition | - Additional conditions.
  $NativeTable | - Table name.

Returns
  Condition of records selection.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 209 of file database_algorithms.php.

{
try
{
if( $Start !== false )
{
$Start = $this->Security->get( $Start , 'integer' );
$Limit = $this->Security->get( $Limit , 'integer' );
if( $Field === false )
{
$Field = $NativeTable !== false ? "$NativeTable.id" : 'id';
$Order = 'DESC';
}
else
{
$Field = $this->Security->get( $Field , 'command' );
$Order = $this->Security->get( $Order , 'command' );
$Order = ( $Order === 'ascending' || $Order === 'ASC' ) ? 'ASC' : 'DESC';
}
$Condition = "$Condition ORDER BY $Field $Order LIMIT $Start , $Limit";
}
return( $Condition );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

set | ( |  | $Field,
|  |  | $Value
| ) |  |

Function sets field.

Parameters

  $Field | - Field name.
  $Value | - Field value.

Author
  Dodonov A.A.

Definition at line 92 of file database_algorithms.php.

{
$this->$Field = $Value;
}

try_connect | ( |  | ) |

Function validates can we connect to the database.

Exceptions

  true | if the connection was established, false otherwise.

Author
  Dodonov A.A.

Definition at line 151 of file database_algorithms.php.

{
try
{
$Obj = $this->Database->get_object( true );
$Obj->get_connection();
return( true );
}
catch( Exception $e )
{
return( false );
}
}

## Field Documentation

$Database = false

Database object.

Author
  Dodonov A.A.

Definition at line 43 of file database_algorithms.php.

$Security = false

Definition at line 44 of file database_algorithms.php.

$UserAlgorithms = false

Definition at line 45 of file database_algorithms.php.

The documentation for this class was generated from the following file:

- packages/database/packages/database_algorithms/database_algorithms.php