Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
xmldb_table Class Reference
Inheritance diagram for xmldb_table:
xmldb_object

Public Member Functions

 __construct ($name)
 Creates one new xmldb_table.
 
 add_field ($name, $type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $default=null, $previous=null)
 This function will add one new field to the table with all its attributes defined.
 
 add_index ($name, $type, $fields, $hints=array())
 This function will add one new index to the table with all its attributes defined.
 
 add_key ($name, $type, $fields, $reftable=null, $reffields=null)
 This function will add one new key to the table with all its attributes defined.
 
 addField ($field, $after=null)
 Add one field to the table, allowing to specify the desired order If it's not specified, then the field is added at the end.
 
 addIndex ($index, $after=null)
 Add one index to the table, allowing to specify the desired order If it's not specified, then the index is added at the end.
 
 addKey ($key, $after=null)
 Add one key to the table, allowing to specify the desired order If it's not specified, then the key is added at the end.
 
 arr2xmldb_table ($xmlarr)
 Load data from XML to the table.
 
 calculateHash ($recursive=false)
 This function calculate and set the hash of one xmldb_table.
 
 checkName ()
 This function will check if one key name is ok or no (true/false) only lowercase a-z, 0-9 and _ are allowed.
 
 checkNameValues ($arr)
 This function will check that all the elements in one array have a correct name [a-z0-9_].
 
 comma2array ($string)
 Returns one array of elements from one comma separated string, supporting quoted strings containing commas and concat function calls.
 
 debug ($message)
 This function will perform the central debug of all the XMLDB classes being called automatically every time one error is found.
 
 deleteField ($fieldname)
 Delete one field from the table.
 
 deleteIndex ($indexname)
 Delete one index from the table.
 
 deleteKey ($keyname)
 Delete one key from the table.
 
 findFieldInArray ($fieldname)
 Returns the position of one field in the array.
 
 findIndexInArray ($indexname)
 Returns the position of one index in the array.
 
 findKeyInArray ($keyname)
 Returns the position of one key in the array.
 
 findObjectInArray ($objectname, $arr)
 Returns the position of one object in the array.
 
 fixPrevNext (&$arr)
 Reconstruct previous/next attributes.
 
 getAllErrors ()
 This function will return all the errors found in one table looking recursively inside each field/key/index.
 
 getComment ()
 This function returns the comment of one xmldb_object.
 
 getError ()
 This function will return the error detected in the object.
 
 getField ($fieldname)
 Returns one xmldb_field.
 
 getFields ()
 This function will return the array of fields in the table.
 
 getHash ()
 This function returns the hash of one xmldb_object.
 
 getIndex ($indexname)
 Returns one xmldb_index.
 
 getIndexes ()
 This function will return the array of indexes in the table.
 
 getKey ($keyname)
 Returns one xmldb_key.
 
 getKeys ()
 This function will return the array of keys in the table.
 
 getName ()
 This function will return the name of the xmldb_object.
 
 getNext ()
 This function will return the name of the next xmldb_object.
 
 getPrevious ()
 This function will return the name of the previous xmldb_object.
 
 hasChanged ()
 This function returns true/false, if the xmldb_object has changed.
 
 isLoaded ()
 This function returns true/false, if the xmldb_object has been loaded.
 
 orderElements ($arr)
 This function will order all the elements in one array, following the previous/next rules.
 
 orderFields ()
 This function will reorder the array of fields.
 
 orderIndexes ()
 This function will reorder the array of indexes.
 
 orderKeys ()
 This function will reorder the array of keys.
 
 readableInfo ()
 This function will display a readable info about the xmldb_object (should be implemented inside each XMLDBxxx object)
 
 setChanged ($changed=true)
 This function will set the changed field of the xmldb_object.
 
 setComment ($comment)
 This function will set the comment of the xmldb_object.
 
 setFields ($fields)
 This function will set the array of fields in the table.
 
 setHash ($hash)
 This function will set the hash of the xmldb_object.
 
 setIndexes ($indexes)
 This function will set the array of indexes in the table.
 
 setKeys ($keys)
 This function will set the array of keys in the table.
 
 setLoaded ($loaded=true)
 This function will set the loaded field of the xmldb_object.
 
 setName ($name)
 This function will set the name field of the xmldb_object.
 
 setNext ($next)
 This function will set the next of the xmldb_object.
 
 setPrevious ($previous)
 This function will set the previous of the xmldb_object.
 
 validateDefinition (xmldb_table $xmldb_table=null)
 Validates the table restrictions (does not validate child elements).
 
 xmlOutput ()
 This function will output the XML text for one table.
 

Public Attributes

int const NAME_MAX_LENGTH = 63 - self::PREFIX_MAX_LENGTH
 Note:
 
int const PREFIX_MAX_LENGTH = 10
 max length of table name prefixes
 

Protected Attributes

bool $changed
 was object changed
 
string $comment
 comment on object
 
string $errormsg
 error message
 
xmldb_field[] $fields
 table columns
 
string $hash
 hash of object
 
xmldb_index[] $indexes
 indexes
 
xmldb_key[] $keys
 keys
 
bool $loaded
 is it loaded yet
 
string $name
 name of obejct
 
string $next
 
string $previous
 

Constructor & Destructor Documentation

◆ __construct()

xmldb_table::__construct ( $name)

Creates one new xmldb_table.

Parameters
string$name

Reimplemented from xmldb_object.

Member Function Documentation

◆ add_field()

xmldb_table::add_field ( $name,
$type,
$precision = null,
$unsigned = null,
$notnull = null,
$sequence = null,
$default = null,
$previous = null )

This function will add one new field to the table with all its attributes defined.

Parameters
string$namename of the field
int$typeXMLDB_TYPE_INTEGER, XMLDB_TYPE_NUMBER, XMLDB_TYPE_CHAR, XMLDB_TYPE_TEXT, XMLDB_TYPE_BINARY
string$precisionlength for integers and chars, two-comma separated numbers for numbers
bool$unsignedXMLDB_UNSIGNED or null (or false)
bool$notnullXMLDB_NOTNULL or null (or false)
bool$sequenceXMLDB_SEQUENCE or null (or false)
mixed$defaultmeaningful default o null (or false)
xmldb_object$previousname of the previous field in the table or null (or false)
Return values
xmlddb_field

◆ add_index()

xmldb_table::add_index ( $name,
$type,
$fields,
$hints = array() )

This function will add one new index to the table with all its attributes defined.

Parameters
string$namename of the index
int$typeXMLDB_INDEX_UNIQUE, XMLDB_INDEX_NOTUNIQUE
array$fieldsan array of fieldnames to build the index over
array$hintsoptional index type hints

◆ add_key()

xmldb_table::add_key ( $name,
$type,
$fields,
$reftable = null,
$reffields = null )

This function will add one new key to the table with all its attributes defined.

Parameters
string$namename of the key
int$typeXMLDB_KEY_PRIMARY, XMLDB_KEY_UNIQUE, XMLDB_KEY_FOREIGN
array$fieldsan array of fieldnames to build the key over
string$reftablename of the table the FK points to or null
array$reffieldsan array of fieldnames in the FK table or null

◆ addField()

xmldb_table::addField ( $field,
$after = null )

Add one field to the table, allowing to specify the desired order If it's not specified, then the field is added at the end.

Parameters
xmldb_field$field
xmldb_object$after
Return values
xmldb_field

◆ addIndex()

xmldb_table::addIndex ( $index,
$after = null )

Add one index to the table, allowing to specify the desired order If it's not specified, then the index is added at the end.

Parameters
xmldb_index$index
xmldb_object$after

◆ addKey()

xmldb_table::addKey ( $key,
$after = null )

Add one key to the table, allowing to specify the desired order If it's not specified, then the key is added at the end.

Parameters
xmldb_key$key
xmldb_object$after

◆ arr2xmldb_table()

xmldb_table::arr2xmldb_table ( $xmlarr)

Load data from XML to the table.

Parameters
array$xmlarr
Return values
boolsuccess

◆ calculateHash()

xmldb_table::calculateHash ( $recursive = false)

This function calculate and set the hash of one xmldb_table.

Parameters
bool$recursive

◆ checkName()

xmldb_object::checkName ( )
inherited

This function will check if one key name is ok or no (true/false) only lowercase a-z, 0-9 and _ are allowed.

Return values
bool

◆ checkNameValues()

xmldb_object::checkNameValues ( $arr)
inherited

This function will check that all the elements in one array have a correct name [a-z0-9_].

Parameters
array$arr
Return values
bool

◆ comma2array()

xmldb_object::comma2array ( $string)
inherited

Returns one array of elements from one comma separated string, supporting quoted strings containing commas and concat function calls.

Parameters
string$string
Return values
array

◆ debug()

xmldb_object::debug ( $message)
inherited

This function will perform the central debug of all the XMLDB classes being called automatically every time one error is found.

Apart from the main actions performed in it (XMLDB agnostic) it looks for one function called xmldb_debug() and invokes it, passing both the message code and the whole object. So, to perform custom debugging just add such function to your libs.

Call to the external hook function can be disabled by request by defining XMLDB_SKIP_DEBUG_HOOK

Parameters
string$message

◆ deleteField()

xmldb_table::deleteField ( $fieldname)

Delete one field from the table.

Parameters
string$fieldname

◆ deleteIndex()

xmldb_table::deleteIndex ( $indexname)

Delete one index from the table.

Parameters
string$indexname

◆ deleteKey()

xmldb_table::deleteKey ( $keyname)

Delete one key from the table.

Parameters
string$keyname

◆ findFieldInArray()

xmldb_table::findFieldInArray ( $fieldname)

Returns the position of one field in the array.

Parameters
string$fieldname
Return values
int|nullindex of the field, or null if not found.

◆ findIndexInArray()

xmldb_table::findIndexInArray ( $indexname)

Returns the position of one index in the array.

Parameters
string$indexname
Return values
int|nullindex of the index, or null if not found.

◆ findKeyInArray()

xmldb_table::findKeyInArray ( $keyname)

Returns the position of one key in the array.

Parameters
string$keyname
Return values
int|nullindex of the key, or null if not found.

◆ findObjectInArray()

xmldb_object::findObjectInArray ( $objectname,
$arr )
inherited

Returns the position of one object in the array.

Parameters
string$objectname
array$arr
Return values
mixed

◆ fixPrevNext()

xmldb_object::fixPrevNext ( & $arr)
inherited

Reconstruct previous/next attributes.

Parameters
array$arr
Return values
booltrue if $arr modified

◆ getAllErrors()

xmldb_table::getAllErrors ( )

This function will return all the errors found in one table looking recursively inside each field/key/index.

Returns an array of errors or false

◆ getComment()

xmldb_object::getComment ( )
inherited

This function returns the comment of one xmldb_object.

Return values
string

◆ getError()

xmldb_object::getError ( )
inherited

This function will return the error detected in the object.

Return values
string

◆ getField()

xmldb_table::getField ( $fieldname)

Returns one xmldb_field.

Parameters
string$fieldname
Return values
xmldb_field|null

◆ getFields()

xmldb_table::getFields ( )

This function will return the array of fields in the table.

Return values
xmldb_field[]

◆ getHash()

xmldb_object::getHash ( )
inherited

This function returns the hash of one xmldb_object.

Return values
string

◆ getIndex()

xmldb_table::getIndex ( $indexname)

Returns one xmldb_index.

Parameters
string$indexname
Return values
xmldb_index|null

◆ getIndexes()

xmldb_table::getIndexes ( )

This function will return the array of indexes in the table.

Return values
xmldb_index[]

◆ getKey()

xmldb_table::getKey ( $keyname)

Returns one xmldb_key.

Parameters
string$keyname
Return values
xmldb_key|null

◆ getKeys()

xmldb_table::getKeys ( )

This function will return the array of keys in the table.

Return values
xmldb_key[]

◆ getName()

xmldb_object::getName ( )
inherited

This function will return the name of the xmldb_object.

Return values
string

◆ getNext()

xmldb_object::getNext ( )
inherited

This function will return the name of the next xmldb_object.

Return values
string

◆ getPrevious()

xmldb_object::getPrevious ( )
inherited

This function will return the name of the previous xmldb_object.

Return values
string

◆ hasChanged()

xmldb_object::hasChanged ( )
inherited

This function returns true/false, if the xmldb_object has changed.

Return values
bool

◆ isLoaded()

xmldb_object::isLoaded ( )
inherited

This function returns true/false, if the xmldb_object has been loaded.

Return values
bool

◆ orderElements()

xmldb_object::orderElements ( $arr)
inherited

This function will order all the elements in one array, following the previous/next rules.

Parameters
array$arr
Return values
array|bool

◆ orderFields()

xmldb_table::orderFields ( )

This function will reorder the array of fields.

Return values
boolwhether the reordering succeeded.

◆ orderIndexes()

xmldb_table::orderIndexes ( )

This function will reorder the array of indexes.

Return values
boolwhether the reordering succeeded.

◆ orderKeys()

xmldb_table::orderKeys ( )

This function will reorder the array of keys.

Return values
boolwhether the reordering succeeded.

◆ readableInfo()

xmldb_object::readableInfo ( )
inherited

This function will display a readable info about the xmldb_object (should be implemented inside each XMLDBxxx object)

Return values
string

Reimplemented in xmldb_field, xmldb_index, and xmldb_key.

◆ setChanged()

xmldb_object::setChanged ( $changed = true)
inherited

This function will set the changed field of the xmldb_object.

Parameters
bool$changed

◆ setComment()

xmldb_object::setComment ( $comment)
inherited

This function will set the comment of the xmldb_object.

Parameters
string$comment

◆ setFields()

xmldb_table::setFields ( $fields)

This function will set the array of fields in the table.

Parameters
xmldb_field[]$fields

◆ setHash()

xmldb_object::setHash ( $hash)
inherited

This function will set the hash of the xmldb_object.

Parameters
string$hash

◆ setIndexes()

xmldb_table::setIndexes ( $indexes)

This function will set the array of indexes in the table.

Parameters
xmldb_index[]$indexes

◆ setKeys()

xmldb_table::setKeys ( $keys)

This function will set the array of keys in the table.

Parameters
xmldb_key[]$keys

◆ setLoaded()

xmldb_object::setLoaded ( $loaded = true)
inherited

This function will set the loaded field of the xmldb_object.

Parameters
bool$loaded

◆ setName()

xmldb_object::setName ( $name)
inherited

This function will set the name field of the xmldb_object.

Parameters
string$name

◆ setNext()

xmldb_object::setNext ( $next)
inherited

This function will set the next of the xmldb_object.

Parameters
string$next

◆ setPrevious()

xmldb_object::setPrevious ( $previous)
inherited

This function will set the previous of the xmldb_object.

Parameters
string$previous

◆ validateDefinition()

xmldb_table::validateDefinition ( xmldb_table $xmldb_table = null)

Validates the table restrictions (does not validate child elements).

The error message should not be localised because it is intended for developers, end users and admins should never see these problems!

Parameters
xmldb_table$xmldb_tableoptional when object is table
Return values
stringnull if ok, error message if problem found

Reimplemented from xmldb_object.

◆ xmlOutput()

xmldb_table::xmlOutput ( )

This function will output the XML text for one table.

Return values
string

Member Data Documentation

◆ NAME_MAX_LENGTH

int const xmldb_table::NAME_MAX_LENGTH = 63 - self::PREFIX_MAX_LENGTH

Note:

  • PostgreSQL has a limit of 63 ascii chars (bytes) for table names. Others have greater limits. Up to PREFIX_MAX_LENGTH ascii chars (bytes) are reserved for table prefixes.

max length of table names (without prefix).


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