3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
11 // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
13 // This program is free software; you can redistribute it and/or modify //
14 // it under the terms of the GNU General Public License as published by //
15 // the Free Software Foundation; either version 2 of the License, or //
16 // (at your option) any later version. //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details: //
23 // http://www.gnu.org/copyleft/gpl.html //
25 ///////////////////////////////////////////////////////////////////////////
27 /// This class represent one XMLDB table
29 class XMLDBTable
extends XMLDBObject
{
36 * Creates one new XMLDBTable
38 function XMLDBTable($name) {
39 parent
::XMLDBObject($name);
40 $this->fields
= array();
41 $this->keys
= array();
42 $this->indexes
= array();
46 * Add one field to the table, allowing to specify the desired order
47 * If it's not specified, then the field is added at the end
49 function addField(&$field, $after=NULL) {
51 /// Calculate the previous and next fields
56 $allfields =& $this->getFields();
57 if (!empty($allfields)) {
59 $prevfield =& $allfields[key($allfields)];
62 $prevfield =& $this->getField($after);
64 if ($prevfield && $prevfield->getNext()) {
65 $nextfield =& $this->getField($prevfield->getNext());
68 /// Set current field previous and next attributes
70 $field->setPrevious($prevfield->getName());
71 $prevfield->setNext($field->getName());
74 $field->setNext($nextfield->getName());
75 $nextfield->setPrevious($field->getName());
77 /// Some more attributes
78 $field->setLoaded(true);
79 $field->setChanged(true);
81 $this->fields
[] = $field;
83 $this->orderFields($this->fields
);
84 /// Recalculate the hash
85 $this->calculateHash(true);
86 /// We have one new field, so the table has changed
87 $this->setChanged(true);
93 * Add one key to the table, allowing to specify the desired order
94 * If it's not specified, then the key is added at the end
96 function addKey(&$key, $after=NULL) {
98 /// Calculate the previous and next keys
103 $allkeys =& $this->getKeys();
104 if (!empty($allkeys)) {
106 $prevkey =& $allkeys[key($allkeys)];
109 $prevkey =& $this->getKey($after);
111 if ($prevkey && $prevkey->getNext()) {
112 $nextkey =& $this->getKey($prevkey->getNext());
115 /// Set current key previous and next attributes
117 $key->setPrevious($prevkey->getName());
118 $prevkey->setNext($key->getName());
121 $key->setNext($nextkey->getName());
122 $nextkey->setPrevious($key->getName());
124 /// Some more attributes
125 $key->setLoaded(true);
126 $key->setChanged(true);
128 $this->keys
[] = $key;
130 $this->orderKeys($this->keys
);
131 /// Recalculate the hash
132 $this->calculateHash(true);
133 /// We have one new field, so the table has changed
134 $this->setChanged(true);
138 * Add one index to the table, allowing to specify the desired order
139 * If it's not specified, then the index is added at the end
141 function addIndex(&$index, $after=NULL) {
143 /// Calculate the previous and next indexes
148 $allindexes =& $this->getIndexes();
149 if (!empty($allindexes)) {
151 $previndex =& $allindexes[key($allindexes)];
154 $previndex =& $this->getIndex($after);
156 if ($previndex && $previndex->getNext()) {
157 $nextindex =& $this->getIndex($previndex->getNext());
160 /// Set current index previous and next attributes
162 $index->setPrevious($previndex->getName());
163 $previndex->setNext($index->getName());
166 $index->setNext($nextindex->getName());
167 $nextindex->setPrevious($index->getName());
170 /// Some more attributes
171 $index->setLoaded(true);
172 $index->setChanged(true);
173 /// Add the new index
174 $this->indexes
[] = $index;
175 /// Reorder the indexes
176 $this->orderIndexes($this->indexes
);
177 /// Recalculate the hash
178 $this->calculateHash(true);
179 /// We have one new index, so the table has changed
180 $this->setChanged(true);
184 * This function will return the array of fields in the table
186 function &getFields() {
187 return $this->fields
;
191 * This function will return the array of keys in the table
193 function &getKeys() {
198 * This function will return the array of indexes in the table
200 function &getIndexes() {
201 return $this->indexes
;
205 * Returns one XMLDBField
207 function &getField($fieldname) {
208 $i = $this->findFieldInArray($fieldname);
210 return $this->fields
[$i];
217 * Returns the position of one field in the array.
219 function &findFieldInArray($fieldname) {
220 foreach ($this->fields
as $i => $field) {
221 if ($fieldname == $field->getName()) {
230 * This function will reorder the array of fields
232 function orderFields() {
233 $result = $this->orderElements($this->fields
);
235 $this->setFields($result);
243 * Returns one XMLDBKey
245 function &getKey($keyname) {
246 $i = $this->findKeyInArray($keyname);
248 return $this->keys
[$i];
255 * Returns the position of one key in the array.
257 function &findKeyInArray($keyname) {
258 foreach ($this->keys
as $i => $key) {
259 if ($keyname == $key->getName()) {
268 * This function will reorder the array of keys
270 function orderKeys() {
271 $result = $this->orderElements($this->keys
);
273 $this->setKeys($result);
281 * Returns one XMLDBIndex
283 function &getIndex($indexname) {
284 $i = $this->findIndexInArray($indexname);
286 return $this->indexes
[$i];
293 * Returns the position of one index in the array.
295 function &findIndexInArray($indexname) {
296 foreach ($this->indexes
as $i => $index) {
297 if ($indexname == $index->getName()) {
306 * This function will reorder the array of indexes
308 function orderIndexes() {
309 $result = $this->orderElements($this->indexes
);
311 $this->setIndexes($result);
319 * This function will set the array of fields in the table
321 function setFields($fields) {
322 $this->fields
= $fields;
326 * This function will set the array of keys in the table
328 function setKeys($keys) {
333 * This function will set the array of indexes in the table
335 function setIndexes($indexes) {
336 $this->indexes
= $indexes;
340 * Delete one field from the table
342 function deleteField($fieldname) {
344 $field =& $this->getField($fieldname);
346 $i = $this->findFieldInArray($fieldname);
349 /// Look for prev and next field
350 $prevfield =& $this->getField($field->getPrevious());
351 $nextfield =& $this->getField($field->getNext());
352 /// Change their previous and next attributes
354 $prevfield->setNext($field->getNext());
357 $nextfield->setPrevious($field->getPrevious());
360 unset($this->fields
[$i]);
361 /// Reorder the whole structure
362 $this->orderFields($this->fields
);
363 /// Recalculate the hash
364 $this->calculateHash(true);
365 /// We have one deleted field, so the table has changed
366 $this->setChanged(true);
371 * Delete one key from the table
373 function deleteKey($keyname) {
375 $key =& $this->getKey($keyname);
377 $i = $this->findKeyInArray($keyname);
380 /// Look for prev and next key
381 $prevkey =& $this->getKey($key->getPrevious());
382 $nextkey =& $this->getKey($key->getNext());
383 /// Change their previous and next attributes
385 $prevkey->setNext($key->getNext());
388 $nextkey->setPrevious($key->getPrevious());
391 unset($this->keys
[$i]);
393 $this->orderKeys($this->keys
);
394 /// Recalculate the hash
395 $this->calculateHash(true);
396 /// We have one deleted key, so the table has changed
397 $this->setChanged(true);
402 * Delete one index from the table
404 function deleteIndex($indexname) {
406 $index =& $this->getIndex($indexname);
408 $i = $this->findIndexInArray($indexname);
411 /// Look for prev and next index
412 $previndex =& $this->getIndex($index->getPrevious());
413 $nextindex =& $this->getIndex($index->getNext());
414 /// Change their previous and next attributes
416 $previndex->setNext($index->getNext());
419 $nextindex->setPrevious($index->getPrevious());
422 unset($this->indexes
[$i]);
423 /// Reorder the indexes
424 $this->orderIndexes($this->indexes
);
425 /// Recalculate the hash
426 $this->calculateHash(true);
427 /// We have one deleted index, so the table has changed
428 $this->setChanged(true);
433 * Load data from XML to the table
435 function arr2XMLDBTable($xmlarr) {
442 /// traverse_xmlize($xmlarr); //Debug
443 /// print_object ($GLOBALS['traverse_array']); //Debug
444 /// $GLOBALS['traverse_array']=""; //Debug
446 /// Process table attributes (name, comment, previoustable and nexttable)
447 if (isset($xmlarr['@']['NAME'])) {
448 $this->name
= trim($xmlarr['@']['NAME']);
450 $this->errormsg
= 'Missing NAME attribute';
451 $this->debug($this->errormsg
);
454 if (isset($xmlarr['@']['COMMENT'])) {
455 $this->comment
= trim($xmlarr['@']['COMMENT']);
456 } else if (!empty($CFG->xmldbdisablecommentchecking
)) {
459 $this->errormsg
= 'Missing COMMENT attribute';
460 $this->debug($this->errormsg
);
463 if (isset($xmlarr['@']['PREVIOUS'])) {
464 $this->previous
= trim($xmlarr['@']['PREVIOUS']);
466 if (isset($xmlarr['@']['NEXT'])) {
467 $this->next
= trim($xmlarr['@']['NEXT']);
470 /// Iterate over fields
471 if (isset($xmlarr['#']['FIELDS']['0']['#']['FIELD'])) {
472 foreach ($xmlarr['#']['FIELDS']['0']['#']['FIELD'] as $xmlfield) {
473 if (!$result) { //Skip on error
476 $name = trim($xmlfield['@']['NAME']);
477 $field = new XMLDBField($name);
478 $field->arr2XMLDBField($xmlfield);
479 $this->fields
[] = $field;
480 if (!$field->isLoaded()) {
481 $this->errormsg
= 'Problem loading field ' . $name;
482 $this->debug($this->errormsg
);
487 $this->errormsg
= 'Missing FIELDS section';
488 $this->debug($this->errormsg
);
492 /// Perform some general checks over fields
493 if ($result && $this->fields
) {
494 /// Check field names are ok (lowercase, a-z _-)
495 if (!$this->checkNameValues($this->fields
)) {
496 $this->errormsg
= 'Some FIELDS name values are incorrect';
497 $this->debug($this->errormsg
);
500 /// Check previous & next are ok (duplicates and existing fields)
501 $this->fixPrevNext($this->fields
);
502 if ($result && !$this->checkPreviousNextValues($this->fields
)) {
503 $this->errormsg
= 'Some FIELDS previous/next values are incorrect';
504 $this->debug($this->errormsg
);
508 if ($result && !$this->orderFields($this->fields
)) {
509 $this->errormsg
= 'Error ordering the fields';
510 $this->debug($this->errormsg
);
515 /// Iterate over keys
516 if (isset($xmlarr['#']['KEYS']['0']['#']['KEY'])) {
517 foreach ($xmlarr['#']['KEYS']['0']['#']['KEY'] as $xmlkey) {
518 if (!$result) { //Skip on error
521 $name = trim($xmlkey['@']['NAME']);
522 $key = new XMLDBKey($name);
523 $key->arr2XMLDBKey($xmlkey);
524 $this->keys
[] = $key;
525 if (!$key->isLoaded()) {
526 $this->errormsg
= 'Problem loading key ' . $name;
527 $this->debug($this->errormsg
);
532 $this->errormsg
= 'Missing KEYS section (at least one PK must exist)';
533 $this->debug($this->errormsg
);
537 /// Perform some general checks over keys
538 if ($result && $this->keys
) {
539 /// Check keys names are ok (lowercase, a-z _-)
540 if (!$this->checkNameValues($this->keys
)) {
541 $this->errormsg
= 'Some KEYS name values are incorrect';
542 $this->debug($this->errormsg
);
545 /// Check previous & next are ok (duplicates and existing keys)
546 $this->fixPrevNext($this->keys
);
547 if ($result && !$this->checkPreviousNextValues($this->keys
)) {
548 $this->errormsg
= 'Some KEYS previous/next values are incorrect';
549 $this->debug($this->errormsg
);
553 if ($result && !$this->orderKeys($this->keys
)) {
554 $this->errormsg
= 'Error ordering the keys';
555 $this->debug($this->errormsg
);
558 /// TODO: Only one PK
559 /// TODO: Not keys with repeated fields
560 /// TODO: Check fields and reffieds exist in table
563 /// Iterate over indexes
564 if (isset($xmlarr['#']['INDEXES']['0']['#']['INDEX'])) {
565 foreach ($xmlarr['#']['INDEXES']['0']['#']['INDEX'] as $xmlindex) {
566 if (!$result) { //Skip on error
569 $name = trim($xmlindex['@']['NAME']);
570 $index = new XMLDBIndex($name);
571 $index->arr2XMLDBIndex($xmlindex);
572 $this->indexes
[] = $index;
573 if (!$index->isLoaded()) {
574 $this->errormsg
= 'Problem loading index ' . $name;
575 $this->debug($this->errormsg
);
581 /// Perform some general checks over indexes
582 if ($result && $this->indexes
) {
583 /// Check field names are ok (lowercase, a-z _-)
584 if (!$this->checkNameValues($this->indexes
)) {
585 $this->errormsg
= 'Some INDEXES name values are incorrect';
586 $this->debug($this->errormsg
);
589 /// Check previous & next are ok (duplicates and existing INDEXES)
590 $this->fixPrevNext($this->indexes
);
591 if ($result && !$this->checkPreviousNextValues($this->indexes
)) {
592 $this->errormsg
= 'Some INDEXES previous/next values are incorrect';
593 $this->debug($this->errormsg
);
597 if ($result && !$this->orderIndexes($this->indexes
)) {
598 $this->errormsg
= 'Error ordering the indexes';
599 $this->debug($this->errormsg
);
602 /// TODO: Not indexes with repeated fields
603 /// TODO: Check fields exist in table
606 /// Set some attributes
608 $this->loaded
= true;
610 $this->calculateHash();
615 * This function calculate and set the hash of one XMLDBTable
617 function calculateHash($recursive = false) {
618 if (!$this->loaded
) {
621 $key = $this->name
. $this->comment
;
623 foreach ($this->fields
as $fie) {
624 $field =& $this->getField($fie->getName());
626 $field->calculateHash($recursive);
628 $key .= $field->getHash();
632 foreach ($this->keys
as $ke) {
633 $k =& $this->getKey($ke->getName());
635 $k->calculateHash($recursive);
637 $key .= $k->getHash();
640 if ($this->indexes
) {
641 foreach ($this->indexes
as $in) {
642 $index =& $this->getIndex($in->getName());
644 $index->calculateHash($recursive);
646 $key .= $index->getHash();
649 $this->hash
= md5($key);
654 * This function will output the XML text for one table
656 function xmlOutput() {
658 $o.= ' <TABLE NAME="' . $this->name
. '"';
659 if ($this->comment
) {
660 $o.= ' COMMENT="' . htmlspecialchars($this->comment
) . '"';
662 if ($this->previous
) {
663 $o.= ' PREVIOUS="' . $this->previous
. '"';
666 $o.= ' NEXT="' . $this->next
. '"';
671 $o.= ' <FIELDS>' . "\n";
672 foreach ($this->fields
as $field) {
673 $o.= $field->xmlOutput();
675 $o.= ' </FIELDS>' . "\n";
679 $o.= ' <KEYS>' . "\n";
680 foreach ($this->keys
as $key) {
681 $o.= $key->xmlOutput();
683 $o.= ' </KEYS>' . "\n";
686 if ($this->indexes
) {
687 $o.= ' <INDEXES>' . "\n";
688 foreach ($this->indexes
as $index) {
689 $o.= $index->xmlOutput();
691 $o.= ' </INDEXES>' . "\n";
693 $o.= ' </TABLE>' . "\n";
699 * This function will add one new field to the table with all
700 * its attributes defined
702 * @param string name name of the field
703 * @param string type XMLDB_TYPE_INTEGER, XMLDB_TYPE_NUMBER, XMLDB_TYPE_CHAR, XMLDB_TYPE_TEXT, XMLDB_TYPE_BINARY
704 * @param string precision length for integers and chars, two-comma separated numbers for numbers and 'small', 'medium', 'big' for texts and binaries
705 * @param string unsigned XMLDB_UNSIGNED or null (or false)
706 * @param string notnull XMLDB_NOTNULL or null (or false)
707 * @param string sequence XMLDB_SEQUENCE or null (or false)
708 * @param string enum XMLDB_ENUM or null (or false)
709 * @param array enumvalues an array of possible values if XMLDB_ENUM is set
710 * @param string default meaningful default o null (or false)
711 * @param string previous name of the previous field in the table or null (or false)
713 function addFieldInfo($name, $type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $enum=null, $enumvalues=null, $default=null, $previous=null) {
714 $field = new XMLDBField($name);
715 $field->setAttributes($type, $precision, $unsigned, $notnull, $sequence, $enum, $enumvalues, $default);
716 $this->addField($field, $previous);
722 * This function will add one new key to the table with all
723 * its attributes defined
725 * @param string name name of the key
726 * @param string type XMLDB_KEY_PRIMARY, XMLDB_KEY_UNIQUE, XMLDB_KEY_FOREIGN
727 * @param array fields an array of fieldnames to build the key over
728 * @param string reftable name of the table the FK points to or null
729 * @param array reffields an array of fieldnames in the FK table or null
731 function addKeyInfo($name, $type, $fields, $reftable=null, $reffields=null) {
732 $key = new XMLDBKey($name);
733 $key->setAttributes($type, $fields, $reftable, $reffields);
738 * This function will add one new index to the table with all
739 * its attributes defined
741 * @param string name name of the index
742 * @param string type XMLDB_INDEX_UNIQUE, XMLDB_INDEX_NOTUNIQUE
743 * @param array fields an array of fieldnames to build the index over
745 function addIndexInfo($name, $type, $fields) {
746 $index = new XMLDBIndex($name);
747 $index->setAttributes($type, $fields);
748 $this->addIndex($index);
752 * This function will return all the errors found in one table
753 * looking recursively inside each field/key/index. Returns
754 * an array of errors or false
756 function getAllErrors() {
759 /// First the table itself
760 if ($this->getError()) {
761 $errors[] = $this->getError();
763 /// Delegate to fields
764 if ($fields = $this->getFields()) {
765 foreach ($fields as $field) {
766 if ($field->getError()) {
767 $errors[] = $field->getError();
772 if ($keys = $this->getKeys()) {
773 foreach ($keys as $key) {
774 if ($key->getError()) {
775 $errors[] = $key->getError();
779 /// Delegate to indexes
780 if ($indexes = $this->getIndexes()) {
781 foreach ($indexes as $index) {
782 if ($index->getError()) {
783 $errors[] = $index->getError();
788 if (count($errors)) {
796 * This function will return the SQL code needed to create the table for the specified DB and
797 * prefix. Just one simple wrapper over generators.
799 function getCreateTableSQL ($dbtype, $prefix, $statement_end=true) {
803 $classname = 'XMLDB' . $dbtype;
804 $generator = new $classname();
805 $generator->setPrefix($prefix);
806 $results = $generator->getCreateTableSQL($this);
807 if ($statement_end) {
808 $results = $generator->getEndedStatements($results);
814 * This function will return the SQL code needed to create the table for the specified DB and
815 * prefix. Just one simple wrapper over generators.
817 function getRenameTableSQL ($dbtype, $prefix, $newname, $statement_end=true) {
821 $classname = 'XMLDB' . $dbtype;
822 $generator = new $classname();
823 $generator->setPrefix($prefix);
824 $results = $generator->getRenameTableSQL($this, $newname);
825 if ($statement_end) {
826 $results = $generator->getEndedStatements($results);
832 * This function will return the SQL code needed to drop the table for the specified DB and
833 * prefix. Just one simple wrapper over generators.
835 function getDropTableSQL ($dbtype, $prefix, $statement_end=true) {
839 $classname = 'XMLDB' . $dbtype;
840 $generator = new $classname();
841 $generator->setPrefix($prefix);
842 $results = $generator->getDropTableSQL($this);
843 if ($statement_end) {
844 $results = $generator->getEndedStatements($results);
850 * This function will return the SQL code needed to add one field to the table for the specified DB and
851 * prefix. Just one simple wrapper over generators.
853 function getAddFieldSQL ($dbtype, $prefix, $xmldb_field, $statement_end=true) {
857 $classname = 'XMLDB' . $dbtype;
858 $generator = new $classname();
859 $generator->setPrefix($prefix);
860 $results = $generator->getAddFieldSQL($this, $xmldb_field);
861 if ($statement_end) {
862 $results = $generator->getEndedStatements($results);
868 * This function will return the SQL code needed to drop one field from the table for the specified DB and
869 * prefix. Just one simple wrapper over generators.
871 function getDropFieldSQL ($dbtype, $prefix, $xmldb_field, $statement_end=true) {
875 $classname = 'XMLDB' . $dbtype;
876 $generator = new $classname();
877 $generator->setPrefix($prefix);
878 $results = $generator->getDropFieldSQL($this, $xmldb_field);
879 if ($statement_end) {
880 $results = $generator->getEndedStatements($results);
886 * This function will return the SQL code needed to rename one field from the table for the specified DB and
887 * prefix. Just one simple wrapper over generators.
889 function getRenameFieldSQL ($dbtype, $prefix, $xmldb_field, $newname, $statement_end=true) {
893 $classname = 'XMLDB' . $dbtype;
894 $generator = new $classname();
895 $generator->setPrefix($prefix);
896 $results = $generator->getRenameFieldSQL($this, $xmldb_field, $newname);
897 if ($statement_end) {
898 $results = $generator->getEndedStatements($results);
904 * This function will return the SQL code needed to alter one field in the table for the specified DB and
905 * prefix. Just one simple wrapper over generators.
907 function getAlterFieldSQL ($dbtype, $prefix, $xmldb_field, $statement_end=true) {
911 $classname = 'XMLDB' . $dbtype;
912 $generator = new $classname();
913 $generator->setPrefix($prefix);
914 $results = $generator->getAlterFieldSQL($this, $xmldb_field);
915 if ($statement_end) {
916 $results = $generator->getEndedStatements($results);
922 * This function will return the SQL code needed to modify the enum of one field in the table for the specified DB and
923 * prefix. Just one simple wrapper over generators.
925 function getModifyEnumSQL ($dbtype, $prefix, $xmldb_field, $statement_end=true) {
929 $classname = 'XMLDB' . $dbtype;
930 $generator = new $classname();
931 $generator->setPrefix($prefix);
932 $results = $generator->getModifyEnumSQL($this, $xmldb_field);
933 if ($statement_end) {
934 $results = $generator->getEndedStatements($results);
940 * This function will return the SQL code needed to modify the default of one field in the table for the specified DB and
941 * prefix. Just one simple wrapper over generators.
943 function getModifyDefaultSQL ($dbtype, $prefix, $xmldb_field, $statement_end=true) {
947 $classname = 'XMLDB' . $dbtype;
948 $generator = new $classname();
949 $generator->setPrefix($prefix);
950 $results = $generator->getModifyDefaultSQL($this, $xmldb_field);
951 if ($statement_end) {
952 $results = $generator->getEndedStatements($results);
958 * This function will return the SQL code needed to add one key to the table for the specified DB and
959 * prefix. Just one simple wrapper over generators.
961 function getAddKeySQL ($dbtype, $prefix, $xmldb_key, $statement_end=true) {
965 $classname = 'XMLDB' . $dbtype;
966 $generator = new $classname();
967 $generator->setPrefix($prefix);
968 $results = $generator->getAddKeySQL($this, $xmldb_key);
969 if ($statement_end) {
970 $results = $generator->getEndedStatements($results);
976 * This function will return the SQL code needed to drop one key from the table for the specified DB and
977 * prefix. Just one simple wrapper over generators.
979 function getDropKeySQL ($dbtype, $prefix, $xmldb_key, $statement_end=true) {
983 $classname = 'XMLDB' . $dbtype;
984 $generator = new $classname();
985 $generator->setPrefix($prefix);
986 $results = $generator->getDropKeySQL($this, $xmldb_key);
987 if ($statement_end) {
988 $results = $generator->getEndedStatements($results);
994 * This function will return the SQL code needed to rename one key from the table for the specified DB and
995 * prefix. Just one simple wrapper over generators.
997 function getRenameKeySQL ($dbtype, $prefix, $xmldb_key, $newname, $statement_end=true) {
1001 $classname = 'XMLDB' . $dbtype;
1002 $generator = new $classname();
1003 $generator->setPrefix($prefix);
1004 $results = $generator->getRenameKeySQL($this, $xmldb_key, $newname);
1005 if ($statement_end) {
1006 $results = $generator->getEndedStatements($results);
1012 * This function will return the SQL code needed to add one index to the table for the specified DB and
1013 * prefix. Just one simple wrapper over generators.
1015 function getAddIndexSQL ($dbtype, $prefix, $xmldb_index, $statement_end=true) {
1019 $classname = 'XMLDB' . $dbtype;
1020 $generator = new $classname();
1021 $generator->setPrefix($prefix);
1022 $results = $generator->getAddIndexSQL($this, $xmldb_index);
1023 if ($statement_end) {
1024 $results = $generator->getEndedStatements($results);
1030 * This function will return the SQL code needed to drop one index from the table for the specified DB and
1031 * prefix. Just one simple wrapper over generators.
1033 function getDropIndexSQL ($dbtype, $prefix, $xmldb_index, $statement_end=true) {
1037 $classname = 'XMLDB' . $dbtype;
1038 $generator = new $classname();
1039 $generator->setPrefix($prefix);
1040 $results = $generator->getDropIndexSQL($this, $xmldb_index);
1041 if ($statement_end) {
1042 $results = $generator->getEndedStatements($results);
1048 * This function will return the SQL code needed to rename one index from the table for the specified DB and
1049 * prefix. Just one simple wrapper over generators.
1050 * Experimental. Shouldn't be used at all!
1052 function getRenameIndexSQL ($dbtype, $prefix, $xmldb_index, $newname, $statement_end=true) {
1056 $classname = 'XMLDB' . $dbtype;
1057 $generator = new $classname();
1058 $generator->setPrefix($prefix);
1059 $results = $generator->getRenameIndexSQL($this, $xmldb_index, $newname);
1060 if ($statement_end) {
1061 $results = $generator->getEndedStatements($results);
1067 * This function will return the name of the sequence created for the pk of the table specified
1068 * Just one simple wrapper over generators. Returns false if not found
1069 * Note that not all DB use sequences (only Oracle and PostgreSQL)
1071 function getSequenceFromDB($dbtype, $prefix) {
1073 $classname = 'XMLDB' . $dbtype;
1074 $generator = new $classname();
1075 $generator->setPrefix($prefix);
1076 return $generator->getSequenceFromDB($this);