Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
Database manager instance is responsible for all database structure modifications. More...
Public Member Functions | |
__construct ($mdb, $generator) | |
Creates a new database manager instance. More... | |
add_field (xmldb_table $xmldb_table, xmldb_field $xmldb_field) | |
This function will add the field to the table passed as arguments. More... | |
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. More... | |
add_key (xmldb_table $xmldb_table, xmldb_key $xmldb_key) | |
This function will create the key in the table passed as arguments. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
check_database_schema (xmldb_structure $schema, array $options=null) | |
Checks the database schema against a schema specified by an xmldb_structure object. More... | |
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. More... | |
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. More... | |
delete_tables_from_xmldb_file ($file) | |
This function will delete all tables found in XMLDB file from db. More... | |
dispose () | |
Releases all resources. | |
drop_field (xmldb_table $xmldb_table, xmldb_field $xmldb_field) | |
This function will drop the field from the table passed as arguments. More... | |
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. More... | |
drop_key (xmldb_table $xmldb_table, xmldb_key $xmldb_key) | |
This function will drop the key in the table passed as arguments. More... | |
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. More... | |
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. More... | |
field_exists ($table, $field) | |
Given one xmldb_field, check if it exists in DB (true/false). More... | |
find_index_name (xmldb_table $xmldb_table, xmldb_index $xmldb_index, $returnall=false) | |
Given one xmldb_index, the function returns the name of the index in DB of false if it doesn't exist. More... | |
find_key_name (xmldb_table $xmldb_table, xmldb_key $xmldb_key) | |
This function IS NOT IMPLEMENTED. More... | |
get_install_xml_files () | |
Get the list of install.xml files. More... | |
get_install_xml_schema () | |
Reads the install.xml files for Moodle core and modules and returns an array of xmldb_structure object with xmldb_table from these files. More... | |
index_exists (xmldb_table $xmldb_table, xmldb_index $xmldb_index) | |
Given one xmldb_index, check if it exists in DB (true/false). More... | |
install_from_xmldb_file ($file) | |
This function will load one entire XMLDB file and call install_from_xmldb_structure. More... | |
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. More... | |
install_one_table_from_xmldb_file ($file, $tablename, $cachestructures=false) | |
This function will load one entire XMLDB file and call install_from_xmldb_structure. More... | |
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. More... | |
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. More... | |
rename_key (xmldb_table $xmldb_table, xmldb_key $xmldb_key, $newname) | |
This function will rename the key in the table passed as arguments Experimental. More... | |
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. More... | |
reset_sequence ($table) | |
Reset a sequence to the id field of a table. More... | |
table_exists ($table) | |
Given one xmldb_table, check if it exists in DB (true/false). More... | |
Public Attributes | |
sql_generator | $generator |
A driver specific SQL generator instance. More... | |
Protected Member Functions | |
execute_sql ($sql) | |
Execute a given sql command string. More... | |
execute_sql_arr (array $sqlarr, $tablenames=null) | |
This function will execute an array of SQL commands. More... | |
Protected Attributes | |
moodle_database | $mdb |
A moodle_database driver specific instance. | |
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.
database_manager::__construct | ( | $mdb, | |
$generator | |||
) |
Creates a new database manager instance.
moodle_database | $mdb | A moodle_database driver specific instance. |
sql_generator | $generator | A driver specific SQL generator instance. |
database_manager::add_field | ( | xmldb_table | $xmldb_table, |
xmldb_field | $xmldb_field | ||
) |
This function will add the field to the table passed as arguments.
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
xmldb_field | $xmldb_field | Index object (full specs are required). |
void |
database_manager::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.
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
xmldb_index | $xmldb_intex | Index object (full specs are required). |
void |
database_manager::add_key | ( | xmldb_table | $xmldb_table, |
xmldb_key | $xmldb_key | ||
) |
This function will create the key in the table passed as arguments.
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
xmldb_key | $xmldb_key | Index object (full specs are required). |
void |
database_manager::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.
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
xmldb_field | $xmldb_field | Index object (full specs are required). |
void |
database_manager::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.
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
xmldb_field | $xmldb_field | Index object (full specs are required). |
void |
database_manager::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.
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
xmldb_field | $xmldb_field | Index object (full specs are required). |
void |
database_manager::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.
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
xmldb_field | $xmldb_field | Index object (full specs are required). |
void |
database_manager::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.
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
xmldb_field | $xmldb_field | Field object (full specs are required). |
void |
database_manager::check_database_schema | ( | xmldb_structure | $schema, |
array | $options = null |
||
) |
Checks the database schema against a schema specified by an xmldb_structure object.
xmldb_structure | $schema | export schema describing all known tables |
array | $options |
array | keyed by table name with array of difference messages as values |
database_manager::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.
xmldb_table | $xmldb_table | Table object (full specs are required). |
void |
database_manager::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!
xmldb_table | $xmldb_table | Table object (full specs are required). |
void |
database_manager::delete_tables_from_xmldb_file | ( | $file | ) |
This function will delete all tables found in XMLDB file from db.
string | $file | Full path to the XML file to be used. |
void |
database_manager::drop_field | ( | xmldb_table | $xmldb_table, |
xmldb_field | $xmldb_field | ||
) |
This function will drop the field from the table passed as arguments.
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
xmldb_field | $xmldb_field | Index object (full specs are required). |
void |
database_manager::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.
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
xmldb_index | $xmldb_intex | Index object (full specs are required). |
void |
database_manager::drop_key | ( | xmldb_table | $xmldb_table, |
xmldb_key | $xmldb_key | ||
) |
This function will drop the key in the table passed as arguments.
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
xmldb_key | $xmldb_key | Key object (full specs are required). |
void |
database_manager::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.
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
void |
database_manager::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.
xmldb_table | $xmldb_table | Table object. |
void |
|
protected |
Execute a given sql command string.
string | $sql | The sql string you wish to be executed. |
ddl_change_structure_exception | This exception is thrown if any error is found. |
|
protected |
This function will execute an array of SQL commands.
string[] | $sqlarr | Array of sql statements to execute. |
array | null | $tablenames | an array of xmldb table names affected by this request. |
ddl_change_structure_exception | This exception is thrown if any error is found. |
database_manager::field_exists | ( | $table, | |
$field | |||
) |
Given one xmldb_field, check if it exists in DB (true/false).
string | xmldb_table | $table | The table to be searched (string name or xmldb_table instance). |
string | xmldb_field | $field | The field to be searched for (string name or xmldb_field instance). |
boolean | true is exists false otherwise. |
ddl_table_missing_exception |
database_manager::find_index_name | ( | xmldb_table | $xmldb_table, |
xmldb_index | $xmldb_index, | ||
$returnall = false |
|||
) |
Given one xmldb_index, the function returns the name of the index in DB of false if it doesn't exist.
xmldb_table | $xmldb_table | table to be searched |
xmldb_index | $xmldb_index | the index to be searched |
bool | $returnall | true means return array of all indexes, false means first index only as string |
array|string|bool | Index name, array of index names or false if no indexes are found. |
ddl_table_missing_exception | Thrown when table is not found. |
database_manager::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
xmldb_table | $xmldb_table | The table to be searched. |
xmldb_key | $xmldb_key | The key to be searched. |
string | key name if found |
database_manager::get_install_xml_files | ( | ) |
Get the list of install.xml files.
array |
database_manager::get_install_xml_schema | ( | ) |
Reads the install.xml files for Moodle core and modules and returns an array of xmldb_structure object with xmldb_table from these files.
xmldb_structure | schema from install.xml files |
database_manager::index_exists | ( | xmldb_table | $xmldb_table, |
xmldb_index | $xmldb_index | ||
) |
Given one xmldb_index, check if it exists in DB (true/false).
xmldb_table | $xmldb_table | The table to be searched. |
xmldb_index | $xmldb_index | The index to be searched for. |
boolean | true id index exists, false otherwise. |
database_manager::install_from_xmldb_file | ( | $file | ) |
This function will load one entire XMLDB file and call install_from_xmldb_structure.
string | $file | full path to the XML file to be used |
void |
database_manager::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.
stdClass | $xmldb_structure | xmldb_structure object. |
void |
database_manager::install_one_table_from_xmldb_file | ( | $file, | |
$tablename, | |||
$cachestructures = false |
|||
) |
This function will load one entire XMLDB file and call install_from_xmldb_structure.
string | $file | full path to the XML file to be used |
string | $tablename | the name of the table. |
bool | $cachestructures | boolean to decide if loaded xmldb structures can be safely cached useful for testunits loading the enormous main xml file hundred of times (100x) |
database_manager::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.
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
xmldb_field | $xmldb_field | Index object (full specs are required). |
string | $newname | New name of the field. |
void |
database_manager::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!
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
xmldb_index | $xmldb_intex | Index object (full specs are required). |
string | $newname | New name of the index. |
void |
database_manager::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!
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
xmldb_key | $xmldb_key | key object (full specs are required). |
string | $newname | New name of the key. |
void |
database_manager::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.
xmldb_table | $xmldb_table | Table object (just the name is mandatory). |
string | $newname | New name of the index. |
void |
database_manager::reset_sequence | ( | $table | ) |
Reset a sequence to the id field of a table.
string | xmldb_table | $table | Name of table. |
ddl_exception | thrown upon reset errors. |
database_manager::table_exists | ( | $table | ) |
Given one xmldb_table, check if it exists in DB (true/false).
string | xmldb_table | $table | The table to be searched (string name or xmldb_table instance). |
bool | True is a table exists, false otherwise. |
sql_generator database_manager::$generator |
A driver specific SQL generator instance.
Public because XMLDB editor needs to access it.