Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
mysql_sql_generator Class Reference
Inheritance diagram for mysql_sql_generator:
sql_generator

Public Member Functions

 addslashes ($s)
 Adds slashes to string.
 
 cleanup_after_drop (xmldb_table $table)
 Performs any clean up that needs to be done after a table is dropped.
 
 dispose ()
 Releases all resources.
 
 get_nullable_fields_in_index ($xmldb_table, $xmldb_index)
 Get the fields from an index definition that might be null.
 
 getAddFieldSQL ($xmldb_table, $xmldb_field, $skip_type_clause=NULL, $skip_default_clause=NULL, $skip_notnull_clause=NULL)
 Given one xmldb_table and one xmldb_field, return the SQL statements needed to add the field to the table.
 
 getAddIndexSQL ($xmldb_table, $xmldb_index)
 Given one xmldb_table and one xmldb_index, return the SQL statements needed to add the index to the table.
 
 getAddKeySQL ($xmldb_table, $xmldb_key)
 Given one xmldb_table and one xmldb_key, return the SQL statements needed to add the key to the table note that undelying indexes will be added as parametrised by $xxxx_keys and $xxxx_index parameters.
 
 getAlterFieldSQL ($xmldb_table, $xmldb_field, $skip_type_clause=NULL, $skip_default_clause=NULL, $skip_notnull_clause=NULL)
 Given one xmldb_table and one xmldb_field, return the SQL statements needed to alter the field in the table.
 
 getCommentSQL ($xmldb_table)
 Returns the code (array of statements) needed to add one comment to the table.
 
 getConcatSQL ($elements)
 Given one array of elements, build the proper CONCAT expression, based in the $concat_character setting.
 
 getCreateDefaultSQL ($xmldb_table, $xmldb_field)
 Given one xmldb_table and one xmldb_field, return the SQL statements needed to add its default (usually invoked from getModifyDefaultSQL()
 
 getCreateIndexSQL ($xmldb_table, $xmldb_index)
 Given one correct xmldb_index, returns the SQL statements needed to create it (in array).
 
 getCreateSequenceSQL ($xmldb_table, $xmldb_field)
 Returns the code (array of statements) needed to create one sequence for the xmldb_table and xmldb_field passed in.
 
 getCreateStructureSQL ($xmldb_structure)
 This function will return the SQL code needed to create db tables and statements.
 
 getCreateTableSQL ($xmldb_table)
 Given one correct xmldb_table, returns the SQL statements to create it (inside one array).
 
 getCreateTempTableSQL ($xmldb_table)
 Given one correct xmldb_table, returns the SQL statements to create temporary table (inside one array).
 
 getDefaultClause ($xmldb_field)
 Given one xmldb_field, returns the correct "default clause" for the current configuration.
 
 getDefaultValue ($xmldb_field)
 Give one xmldb_field, returns the correct "default value" for the current configuration.
 
 getDropDefaultSQL ($xmldb_table, $xmldb_field)
 Given one xmldb_table and one xmldb_field, return the SQL statements needed to drop its default (usually invoked from getModifyDefaultSQL()
 
 getDropFieldSQL ($xmldb_table, $xmldb_field)
 Given one xmldb_table and one xmldb_field, return the SQL statements needed to drop the field from the table.
 
 getDropIndexSQL ($xmldb_table, $xmldb_index)
 Given one xmldb_table and one xmldb_index, return the SQL statements needed to drop the index from the table.
 
 getDropKeySQL ($xmldb_table, $xmldb_key)
 Given one xmldb_table and one xmldb_index, return the SQL statements needed to drop the index from the table.
 
 getDropTableExtraSQL ($xmldb_table)
 Returns the code (array of statements) needed to execute extra statements on table drop.
 
 getDropTableSQL ($xmldb_table)
 Given one correct xmldb_table, returns the SQL statements to drop it (inside one array).
 
 getEncQuoted ($input)
 Given any string (or one array), enclose it by the proper quotes if it's a reserved word.
 
 getEndedStatements ($input)
 Given one string (or one array), ends it with $statement_end .
 
 getExecuteInsertSQL ($statement)
 Given one XMLDB Statement, build the needed SQL insert sentences to execute it.
 
 getFieldSQL ($xmldb_table, $xmldb_field, $skip_type_clause=NULL, $skip_default_clause=NULL, $skip_notnull_clause=NULL, $specify_nulls_clause=NULL, $specify_field_name=true)
 Given one correct xmldb_field, returns the complete SQL line to create it.
 
 getKeySQL ($xmldb_table, $xmldb_key)
 Given one correct xmldb_key, returns its specs.
 
 getModifyDefaultSQL ($xmldb_table, $xmldb_field)
 Given one xmldb_table and one xmldb_field, return the SQL statements needed to modify the default of the field in the table.
 
 getNameForObject ($tablename, $fields, $suffix='')
 Given three strings (table name, list of fields (comma separated) and suffix), create the proper object name quoting it if necessary.
 
 getRenameFieldExtraSQL ($xmldb_table, $xmldb_field)
 Returns the code (array of statements) needed to execute extra statements on field rename.
 
 getRenameFieldSQL ($xmldb_table, $xmldb_field, $newname)
 Given one correct xmldb_field and the new name, returns the SQL statements to rename it (inside one array).
 
 getRenameIndexSQL ($xmldb_table, $xmldb_index, $newname)
 Given one xmldb_table and one xmldb_index, return the SQL statements needed to rename the index in the table Experimental! Shouldn't be used at all!
 
 getRenameKeySQL ($xmldb_table, $xmldb_key, $newname)
 Given one xmldb_table and one xmldb_key, return the SQL statements needed to rename the key in the table Experimental! Shouldn't be used at all!
 
 getRenameTableExtraSQL ($xmldb_table, $newname)
 Returns the code (array of statements) needed to execute extra statements on table rename.
 
 getRenameTableSQL ($xmldb_table, $newname)
 Given one correct xmldb_table and the new name, returns the SQL statements to rename it (inside one array).
 
 getResetSequenceSQL ($table)
 Reset a sequence to the id field of a table.
 
 getSequenceFromDB ($xmldb_table)
 Returns the name (string) of the sequence used in the table for the autonumeric pk Only some DB have this implemented.
 
 getTableName (xmldb_table $xmldb_table, $quoted=true)
 Given one xmldb_table, this returns it's correct name, depending of all the parameterization.
 
 getTypeSQL ($xmldb_type, $xmldb_length=null, $xmldb_decimals=null)
 Given one XMLDB Type, length and decimals, returns the DB proper SQL type.
 
 guess_antelope_row_size (array $columns)
 Calculate proximate row size when using InnoDB tables in Antelope row format.
 
 guess_antolope_row_size (array $columns)
 Calculate proximate row size when using InnoDB tables in Antelope row format.
 
 isNameInUse ($object_name, $type, $table_name)
 Given one object name and it's type (pk, uk, fk, ck, ix, uix, seq, trg).
 
 table_exists ($table)
 Given one xmldb_table, checks if it exists in DB (true/false).
 

Static Public Member Functions

static getAllReservedWords ()
 Returns all reserved words in supported databases.
 
static getReservedWords ()
 Returns an array of reserved words (lowercase) for this DB.
 

Public Attributes

 $add_after_clause = true
 
bool $add_table_comments = true
 True if the generator needs to add code for table comments.
 
bool $alter_column_skip_default = false
 The generator will skip the default clause on alter columns.
 
bool $alter_column_skip_notnull = false
 The generator will skip the null/notnull clause on alter columns.
 
bool $alter_column_skip_type = false
 The generator will skip the type clause on alter columns.
 
string $alter_column_sql = 'ALTER TABLE TABLENAME MODIFY COLUMN COLUMNSPECS'
 The SQL template to alter columns where the 'TABLENAME' and 'COLUMNSPECS' keywords are dynamically replaced.
 
string $concat_character = null
 Characters to be used as concatenation operator.
 
bool $default_after_null = true
 To decide if the default clause of each field must go after the null clause.
 
string $default_for_char = ''
 To define the default to set for NOT NULLs CHARs without default (null=do nothing).
 
string $drop_default_value = null
 The DEFAULT clause required to drop defaults.
 
bool $drop_default_value_required = true
 To specify if the generator must use some DEFAULT clause to drop defaults.
 
string $drop_foreign_key = 'ALTER TABLE TABLENAME DROP FOREIGN KEY KEYNAME'
 Template to drop FKs.
 
string $drop_index_sql = 'ALTER TABLE TABLENAME DROP INDEX INDEXNAME'
 SQL sentence to drop one index where 'TABLENAME', 'INDEXNAME' keywords are dynamically replaced.
 
string $drop_primary_key = 'ALTER TABLE TABLENAME DROP PRIMARY KEY'
 Template to drop PKs.
 
string $drop_table_sql = 'DROP TABLE TABLENAME'
 SQL sentence to drop one table where the 'TABLENAME' keyword is dynamically replaced.
 
string $drop_unique_key = 'ALTER TABLE TABLENAME DROP KEY KEYNAME'
 Template to drop UKs.
 
bool $float_to_number = false
 To create all the floats as NUMBER(x) (also called DECIMAL, NUMERIC...).
 
bool $foreign_keys = false
 True if the generator builds foreign keys.
 
bool $integer_to_number = false
 To create all the integers as NUMBER(x) (also called DECIMAL, NUMERIC...).
 
moodle_database $mdb
 The moodle_database instance.
 
int $names_max_length = 30
 Maximum length for key/index/sequence/trigger/check names (keep 30 for all!).
 
string $number_type = 'NUMERIC'
 Proper type for NUMBER(x) in this DB.
 
string $prefix
 The prefix to be used for all the DB objects.
 
bool $prefix_on_names = true
 True if the generator needs to prepend the prefix to all the key/index/sequence/trigger/check names.
 
string $primary_key_name = ''
 To force primary key names to one string (null=no force).
 
bool $primary_keys = true
 True if the generator builds primary keys.
 
bool $quote_all = false
 To decide if we want to quote all the names or only the reserved ones.
 
string $quote_string = '`'
 Used to quote names.
 
string $rename_column_sql = 'ALTER TABLE TABLENAME RENAME COLUMN OLDFIELDNAME TO NEWFIELDNAME'
 SQL sentence to rename one column where 'TABLENAME', 'OLDFIELDNAME' and 'NEWFIELDNAME' keywords are dynamically replaced.
 
string $rename_index_sql = null
 SQL sentence to rename one index where 'TABLENAME', 'OLDINDEXNAME' and 'NEWINDEXNAME' are dynamically replaced.
 
string $rename_key_sql = null
 SQL sentence to rename one key 'TABLENAME', 'OLDKEYNAME' and 'NEWKEYNAME' are dynamically replaced.
 
string $rename_table_sql = 'ALTER TABLE OLDNAME RENAME TO NEWNAME'
 SQL sentence to rename one table, both 'OLDNAME' and 'NEWNAME' keywords are dynamically replaced.
 
array $reserved_words
 List of reserved words (in order to quote them properly).
 
bool $sequence_extra_code = false
 True if the generator needs to add extra code to generate the sequence fields.
 
string $sequence_name = 'auto_increment'
 The particular name for inline sequences in this generator.
 
string bool $sequence_name_small = false
 Different name for small (4byte) sequences or false if same.
 
bool $sequence_only = false
 To avoid outputting the rest of the field specs, leaving only the name and the sequence_name returned.
 
bool $specify_nulls = false
 To force the generator if NULL clauses must be specified.
 
string $statement_end = ';'
 To be automatically added at the end of each statement.
 
bool $unique_keys = false
 True if the generator builds unique keys.
 
const ANTELOPE_MAX_ROW_SIZE = 8126
 Maximum size of InnoDB row in Antelope file format.
 

Protected Attributes

Control $temptables
 existing temptables.
 

Member Function Documentation

◆ addslashes()

sql_generator::addslashes ( $s)
inherited

Adds slashes to string.

Parameters
string$s
Return values
stringThe escaped string.

Reimplemented in mssql_sql_generator, oracle_sql_generator, postgres_sql_generator, and sqlite_sql_generator.

◆ cleanup_after_drop()

sql_generator::cleanup_after_drop ( xmldb_table $table)
inherited

Performs any clean up that needs to be done after a table is dropped.

Parameters
xmldb_table$table

◆ get_nullable_fields_in_index()

sql_generator::get_nullable_fields_in_index ( $xmldb_table,
$xmldb_index )
inherited

Get the fields from an index definition that might be null.

Parameters
xmldb_table$xmldb_tablethe table
xmldb_index$xmldb_indexthe index
Return values
arraylist of fields in the index definition that might be null.

◆ getAddFieldSQL()

mysql_sql_generator::getAddFieldSQL ( $xmldb_table,
$xmldb_field,
$skip_type_clause = NULL,
$skip_default_clause = NULL,
$skip_notnull_clause = NULL )

Given one xmldb_table and one xmldb_field, return the SQL statements needed to add the field to the table.

Parameters
xmldb_table$xmldb_tableThe table related to $xmldb_field.
xmldb_field$xmldb_fieldThe instance of xmldb_field to create the SQL from.
string$skip_type_clauseThe type clause on alter columns, NULL by default.
string$skip_default_clauseThe default clause on alter columns, NULL by default.
string$skip_notnull_clauseThe null/notnull clause on alter columns, NULL by default.
Return values
arrayThe SQL statement for adding a field to the table.

Reimplemented from sql_generator.

◆ getAddIndexSQL()

sql_generator::getAddIndexSQL ( $xmldb_table,
$xmldb_index )
inherited

Given one xmldb_table and one xmldb_index, return the SQL statements needed to add the index to the table.

Parameters
xmldb_table$xmldb_tableThe xmldb_table instance to add the index on.
xmldb_index$xmldb_indexThe xmldb_index to add.
Return values
arrayAn array of SQL statements to add the index.

◆ getAddKeySQL()

sql_generator::getAddKeySQL ( $xmldb_table,
$xmldb_key )
inherited

Given one xmldb_table and one xmldb_key, return the SQL statements needed to add the key to the table note that undelying indexes will be added as parametrised by $xxxx_keys and $xxxx_index parameters.

Parameters
xmldb_table$xmldb_tableThe table related to $xmldb_key.
xmldb_key$xmldb_keyThe xmldb_key to add.
Return values
arraySQL statement to add the xmldb_key.

Reimplemented in sqlite_sql_generator.

◆ getAllReservedWords()

static sql_generator::getAllReservedWords ( )
staticinherited

Returns all reserved words in supported databases.

Reserved words should be lowercase.

Return values
array('word'=>array(databases))

◆ getAlterFieldSQL()

mysql_sql_generator::getAlterFieldSQL ( $xmldb_table,
$xmldb_field,
$skip_type_clause = NULL,
$skip_default_clause = NULL,
$skip_notnull_clause = NULL )

Given one xmldb_table and one xmldb_field, return the SQL statements needed to alter the field in the table.

Parameters
xmldb_table$xmldb_tableThe table related to $xmldb_field.
xmldb_field$xmldb_fieldThe instance of xmldb_field to create the SQL from.
string$skip_type_clauseThe type clause on alter columns, NULL by default.
string$skip_default_clauseThe default clause on alter columns, NULL by default.
string$skip_notnull_clauseThe null/notnull clause on alter columns, NULL by default.
Return values
arrayThe field altering SQL statement.

Reimplemented from sql_generator.

◆ getCommentSQL()

mysql_sql_generator::getCommentSQL ( $xmldb_table)

Returns the code (array of statements) needed to add one comment to the table.

Parameters
xmldb_table$xmldb_tableThe xmldb_table object instance.
Return values
arrayArray of SQL statements to add one comment to the table.

Reimplemented from sql_generator.

◆ getConcatSQL()

sql_generator::getConcatSQL ( $elements)
inherited

Given one array of elements, build the proper CONCAT expression, based in the $concat_character setting.

If such setting is empty, then MySQL's CONCAT function will be used instead.

Parameters
array$elementsAn array of elements to concatenate.
Return values
mixedReturns the result of moodle_database\sql_concat() or false. @uses moodle_database\sql_concat() @uses call_user_func_array()

◆ getCreateDefaultSQL()

mysql_sql_generator::getCreateDefaultSQL ( $xmldb_table,
$xmldb_field )

Given one xmldb_table and one xmldb_field, return the SQL statements needed to add its default (usually invoked from getModifyDefaultSQL()

Parameters
xmldb_table$xmldb_tableThe xmldb_table object instance.
xmldb_field$xmldb_fieldThe xmldb_field object instance.
Return values
arrayArray of SQL statements to create a field's default.

Reimplemented from sql_generator.

◆ getCreateIndexSQL()

sql_generator::getCreateIndexSQL ( $xmldb_table,
$xmldb_index )
inherited

Given one correct xmldb_index, returns the SQL statements needed to create it (in array).

Parameters
xmldb_table$xmldb_tableThe xmldb_table instance to create the index on.
xmldb_index$xmldb_indexThe xmldb_index to create.
Return values
arrayAn array of SQL statements to create the index.
Exceptions
coding_exceptionThrown if the xmldb_index does not validate with the xmldb_table.

Reimplemented in mssql_sql_generator, oracle_sql_generator, and postgres_sql_generator.

◆ getCreateSequenceSQL()

sql_generator::getCreateSequenceSQL ( $xmldb_table,
$xmldb_field )
inherited

Returns the code (array of statements) needed to create one sequence for the xmldb_table and xmldb_field passed in.

Parameters
xmldb_table$xmldb_tableThe xmldb_table object instance.
xmldb_field$xmldb_fieldThe xmldb_field object instance.
Return values
arrayArray of SQL statements to create the sequence.

Reimplemented in oracle_sql_generator.

◆ getCreateStructureSQL()

sql_generator::getCreateStructureSQL ( $xmldb_structure)
inherited

This function will return the SQL code needed to create db tables and statements.

See also
xmldb_structure
Parameters
xmldb_structure$xmldb_structureAn xmldb_structure instance.
Return values
array

◆ getCreateTableSQL()

mysql_sql_generator::getCreateTableSQL ( $xmldb_table)

Given one correct xmldb_table, returns the SQL statements to create it (inside one array).

Parameters
xmldb_table$xmldb_tableAn xmldb_table instance.
Return values
arrayAn array of SQL statements, starting with the table creation SQL followed by any of its comments, indexes and sequence creation SQL statements.

Reimplemented from sql_generator.

◆ getCreateTempTableSQL()

mysql_sql_generator::getCreateTempTableSQL ( $xmldb_table)

Given one correct xmldb_table, returns the SQL statements to create temporary table (inside one array).

Parameters
xmldb_table$xmldb_tableThe xmldb_table object instance.
Return values
arrayof sql statements

Reimplemented from sql_generator.

◆ getDefaultClause()

sql_generator::getDefaultClause ( $xmldb_field)
inherited

Given one xmldb_field, returns the correct "default clause" for the current configuration.

Parameters
xmldb_field$xmldb_fieldThe xmldb_field.
Return values
TheSQL clause for generating the default value as in $xmldb_field.

◆ getDefaultValue()

sql_generator::getDefaultValue ( $xmldb_field)
inherited

Give one xmldb_field, returns the correct "default value" for the current configuration.

Parameters
xmldb_field$xmldb_fieldThe field.
Return values
Thedefault value of the field.

◆ getDropDefaultSQL()

mysql_sql_generator::getDropDefaultSQL ( $xmldb_table,
$xmldb_field )

Given one xmldb_table and one xmldb_field, return the SQL statements needed to drop its default (usually invoked from getModifyDefaultSQL()

Note that this method may be dropped in future.

Parameters
xmldb_table$xmldb_tableThe xmldb_table object instance.
xmldb_field$xmldb_fieldThe xmldb_field object instance.
Return values
arrayArray of SQL statements to create a field's default.
Todo
MDL-31147 Moodle 2.1 - Drop getDropDefaultSQL()

Reimplemented from sql_generator.

◆ getDropFieldSQL()

sql_generator::getDropFieldSQL ( $xmldb_table,
$xmldb_field )
inherited

Given one xmldb_table and one xmldb_field, return the SQL statements needed to drop the field from the table.

Parameters
xmldb_table$xmldb_tableThe table related to $xmldb_field.
xmldb_field$xmldb_fieldThe instance of xmldb_field to create the SQL from.
Return values
arrayThe SQL statement for dropping a field from the table.

Reimplemented in mssql_sql_generator, and sqlite_sql_generator.

◆ getDropIndexSQL()

sql_generator::getDropIndexSQL ( $xmldb_table,
$xmldb_index )
inherited

Given one xmldb_table and one xmldb_index, return the SQL statements needed to drop the index from the table.

Parameters
xmldb_table$xmldb_tableThe xmldb_table instance to drop the index on.
xmldb_index$xmldb_indexThe xmldb_index to drop.
Return values
arrayAn array of SQL statements to drop the index.

Reimplemented in sqlite_sql_generator.

◆ getDropKeySQL()

sql_generator::getDropKeySQL ( $xmldb_table,
$xmldb_key )
inherited

Given one xmldb_table and one xmldb_index, return the SQL statements needed to drop the index from the table.

Parameters
xmldb_table$xmldb_tableThe table related to $xmldb_key.
xmldb_key$xmldb_keyThe xmldb_key to drop.
Return values
arraySQL statement to drop the xmldb_key.

Reimplemented in sqlite_sql_generator.

◆ getDropTableExtraSQL()

sql_generator::getDropTableExtraSQL ( $xmldb_table)
inherited

Returns the code (array of statements) needed to execute extra statements on table drop.

Parameters
xmldb_table$xmldb_tableThe xmldb_table object instance.
Return values
arrayArray of extra SQL statements to drop a table.

Reimplemented in oracle_sql_generator.

◆ getDropTableSQL()

mysql_sql_generator::getDropTableSQL ( $xmldb_table)

Given one correct xmldb_table, returns the SQL statements to drop it (inside one array).

Parameters
xmldb_table$xmldb_tableThe table to drop.
Return values
arraySQL statement(s) for dropping the specified table.

Reimplemented from sql_generator.

◆ getEncQuoted()

sql_generator::getEncQuoted ( $input)
inherited

Given any string (or one array), enclose it by the proper quotes if it's a reserved word.

Parameters
string | array$inputString to quote.
Return values
string|arrayQuoted string.

◆ getEndedStatements()

sql_generator::getEndedStatements ( $input)
inherited

Given one string (or one array), ends it with $statement_end .

See also
$statement_end
Parameters
array | string$inputSQL statement(s).
Return values
array|string

◆ getExecuteInsertSQL()

sql_generator::getExecuteInsertSQL ( $statement)
inherited

Given one XMLDB Statement, build the needed SQL insert sentences to execute it.

Parameters
mixed$statementSQL statement.
Return values
arrayArray of sentences in the SQL statement.

◆ getFieldSQL()

sql_generator::getFieldSQL ( $xmldb_table,
$xmldb_field,
$skip_type_clause = NULL,
$skip_default_clause = NULL,
$skip_notnull_clause = NULL,
$specify_nulls_clause = NULL,
$specify_field_name = true )
inherited

Given one correct xmldb_field, returns the complete SQL line to create it.

Parameters
xmldb_table$xmldb_tableThe table related to $xmldb_field.
xmldb_field$xmldb_fieldThe instance of xmldb_field to create the SQL from.
string$skip_type_clauseThe type clause on alter columns, NULL by default.
string$skip_default_clauseThe default clause on alter columns, NULL by default.
string$skip_notnull_clauseThe null/notnull clause on alter columns, NULL by default.
string$specify_nulls_clauseTo force a specific null clause, NULL by default.
bool$specify_field_nameFlag to specify fieldname in return.
Return values
stringThe field generating SQL statement.
Exceptions
coding_exceptionThrown when xmldb_field doesn't validate with the xmldb_table.

◆ getKeySQL()

sql_generator::getKeySQL ( $xmldb_table,
$xmldb_key )
inherited

Given one correct xmldb_key, returns its specs.

Parameters
xmldb_table$xmldb_tableThe table related to $xmldb_key.
xmldb_key$xmldb_keyThe xmldb_key's specifications requested.
Return values
stringSQL statement about the xmldb_key.

Reimplemented in sqlite_sql_generator.

◆ getModifyDefaultSQL()

sql_generator::getModifyDefaultSQL ( $xmldb_table,
$xmldb_field )
inherited

Given one xmldb_table and one xmldb_field, return the SQL statements needed to modify the default of the field in the table.

Parameters
xmldb_table$xmldb_tableThe table related to $xmldb_field.
xmldb_field$xmldb_fieldThe instance of xmldb_field to get the modified default value from.
Return values
arrayThe SQL statement for modifying the default value.

Reimplemented in mssql_sql_generator.

◆ getNameForObject()

sql_generator::getNameForObject ( $tablename,
$fields,
$suffix = '' )
inherited

Given three strings (table name, list of fields (comma separated) and suffix), create the proper object name quoting it if necessary.

IMPORTANT: This function must be used to CALCULATE NAMES of objects TO BE CREATED, NEVER TO GUESS NAMES of EXISTING objects!!!

Parameters
string$tablenameThe table name.
string$fieldsA list of comma separated fields.
string$suffixA suffix for the object name.
Return values
stringObject's name.

Reimplemented in mssql_sql_generator.

◆ getRenameFieldExtraSQL()

sql_generator::getRenameFieldExtraSQL ( $xmldb_table,
$xmldb_field )
inherited

Returns the code (array of statements) needed to execute extra statements on field rename.

Parameters
xmldb_table$xmldb_tableThe xmldb_table object instance.
xmldb_field$xmldb_fieldThe xmldb_field object instance.
Return values
arrayArray of extra SQL statements to run with a field being renamed.

◆ getRenameFieldSQL()

mysql_sql_generator::getRenameFieldSQL ( $xmldb_table,
$xmldb_field,
$newname )

Given one correct xmldb_field and the new name, returns the SQL statements to rename it (inside one array).

Parameters
xmldb_table$xmldb_tableThe table related to $xmldb_field.
xmldb_field$xmldb_fieldThe instance of xmldb_field to get the renamed field from.
string$newnameThe new name to rename the field to.
Return values
arrayThe SQL statements for renaming the field.

Reimplemented from sql_generator.

◆ getRenameIndexSQL()

sql_generator::getRenameIndexSQL ( $xmldb_table,
$xmldb_index,
$newname )
inherited

Given one xmldb_table and one xmldb_index, return the SQL statements needed to rename the index in the table Experimental! Shouldn't be used at all!

Parameters
xmldb_table$xmldb_tableThe xmldb_table instance to rename the index on.
xmldb_index$xmldb_indexThe xmldb_index to rename.
string$newnameThe xmldb_index's new name.
Return values
arrayAn array of SQL statements to rename the index.

Reimplemented in sqlite_sql_generator.

◆ getRenameKeySQL()

sql_generator::getRenameKeySQL ( $xmldb_table,
$xmldb_key,
$newname )
inherited

Given one xmldb_table and one xmldb_key, return the SQL statements needed to rename the key in the table Experimental! Shouldn't be used at all!

Parameters
xmldb_table$xmldb_tableThe table related to $xmldb_key.
xmldb_key$xmldb_keyThe xmldb_key to rename.
string$newnameThe xmldb_key's new name.
Return values
arraySQL statement to rename the xmldb_key.

Reimplemented in sqlite_sql_generator.

◆ getRenameTableExtraSQL()

sql_generator::getRenameTableExtraSQL ( $xmldb_table,
$newname )
inherited

Returns the code (array of statements) needed to execute extra statements on table rename.

Parameters
xmldb_table$xmldb_tableThe xmldb_table object instance.
string$newnameThe new name for the table.
Return values
arrayArray of extra SQL statements to rename a table.

Reimplemented in mssql_sql_generator, oracle_sql_generator, and postgres_sql_generator.

◆ getRenameTableSQL()

sql_generator::getRenameTableSQL ( $xmldb_table,
$newname )
inherited

Given one correct xmldb_table and the new name, returns the SQL statements to rename it (inside one array).

Parameters
xmldb_table$xmldb_tableThe table to rename.
string$newnameThe new name to rename the table to.
Return values
arraySQL statement(s) to rename the table.

◆ getReservedWords()

static mysql_sql_generator::getReservedWords ( )
static

Returns an array of reserved words (lowercase) for this DB.

Return values
arrayAn array of database specific reserved words

Reimplemented from sql_generator.

◆ getResetSequenceSQL()

mysql_sql_generator::getResetSequenceSQL ( $table)

Reset a sequence to the id field of a table.

Parameters
xmldb_table | string$tablename of table or the table object.
Return values
arrayof sql statements

Reimplemented from sql_generator.

◆ getSequenceFromDB()

sql_generator::getSequenceFromDB ( $xmldb_table)
inherited

Returns the name (string) of the sequence used in the table for the autonumeric pk Only some DB have this implemented.

Parameters
xmldb_table$xmldb_tableThe xmldb_table instance.
Return values
boolReturns the sequence from the DB or false.

Reimplemented in oracle_sql_generator, and postgres_sql_generator.

◆ getTableName()

sql_generator::getTableName ( xmldb_table $xmldb_table,
$quoted = true )
inherited

Given one xmldb_table, this returns it's correct name, depending of all the parameterization.

eg: This appends $prefix to the table name.

See also
$prefix
Parameters
xmldb_table$xmldb_tableThe table whose name we want.
boolean$quotedTo specify if the name must be quoted (if reserved word, only!).
Return values
stringThe correct name of the table.

Reimplemented in mssql_sql_generator, and oracle_sql_generator.

◆ getTypeSQL()

mysql_sql_generator::getTypeSQL ( $xmldb_type,
$xmldb_length = null,
$xmldb_decimals = null )

Given one XMLDB Type, length and decimals, returns the DB proper SQL type.

Parameters
int$xmldb_typeThe xmldb_type defined constant. XMLDB_TYPE_INTEGER and other XMLDB_TYPE_* constants.
int$xmldb_lengthThe length of that data type.
int$xmldb_decimalsThe decimal places of precision of the data type.
Return values
stringThe DB defined data type.

Reimplemented from sql_generator.

◆ guess_antelope_row_size()

mysql_sql_generator::guess_antelope_row_size ( array $columns)

Calculate proximate row size when using InnoDB tables in Antelope row format.

Note: the returned value is a bit higher to compensate for errors and changes of column data types.

Parameters
xmldb_field[] | database_column_info[]$columns
Return values
intapproximate row size in bytes

◆ guess_antolope_row_size()

mysql_sql_generator::guess_antolope_row_size ( array $columns)

Calculate proximate row size when using InnoDB tables in Antelope row format.

Note: the returned value is a bit higher to compensate for errors and changes of column data types.

Deprecated
since Moodle 2.9 MDL-49723 - please do not use this function any more.

◆ isNameInUse()

mysql_sql_generator::isNameInUse ( $object_name,
$type,
$table_name )

Given one object name and it's type (pk, uk, fk, ck, ix, uix, seq, trg).

(MySQL requires the whole xmldb_table object to be specified, so we add it always)

This is invoked from getNameForObject(). Only some DB have this implemented.

Parameters
string$object_nameThe object's name to check for.
string$typeThe object's type (pk, uk, fk, ck, ix, uix, seq, trg).
string$table_nameThe table's name to check in
Return values
boolIf such name is currently in use (true) or no (false)

Reimplemented from sql_generator.

◆ table_exists()

sql_generator::table_exists ( $table)
inherited

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

Parameters
mixed$tableThe table to be searched (string name or xmldb_table instance).
Return values
booleantrue/false

Member Data Documentation

◆ $drop_foreign_key

string mysql_sql_generator::$drop_foreign_key = 'ALTER TABLE TABLENAME DROP FOREIGN KEY KEYNAME'

Template to drop FKs.

'TABLENAME' and 'KEYNAME' will be replaced from this template.

◆ $drop_primary_key

string mysql_sql_generator::$drop_primary_key = 'ALTER TABLE TABLENAME DROP PRIMARY KEY'

Template to drop PKs.

'TABLENAME' and 'KEYNAME' will be replaced from this template.

◆ $drop_unique_key

string mysql_sql_generator::$drop_unique_key = 'ALTER TABLE TABLENAME DROP KEY KEYNAME'

Template to drop UKs.

'TABLENAME' and 'KEYNAME' will be replaced from this template.

◆ $prefix_on_names

bool sql_generator::$prefix_on_names = true
inherited

True if the generator needs to prepend the prefix to all the key/index/sequence/trigger/check names.

See also
$prefix

◆ $sequence_only

bool sql_generator::$sequence_only = false
inherited

To avoid outputting the rest of the field specs, leaving only the name and the sequence_name returned.

See also
getFieldSQL()

◆ $specify_nulls

bool sql_generator::$specify_nulls = false
inherited

To force the generator if NULL clauses must be specified.

It shouldn't be necessary.


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