MDB2_Schema
[ class tree: MDB2_Schema ] [ index: MDB2_Schema ] [ all elements ]

Class: MDB2_Schema

Source Location: /MDB2_Schema-0.8.6/MDB2/Schema.php

Class Overview

PEAR
   |
   --MDB2_Schema

The database manager is a class that provides a set of database management services like installing, altering and dumping the data structures of databases.


Author(s):

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 80]
The database manager is a class that provides a set of database management services like installing, altering and dumping the data structures of databases.


[ Top ]


Class Variables

$db =

[line 84]


Type:   mixed


[ Top ]

$options = array(
        'fail_on_invalid_names' => true,
        'dtd_file'              => false,
        'valid_types'           => array(),'force_defaults'=>true,'parser'=>'MDB2_Schema_Parser','writer'=>'MDB2_Schema_Writer','validate'=>'MDB2_Schema_Validate','drop_obsolete_objects'=>false)

[line 88]


Type:   mixed


[ Top ]

$warnings = array()

[line 86]


Type:   mixed


[ Top ]



Method Detail

alterDatabase   [line 2174]

bool|MDB2_Error alterDatabase( array $current_definition, array $previous_definition, array $changes)

Execute the necessary actions to implement the requested changes in a database structure.
  • Return: MDB2_OK or error object
  • Access: public

Parameters:

array   $current_definition   —  multi dimensional array that contains the current definition
array   $previous_definition   —  multi dimensional array that contains the previous definition
array   $changes   —  associative array that contains the definition of the changes that are meant to be applied to the database structure.

[ Top ]

alterDatabaseIndexes   [line 1946]

bool|MDB2_Error alterDatabaseIndexes( string $table_name, array $changes)

Execute the necessary actions to implement the requested changes in the indexes inside a database structure.
  • Return: MDB2_OK or error object
  • Access: public

Parameters:

string   $table_name   —  name of the table
array   $changes   —  associative array that contains the definition of the changes that are meant to be applied to the database structure.

[ Top ]

alterDatabaseSequences   [line 2112]

bool|MDB2_Error alterDatabaseSequences( array $current_definition, array $previous_definition, array $changes)

Execute the necessary actions to implement the requested changes in the sequences inside a database structure.
  • Return: MDB2_OK or error object
  • Access: public

Parameters:

array   $current_definition   —  multi dimensional array that contains the current definition
array   $previous_definition   —  multi dimensional array that contains the previous definition
array   $changes   —  associative array that contains the definition of the changes that are meant to be applied to the database structure.

[ Top ]

alterDatabaseTables   [line 2027]

bool|MDB2_Error alterDatabaseTables( array $current_definition, array $previous_definition, array $changes)

Execute the necessary actions to implement the requested changes in the tables inside a database structure.
  • Return: MDB2_OK or error object
  • Access: public

Parameters:

array   $current_definition   —  multi dimensional array that contains the current definition
array   $previous_definition   —  multi dimensional array that contains the previous definition
array   $changes   —  associative array that contains the definition of the changes that are meant to be applied to the database structure.

[ Top ]

apiVersion   [line 108]

string apiVersion( )

Return the MDB2 API version
  • Return: the MDB2 API version number
  • Access: public

[ Top ]

arrayMergeClobber   [line 127]

array|false arrayMergeClobber( array $a1, array $a2)

Clobbers two arrays together
  • Return: array on success and false on error
  • Author: kc@hireability.com
  • Access: public

Parameters:

array   $a1   —  array that should be clobbered
array   $a2   —  array that should be clobbered

[ Top ]

buildFieldValue   [line 1027]

void buildFieldValue( string &$element, string $key)

Appends the contents of second argument + '=' to the beginning of first argument.

Used with array_walk() in initializeTable() for UPDATEs.


Parameters:

string   &$element   —  value of array's element
string   $key   —  key of array's element

[ Top ]

compareDefinitions   [line 1455]

array|MDB2_Error compareDefinitions( array $current_definition, array $previous_definition)

Compare a previous definition with the currently parsed definition
  • Return: array of changes on success, or a error object
  • Access: public

Parameters:

array   $current_definition   —  multi dimensional array that contains the current definition
array   $previous_definition   —  multi dimensional array that contains the previous definition

[ Top ]

compareSequenceDefinitions   [line 1808]

array|MDB2_Error compareSequenceDefinitions( string $sequence_name, array $current_definition, array $previous_definition, array &$defined_sequences)

Compare a previous definition with the currently parsed definition
  • Return: array of changes on success, or a error object
  • Access: public

Parameters:

string   $sequence_name   —  name of the sequence
array   $current_definition   —  multi dimensional array that contains the current definition
array   $previous_definition   —  multi dimensional array that contains the previous definition
array   &$defined_sequences   —  names in the schema

[ Top ]

compareTableDefinitions   [line 1718]

array|MDB2_Error compareTableDefinitions( string $table_name, array $current_definition, array $previous_definition, array &$defined_tables)

Compare a previous definition with the currently parsed definition
  • Return: array of changes on success, or a error object
  • Access: public

Parameters:

string   $table_name   —  name of the table
array   $current_definition   —  multi dimensional array that contains the current definition
array   $previous_definition   —  multi dimensional array that contains the previous definition
array   &$defined_tables   —  table names in the schema

[ Top ]

compareTableFieldsDefinitions   [line 1531]

array|MDB2_Error compareTableFieldsDefinitions( string $table_name, array $current_definition, array $previous_definition)

Compare a previous definition with the currently parsed definition
  • Return: array of changes on success, or a error object
  • Access: public

Parameters:

string   $table_name   —  name of the table
array   $current_definition   —  multi dimensional array that contains the current definition
array   $previous_definition   —  multi dimensional array that contains the previous definition

[ Top ]

compareTableIndexesDefinitions   [line 1614]

array|MDB2_Error compareTableIndexesDefinitions( string $table_name, array $current_definition, array $previous_definition)

Compare a previous definition with the currently parsed definition
  • Return: array of changes on success, or a error object
  • Access: public

Parameters:

string   $table_name   —  name of the table
array   $current_definition   —  multi dimensional array that contains the current definition
array   $previous_definition   —  multi dimensional array that contains the previous definition

[ Top ]

connect   [line 266]

bool|MDB2_Error connect( string|array|MDB2_Driver_Common &$db, [array $options = array()])

Create a new MDB2 connection object and connect to the specified database
  • Return: MDB2_OK or error object
  • See: MDB2::parseDSN
  • Access: public

Parameters:

string|array|MDB2_Driver_Common   &$db   —  'data source name', see the MDB2::parseDSN method for a description of the dsn format. Can also be specified as an array of the format returned by MDB2::parseDSN. Finally you can also pass an existing db object to be used.
array   $options   —  An associative array of option names and their values.

[ Top ]

createDatabase   [line 1308]

bool|MDB2_Error createDatabase( array $database_definition, [array $options = array()])

Create a database space within which may be created database objects

like tables, indexes and sequences. The implementation of this function is highly DBMS specific and may require special permissions to run successfully. Consult the documentation or the DBMS drivers that you use to be aware of eventual configuration requirements.

  • Return: MDB2_OK or error object
  • Access: public

Parameters:

array   $database_definition   —  multi dimensional array that contains the current definition
array   $options   —  an array of options to be passed to the database specific driver version of MDB2_Driver_Manager_Common::createTable().

[ Top ]

createSequence   [line 1221]

bool|MDB2_Error createSequence( string $sequence_name, array $sequence, [bool $overwrite = false])

Create a sequence
  • Return: MDB2_OK or error object
  • Access: public

Parameters:

string   $sequence_name   —  name of the sequence to be created
array   $sequence   —  multi dimensional array that contains the structure and optional data of the table
bool   $overwrite   —  if the sequence should be overwritten if it already exists

[ Top ]

createTable   [line 866]

bool|MDB2_Error createTable( string $table_name, array $table, [bool $overwrite = false], [array $options = array()])

Create a table and inititialize the table if data is available
  • Return: MDB2_OK or error object
  • Access: public

Parameters:

string   $table_name   —  name of the table to be created
array   $table   —  multi dimensional array that contains the structure and optional data of the table
bool   $overwrite   —  if the table/index should be overwritten if it already exists
array   $options   —  an array of options to be passed to the database specific driver version of MDB2_Driver_Manager_Common::createTable().

[ Top ]

createTableConstraints   [line 807]

mixed createTableConstraints( string $table_name, array $constraints, [boolean $overwrite = false])

A method to create foreign keys for an existing table
  • Return: MDB2_Error if there is an error creating a foreign key, MDB2_OK otherwise
  • Access: public

Parameters:

string   $table_name   —  Name of the table
array   $constraints   —  An array of foreign keys to be created
boolean   $overwrite   —  If the foreign key should be overwritten if it already exists

[ Top ]

createTableIndexes   [line 711]

mixed createTableIndexes( string $table_name, array $indexes, [boolean $overwrite = false])

A method to create indexes for an existing table
  • Return: MDB2_Error if there is an error creating an index, MDB2_OK otherwise
  • Access: public

Parameters:

string   $table_name   —  Name of the table
array   $indexes   —  An array of indexes to be created
boolean   $overwrite   —  If the table/index should be overwritten if it already exists

[ Top ]

disconnect   [line 312]

void disconnect( )

Log out and disconnect from the database.
  • Access: public

[ Top ]

dumpDatabase   [line 2428]

bool|MDB2_Error dumpDatabase( array $database_definition, array $arguments, [int $dump = MDB2_SCHEMA_DUMP_ALL])

Dump a previously parsed database structure in the Metabase schema XML based format suitable for the Metabase parser. This function may optionally dump the database definition with initialization commands that specify the data that is currently present in the tables.
  • Return: MDB2_OK or error object
  • Access: public

Parameters:

array   $database_definition   —  multi dimensional array that contains the current definition
array   $arguments   —  associative array that takes pairs of tag names and values that define dump options.
array (
                     'output_mode'    =>    String
                         'file' :   dump into a file
                         default:   dump using a function
                     'output'        =>    String
                         depending on the 'Output_Mode'
                                  name of the file
                                  name of the function
                     'end_of_line'        =>    String
                         end of line delimiter that should be used
                         default: "\n"
                 );
int   $dump   —  Int that determines what data to dump
  • MDB2_SCHEMA_DUMP_ALL : the entire db
  • MDB2_SCHEMA_DUMP_STRUCTURE : only the structure of the db
  • MDB2_SCHEMA_DUMP_CONTENT : only the content of the db

[ Top ]

dumpDatabaseChanges   [line 2248]

bool|MDB2_Error dumpDatabaseChanges( array $changes)

Dump the changes between two database definitions.
  • Return: MDB2_OK or error object
  • Access: public

Parameters:

array   $changes   —  associative array that specifies the list of database definitions changes as returned by the _compareDefinitions manager class function.

[ Top ]

errorMessage   [line 2677]

string errorMessage( [int|array $value = null])

Return a textual error message for a MDB2 error code
  • Return: error message, or false if the error code was not recognized
  • Access: public

Parameters:

int|array   $value   —  integer error code,
  1. null
to get the current error code-message map, or an array with a new error code-message map

[ Top ]

factory   [line 237]

bool|MDB2_Error factory( string|array|MDB2_Driver_Common &$db, [array $options = array()])

Create a new MDB2 object for the specified database type type
  • Return: MDB2_OK or error object
  • See: MDB2::parseDSN
  • Access: public

Parameters:

string|array|MDB2_Driver_Common   &$db   —  'data source name', see the MDB2::parseDSN method for a description of the dsn format. Can also be specified as an array of the format returned by @see MDB2::parseDSN. Finally you can also pass an existing db object to be used.
array   $options   —  An associative array of option names and their values.

[ Top ]

getDefinitionFromDatabase   [line 430]

array|MDB2_Error getDefinitionFromDatabase( )

Attempt to reverse engineer a schema structure from an existing MDB2 This method can be used if no xml schema file exists yet.

The resulting xml schema file may need some manual adjustments.

  • Return: array with definition or error object
  • Access: public

[ Top ]

getExpression   [line 1050]

string getExpression( array $element, [array $fields_definition = array()], [string $type = null])

Generates a string that represents a value that would be associated with a column in a DML instruction.

Parameters:

array   $element   —  multi dimensional array that contains the structure of the current DML instruction.
array   $fields_definition   —  multi dimensional array that contains the definition for current table's fields
string   $type   —  type of given field

[ Top ]

getInstructionFields   [line 1167]

array getInstructionFields( array $instruction, [array $fields_definition = array()])

Walks the parsed DML instruction array, field by field, storing them and their processed values inside a new array.

Parameters:

array   $instruction   —  multi dimensional array that contains the structure of the current DML instruction.
array   $fields_definition   —  multi dimensional array that contains the definition for current table's fields

[ Top ]

getInstructionWhere   [line 1198]

string getInstructionWhere( array $instruction, [array $fields_definition = array()])

Translates the parsed WHERE expression of a DML instruction (array structure) to a SQL WHERE clause (string).

Parameters:

array   $instruction   —  multi dimensional array that contains the structure of the current DML instruction.
array   $fields_definition   —  multi dimensional array that contains the definition for current table's fields.

[ Top ]

getOperator   [line 1121]

string getOperator( string $op)

Returns the matching SQL operator

Parameters:

string   $op   —  parsed descriptive operator

[ Top ]

getOption   [line 210]

mixed getOption( string $option)

returns the value of an option
  • Return: the option value or error object
  • Access: public

Parameters:

string   $option   —  option name

[ Top ]

getWarnings   [line 168]

array getWarnings( )

Get all warnings in reverse order

This means that the last warning is the first element in the array


[ Top ]

initializeTable   [line 938]

bool|MDB2_Error initializeTable( string $table_name, array $table)

Inititialize the table with data
  • Return: MDB2_OK or error object
  • Access: public

Parameters:

string   $table_name   —  name of the table
array   $table   —  multi dimensional array that contains the structure and optional data of the table

[ Top ]

isError   [line 2750]

bool isError( mixed $data, [int $code = null])

Tell whether a value is an MDB2_Schema error.
  • Return: true if parameter is an error
  • Access: public

Parameters:

mixed   $data   —  the value to test
int   $code   —  if $data is an error object, return true only if $code is a string and $db->getMessage() == $code or $code is an integer and $db->getCode() == $code

[ Top ]

parseDatabaseDefinition   [line 337]

array parseDatabaseDefinition( string|array $schema, [bool $skip_unreadable = false], [array $variables = array()], [bool $fail_on_invalid_names = true], [array $structure = false])

Parse a database definition from a file or an array
  • Access: public

Parameters:

string|array   $schema   —  the database schema array or file name
bool   $skip_unreadable   —  if non readable files should be skipped
array   $variables   —  associative array that the defines the text string values that are meant to be used to replace the variables that are used in the schema description.
bool   $fail_on_invalid_names   —  make function fail on invalid names
array   $structure   —  database structure definition

[ Top ]

parseDatabaseDefinitionFile   [line 374]

array parseDatabaseDefinitionFile( string $input_file, [array $variables = array()], [bool $fail_on_invalid_names = true], [array $structure = false])

Parse a database definition file by creating a schema format parser object and passing the file contents as parser input data stream.
  • Access: public

Parameters:

string   $input_file   —  the database schema file.
array   $variables   —  associative array that the defines the text string values that are meant to be used to replace the variables that are used in the schema description.
bool   $fail_on_invalid_names   —  make function fail on invalid names
array   $structure   —  database structure definition

[ Top ]

raiseError   [line 2729]

object a &raiseError( [int|PEAR_Error $code = null], [int $mode = null], [array $options = null], [string $userinfo = null])

This method is used to communicate an error and invoke error callbacks etc. Basically a wrapper for PEAR::raiseError without the message string.
  • Return: PEAR error object
  • See: PEAR_Error
  • Access: public

Parameters:

int|PEAR_Error   $code   —  integer error code or and PEAR_Error instance
int   $mode   —  error mode, see PEAR_Error docs error level (E_USER_NOTICE etc). If error mode is PEAR_ERROR_CALLBACK, this is the callback function, either as a function name, or as an array of an object and method name. For other error modes this parameter is ignored.
array   $options   —  Options, depending on the mode, @see PEAR::setErrorHandling
string   $userinfo   —  Extra debug information. Defaults to the last query and native error code.

[ Top ]

resetWarnings   [line 151]

void resetWarnings( )

reset the warning array
  • Access: public

[ Top ]

setOption   [line 185]

bool|MDB2_Error setOption( string $option, mixed $value)

Sets the option for the db class
  • Return: MDB2_OK or error object
  • Access: public

Parameters:

string   $option   —  option name
mixed   $value   —  value for the option

[ Top ]

updateDatabase   [line 2593]

bool|MDB2_Error updateDatabase( string|array $current_schema, [string|array $previous_schema = false], [array $variables = array()], [bool $disable_query = false], [bool $overwrite_old_schema_file = false])

Compare the correspondent files of two versions of a database schema definition: the previously installed and the one that defines the schema that is meant to update the database.

If the specified previous definition file does not exist, this function will create the database from the definition specified in the current schema file. If both files exist, the function assumes that the database was previously installed based on the previous schema file and will update it by just applying the changes. If this function succeeds, the contents of the current schema file are copied to replace the previous schema file contents. Any subsequent schema changes should only be done on the file specified by the $current_schema_file to let this function make a consistent evaluation of the exact changes that need to be applied.

  • Return: MDB2_OK or error object
  • Access: public

Parameters:

string|array   $current_schema   —  filename or array of the updated database schema definition.
string|array   $previous_schema   —  filename or array of the previously installed database schema definition.
array   $variables   —  associative array that is passed to the argument of the same name to the parseDatabaseDefinitionFile function. (there third param)
bool   $disable_query   —  determines if the disable_query option should be set to true for the alterDatabase() or createDatabase() call
bool   $overwrite_old_schema_file   —  Overwrite?

[ Top ]

verifyAlterDatabase   [line 1878]

bool|MDB2_Error verifyAlterDatabase( array $changes)

Verify that the changes requested are supported
  • Return: MDB2_OK or error object
  • Access: public

Parameters:

array   $changes   —  associative array that contains the definition of the changes that are meant to be applied to the database structure.

[ Top ]

writeInitialization   [line 2500]

bool|MDB2_Error writeInitialization( string|array $data, [string|array $structure = false], [array $variables = array()])

Write initialization and sequences
  • Return: MDB2_OK or error object
  • Access: public

Parameters:

string|array   $data   —  data file or data array
string|array   $structure   —  structure file or array
array   $variables   —  associative array that is passed to the argument of the same name to the parseDatabaseDefinitionFile function. (there third param)

[ Top ]


Documentation generated on Mon, 11 Mar 2019 16:04:24 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.