Moodle  2.2.1
http://www.collinsharper.com
database_manager Class Reference

Public Member Functions

 __construct ($mdb, $generator)
 dispose ()
 table_exists ($table)
 reset_sequence ($table)
 field_exists ($table, $field)
 find_index_name (xmldb_table $xmldb_table, xmldb_index $xmldb_index)
 index_exists (xmldb_table $xmldb_table, xmldb_index $xmldb_index)
 find_check_constraint_name (xmldb_table $xmldb_table, xmldb_field $xmldb_field)
 check_constraint_exists (xmldb_table $xmldb_table, xmldb_field $xmldb_field)
 find_key_name (xmldb_table $xmldb_table, xmldb_key $xmldb_key)
 delete_tables_from_xmldb_file ($file)
 drop_table (xmldb_table $xmldb_table)
 install_from_xmldb_file ($file)
 install_one_table_from_xmldb_file ($file, $tablename, $cachestructures=false)
 install_from_xmldb_structure ($xmldb_structure)
 create_table (xmldb_table $xmldb_table)
 create_temp_table (xmldb_table $xmldb_table)
 drop_temp_table (xmldb_table $xmldb_table)
 rename_table (xmldb_table $xmldb_table, $newname)
 add_field (xmldb_table $xmldb_table, xmldb_field $xmldb_field)
 drop_field (xmldb_table $xmldb_table, xmldb_field $xmldb_field)
 change_field_type (xmldb_table $xmldb_table, xmldb_field $xmldb_field)
 change_field_precision (xmldb_table $xmldb_table, xmldb_field $xmldb_field)
 change_field_unsigned (xmldb_table $xmldb_table, xmldb_field $xmldb_field)
 change_field_notnull (xmldb_table $xmldb_table, xmldb_field $xmldb_field)
 change_field_default (xmldb_table $xmldb_table, xmldb_field $xmldb_field)
 drop_enum_from_field (xmldb_table $xmldb_table, xmldb_field $xmldb_field)
 rename_field (xmldb_table $xmldb_table, xmldb_field $xmldb_field, $newname)
 add_key (xmldb_table $xmldb_table, xmldb_key $xmldb_key)
 drop_key (xmldb_table $xmldb_table, xmldb_key $xmldb_key)
 rename_key (xmldb_table $xmldb_table, xmldb_key $xmldb_key, $newname)
 add_index ($xmldb_table, $xmldb_intex)
 drop_index ($xmldb_table, $xmldb_intex)
 rename_index ($xmldb_table, $xmldb_intex, $newname)
 get_install_xml_schema ()
 check_database_schema (xmldb_structure $schema)

Data Fields

 $generator

Protected Member Functions

 execute_sql_arr (array $sqlarr)
 execute_sql ($sql)

Protected Attributes

 $mdb

Detailed Description

Database manager instance is responsible for all database structure modifications. It is using db specific generators to find out the correct SQL syntax to do that.

Definition at line 38 of file database_manager.php.


Constructor & Destructor Documentation

__construct ( mdb,
generator 
)

Creates new database manager

Parameters:
objectmoodle_database instance

Definition at line 47 of file database_manager.php.


Member Function Documentation

add_field ( xmldb_table xmldb_table,
xmldb_field xmldb_field 
)

This function will add the field to the table passed as arguments

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_fieldfield object (full specs are required)
Returns:
void

Check the field doesn't exist

If NOT NULL and no default given (we ask the generator about the real* default that will be used) check the table is empty

Definition at line 570 of file database_manager.php.

Here is the call graph for this function:

add_index ( xmldb_table,
xmldb_intex 
)

This function will create the index in the table passed as arguments Before creating the index, the function will check it doesn't exists

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_indexindex object (full specs are required)
Returns:
void

Check index doesn't exist

Definition at line 876 of file database_manager.php.

Here is the call graph for this function:

add_key ( xmldb_table xmldb_table,
xmldb_key xmldb_key 
)

This function will create the key in the table passed as arguments

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_keyindex object (full specs are required)
Returns:
void

Definition at line 812 of file database_manager.php.

Here is the call graph for this function:

change_field_default ( xmldb_table xmldb_table,
xmldb_field xmldb_field 
)

This function will change the default of the field in the table passed as arguments One null value in the default field means delete the default

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_fieldfield object (full specs are required)
Returns:
void

Check the field exists

Check for dependencies in the DB before performing any action

Definition at line 683 of file database_manager.php.

Here is the call graph for this function:

change_field_notnull ( xmldb_table xmldb_table,
xmldb_field xmldb_field 
)

This function will change the nullability of the field in the table passed as arguments

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_fieldfield object (full specs are required)
Returns:
void

Just a wrapper over change_field_type. Does exactly the same processing

Definition at line 670 of file database_manager.php.

Here is the call graph for this function:

change_field_precision ( xmldb_table xmldb_table,
xmldb_field xmldb_field 
)

This function will change the precision of the field in the table passed as arguments

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_fieldfield object (full specs are required)
Returns:
void

Just a wrapper over change_field_type. Does exactly the same processing

Definition at line 646 of file database_manager.php.

Here is the call graph for this function:

change_field_type ( xmldb_table xmldb_table,
xmldb_field xmldb_field 
)

This function will change the type of the field in the table passed as arguments

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_fieldfield object (full specs are required)
Returns:
void

Check the field exists

Check for dependencies in the DB before performing any action

Definition at line 621 of file database_manager.php.

Here is the call graph for this function:

Here is the caller graph for this function:

change_field_unsigned ( xmldb_table xmldb_table,
xmldb_field xmldb_field 
)

This function will change the unsigned/signed of the field in the table passed as arguments

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_fieldfield object (full specs are required)
Returns:
void

Just a wrapper over change_field_type. Does exactly the same processing

Definition at line 658 of file database_manager.php.

Here is the call graph for this function:

check_constraint_exists ( xmldb_table xmldb_table,
xmldb_field xmldb_field 
)

Given one xmldb_field, check if it has a check constraint in DB

TODO: Moodle 2.1 - Drop check_constraint_exists()

Parameters:
xmldb_tablethe table
xmldb_fieldthe field to be searched for any existing constraint
Returns:
boolean true/false

Definition at line 263 of file database_manager.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Checks the database schema against a schema specified by an xmldb_structure object

Parameters:
xmldb_structure$schemaexport schema describing all known tables
Returns:
array keyed by table name with array of difference messages as values

Definition at line 987 of file database_manager.php.

Here is the call graph for this function:

create_table ( xmldb_table xmldb_table)

This function will create the table passed as argument with all its fields/keys/indexes/sequences, everything based in the XMLDB object

Parameters:
xmldb_tabletable object (full specs are required)
Returns:
void

Check table doesn't exist

Definition at line 466 of file database_manager.php.

Here is the call graph for this function:

create_temp_table ( xmldb_table xmldb_table)

This function will create the temporary table passed as argument with all its fields/keys/indexes/sequences, everything based in the XMLDB object

If table already exists ddl_exception will be thrown, please make sure the table name does not collide with existing normal table!

Parameters:
xmldb_tabletable object (full specs are required)
Returns:
void

Definition at line 488 of file database_manager.php.

Here is the call graph for this function:

This function will delete all tables found in XMLDB file from db

Parameters:
$filefull path to the XML file to be used
Returns:
void

Show info about the error if we can find it

Definition at line 322 of file database_manager.php.

Here is the call graph for this function:

dispose ( )

Release all resources

Definition at line 57 of file database_manager.php.

Here is the call graph for this function:

Here is the caller graph for this function:

drop_enum_from_field ( xmldb_table xmldb_table,
xmldb_field xmldb_field 
)

This function will drop the existing enum of the field in the table passed as arguments

TODO: Moodle 2.1 - Drop drop_enum_from_field()

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_fieldfield object (full specs are required)
Returns:
void

Check the field exists

Definition at line 710 of file database_manager.php.

Here is the call graph for this function:

drop_field ( xmldb_table xmldb_table,
xmldb_field xmldb_field 
)

This function will drop the field from the table passed as arguments

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_fieldfield object (just the name is mandatory)
Returns:
void

Check the field exists

Check for dependencies in the DB before performing any action

Definition at line 596 of file database_manager.php.

Here is the call graph for this function:

drop_index ( xmldb_table,
xmldb_intex 
)

This function will drop the index in the table passed as arguments Before dropping the index, the function will check it exists

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_indexindex object (full specs are required)
Returns:
void

Check index exists

Definition at line 903 of file database_manager.php.

Here is the call graph for this function:

drop_key ( xmldb_table xmldb_table,
xmldb_key xmldb_key 
)

This function will drop the key in the table passed as arguments

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_keykey object (full specs are required)
Returns:
void

Definition at line 832 of file database_manager.php.

Here is the call graph for this function:

drop_table ( xmldb_table xmldb_table)

This function will drop the table passed as argument and all the associated objects (keys, indexes, constraints, sequences, triggers) will be dropped too.

Parameters:
xmldb_tabletable object (just the name is mandatory)
Returns:
void

Check table exists

Definition at line 360 of file database_manager.php.

Here is the call graph for this function:

Here is the caller graph for this function:

drop_temp_table ( xmldb_table xmldb_table)

This function will drop the temporary table passed as argument with all its fields/keys/indexes/sequences, everything based in the XMLDB object

It is recommended to drop temp table when not used anymore.

Parameters:
xmldb_tabletable object
Returns:
void

Check table doesn't exist

Definition at line 511 of file database_manager.php.

Here is the call graph for this function:

execute_sql ( sql) [protected]

Execute a given sql command string

Exceptions:
ddl_exceptionif error found
Parameters:
string$commandThe sql string you wish to be executed.
Returns:
void

Definition at line 87 of file database_manager.php.

Here is the caller graph for this function:

execute_sql_arr ( array sqlarr) [protected]

This function will execute an array of SQL commands.

Exceptions:
ddl_exceptionif error found
Parameters:
array$sqlarrarray of sql statements to execute
Returns:
void

Definition at line 73 of file database_manager.php.

Here is the call graph for this function:

Here is the caller graph for this function:

field_exists ( table,
field 
)

Given one xmldb_field, check if it exists in DB (true/false)

Parameters:
mixedthe table to be searched (string name or xmldb_table instance)
mixedthe field to be searched for (string name or xmldb_field instance)
Returns:
boolean true/false

Calculate the name of the table

Check the table exists

Calculate the name of the table

Get list of fields in table

Definition at line 136 of file database_manager.php.

Here is the call graph for this function:

Here is the caller graph for this function:

find_check_constraint_name ( xmldb_table xmldb_table,
xmldb_field xmldb_field 
)

Given one xmldb_field, the function returns the name of the check constraint in DB (if exists) of false if it doesn't exist. Note that XMLDB limits the number of check constraints per field to 1 "enum-like" constraint. So, if more than one is returned, only the first one will be retrieved by this function.

TODO: Moodle 2.1 - Drop find_check_constraint_name()

Parameters:
xmldb_tablethe table to be searched
xmldb_fieldthe field to be searched
Returns:
string check constraint name or false

Check the table exists

Check the field exists

Get list of check_constraints in table/field

Get only the 1st element. Shouldn't be more than 1 under XMLDB

Arriving here, check not found

Definition at line 228 of file database_manager.php.

Here is the call graph for this function:

Here is the caller graph for this function:

find_index_name ( xmldb_table xmldb_table,
xmldb_index xmldb_index 
)

Given one xmldb_index, the function returns the name of the index in DB of false if it doesn't exist

Parameters:
object$xmldb_tabletable to be searched
object$xmldb_indexthe index to be searched
Returns:
string index name of false

Calculate the name of the table

Check the table exists

Extract index columns

Get list of indexes in table

Iterate over them looking for columns coincidence

Check if index matchs queried index

If no diferences, we have find the index

Arriving here, index not found

Definition at line 172 of file database_manager.php.

Here is the call graph for this function:

Here is the caller graph for this function:

find_key_name ( xmldb_table xmldb_table,
xmldb_key xmldb_key 
)

This function IS NOT IMPLEMENTED. ONCE WE'LL BE USING RELATIONAL INTEGRITY IT WILL BECOME MORE USEFUL. FOR NOW, JUST CALCULATE "OFFICIAL" KEY NAMES WITHOUT ACCESSING TO DB AT ALL. Given one xmldb_key, the function returns the name of the key in DB (if exists) of false if it doesn't exist

Parameters:
xmldb_tablethe table to be searched
xmldb_keythe key to be searched
Returns:
string key name of false

Get list of keys in table first primaries (we aren't going to use this now, because the MetaPrimaryKeys is awful)

TODO: To implement when we advance in relational integrity

then uniques (note that Moodle, for now, shouldn't have any UNIQUE KEY for now, but unique indexes)

TODO: To implement when we advance in relational integrity (note that AdoDB hasn't any MetaXXX for this.

then foreign (note that Moodle, for now, shouldn't have any FOREIGN KEY for now, but indexes)

TODO: To implement when we advance in relational integrity (note that AdoDB has one MetaForeignKeys() but it's far from perfect.

TODO: To create the proper functions inside each generator to retrieve all the needed KEY info (name columns, reftable and refcolumns

So all we do is to return the official name of the requested key without any confirmation!) One exception, hardcoded primary constraint names

Calculate the name suffix

And simply, return the official name

Definition at line 278 of file database_manager.php.

Here is the call graph for this function:

Reads the install.xml files for Moodle core and modules and returns an array of xmldb_structure object with xmldb_table from these files.

Returns:
xmldb_structure schema from install.xml files

Definition at line 959 of file database_manager.php.

Here is the call graph for this function:

index_exists ( xmldb_table xmldb_table,
xmldb_index xmldb_index 
)

Given one xmldb_index, check if it exists in DB (true/false)

Parameters:
object$xmldb_tablethe table to be searched
object$xmldb_indexthe index to be searched for
Returns:
boolean true/false

Definition at line 209 of file database_manager.php.

Here is the call graph for this function:

Here is the caller graph for this function:

This function will load one entire XMLDB file and call install_from_xmldb_structure.

Parameters:
$filefull path to the XML file to be used
Returns:
void

Definition at line 405 of file database_manager.php.

Here is the call graph for this function:

install_from_xmldb_structure ( xmldb_structure)

This function will generate all the needed SQL statements, specific for each RDBMS type and, finally, it will execute all those statements against the DB.

Parameters:
object$structurexmldb_structure object
Returns:
void

Definition at line 451 of file database_manager.php.

Here is the call graph for this function:

Here is the caller graph for this function:

install_one_table_from_xmldb_file ( file,
tablename,
cachestructures = false 
)

This function will load one entire XMLDB file and call install_from_xmldb_structure.

Parameters:
$filefull path to the XML file to be used
$tablenamethe name of the table.
bool$cachestructuresboolean to decide if loaded xmldb structures can be safely cached useful for testunits loading the enormous main xml file hundred of times (100x)

Definition at line 419 of file database_manager.php.

Here is the call graph for this function:

rename_field ( xmldb_table xmldb_table,
xmldb_field xmldb_field,
newname 
)

This function will rename the field in the table passed as arguments Before renaming the field, the function will check it exists

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_fieldindex object (full specs are required)
stringnew name of the field
Returns:
void

Check the field exists

Check we have included full field specs

Check field isn't id. Renaming over that field is not allowed

Definition at line 741 of file database_manager.php.

Here is the call graph for this function:

rename_index ( xmldb_table,
xmldb_intex,
newname 
)

This function will rename the index in the table passed as arguments Before renaming the index, the function will check it exists Experimental. Shouldn't be used at all!

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_indexindex object (full specs are required)
stringnew name of the index
Returns:
void

Check newname isn't empty

Check index exists

Definition at line 932 of file database_manager.php.

Here is the call graph for this function:

rename_key ( xmldb_table xmldb_table,
xmldb_key xmldb_key,
newname 
)

This function will rename the key in the table passed as arguments Experimental. Shouldn't be used at all in normal installation/upgrade!

Parameters:
xmldb_tabletable object (just the name is mandatory)
xmldb_keykey object (full specs are required)
stringnew name of the key
Returns:
void

Check newname isn't empty

Definition at line 853 of file database_manager.php.

Here is the call graph for this function:

rename_table ( xmldb_table xmldb_table,
newname 
)

This function will rename the table passed as argument Before renaming the index, the function will check it exists

Parameters:
xmldb_tabletable object (just the name is mandatory)
stringnew name of the index
Returns:
void

Check newname isn't empty

Check table already renamed

Check new table doesn't exist

Definition at line 533 of file database_manager.php.

Here is the call graph for this function:

reset_sequence ( table)

Reset a sequence to the id field of a table.

Parameters:
string$tablename of table
Returns:
success

Check the table exists

Definition at line 112 of file database_manager.php.

Here is the call graph for this function:

table_exists ( table)

Given one xmldb_table, check if it exists in DB (true/false)

Parameters:
mixedthe table to be searched (string name or xmldb_table instance)
Returns:
boolean true/false

Definition at line 100 of file database_manager.php.

Here is the caller graph for this function:


Field Documentation

Definition at line 41 of file database_manager.php.

$mdb [protected]

Definition at line 40 of file database_manager.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations