Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / lib / xmldb / classes / XMLDBTable.class.php
bloba65f7641ccbe3b522765b57c31667795df8ed194
1 <?php // $Id$
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
9 // //
10 // Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
11 // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
12 // //
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. //
17 // //
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: //
22 // //
23 // http://www.gnu.org/copyleft/gpl.html //
24 // //
25 ///////////////////////////////////////////////////////////////////////////
27 /// This class represent one XMLDB table
29 class XMLDBTable extends XMLDBObject {
31 var $fields;
32 var $keys;
33 var $indexes;
35 /**
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();
45 /**
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
52 $prevfield = NULL;
53 $nextfield = NULL;
55 if (!$after) {
56 $allfields =& $this->getFields();
57 if (!empty($allfields)) {
58 end($allfields);
59 $prevfield =& $allfields[key($allfields)];
61 } else {
62 $prevfield =& $this->getField($after);
64 if ($prevfield && $prevfield->getNext()) {
65 $nextfield =& $this->getField($prevfield->getNext());
68 /// Set current field previous and next attributes
69 if ($prevfield) {
70 $field->setPrevious($prevfield->getName());
71 $prevfield->setNext($field->getName());
73 if ($nextfield) {
74 $field->setNext($nextfield->getName());
75 $nextfield->setPrevious($field->getName());
77 /// Some more attributes
78 $field->setLoaded(true);
79 $field->setChanged(true);
80 /// Add the new field
81 $this->fields[] = $field;
82 /// Reorder the 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);
89 return $field;
92 /**
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
99 $prevkey = NULL;
100 $nextkey = NULL;
102 if (!$after) {
103 $allkeys =& $this->getKeys();
104 if (!empty($allkeys)) {
105 end($allkeys);
106 $prevkey =& $allkeys[key($allkeys)];
108 } else {
109 $prevkey =& $this->getKey($after);
111 if ($prevkey && $prevkey->getNext()) {
112 $nextkey =& $this->getKey($prevkey->getNext());
115 /// Set current key previous and next attributes
116 if ($prevkey) {
117 $key->setPrevious($prevkey->getName());
118 $prevkey->setNext($key->getName());
120 if ($nextkey) {
121 $key->setNext($nextkey->getName());
122 $nextkey->setPrevious($key->getName());
124 /// Some more attributes
125 $key->setLoaded(true);
126 $key->setChanged(true);
127 /// Add the new key
128 $this->keys[] = $key;
129 /// Reorder the keys
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
144 $previndex = NULL;
145 $nextindex = NULL;
147 if (!$after) {
148 $allindexes =& $this->getIndexes();
149 if (!empty($allindexes)) {
150 end($allindexes);
151 $previndex =& $allindexes[key($allindexes)];
153 } else {
154 $previndex =& $this->getIndex($after);
156 if ($previndex && $previndex->getNext()) {
157 $nextindex =& $this->getIndex($previndex->getNext());
160 /// Set current index previous and next attributes
161 if ($previndex) {
162 $index->setPrevious($previndex->getName());
163 $previndex->setNext($index->getName());
165 if ($nextindex) {
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() {
194 return $this->keys;
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);
209 if ($i !== NULL) {
210 return $this->fields[$i];
212 $null = NULL;
213 return $null;
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()) {
222 return $i;
225 $null = NULL;
226 return $null;
230 * This function will reorder the array of fields
232 function orderFields() {
233 $result = $this->orderElements($this->fields);
234 if ($result) {
235 $this->setFields($result);
236 return true;
237 } else {
238 return false;
243 * Returns one XMLDBKey
245 function &getKey($keyname) {
246 $i = $this->findKeyInArray($keyname);
247 if ($i !== NULL) {
248 return $this->keys[$i];
250 $null = NULL;
251 return $null;
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()) {
260 return $i;
263 $null = NULL;
264 return $null;
268 * This function will reorder the array of keys
270 function orderKeys() {
271 $result = $this->orderElements($this->keys);
272 if ($result) {
273 $this->setKeys($result);
274 return true;
275 } else {
276 return false;
281 * Returns one XMLDBIndex
283 function &getIndex($indexname) {
284 $i = $this->findIndexInArray($indexname);
285 if ($i !== NULL) {
286 return $this->indexes[$i];
288 $null = NULL;
289 return $null;
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()) {
298 return $i;
301 $null = NULL;
302 return $null;
306 * This function will reorder the array of indexes
308 function orderIndexes() {
309 $result = $this->orderElements($this->indexes);
310 if ($result) {
311 $this->setIndexes($result);
312 return true;
313 } else {
314 return false;
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) {
329 $this->keys = $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);
345 if ($field) {
346 $i = $this->findFieldInArray($fieldname);
347 $prevfield = NULL;
348 $nextfield = NULL;
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
353 if ($prevfield) {
354 $prevfield->setNext($field->getNext());
356 if ($nextfield) {
357 $nextfield->setPrevious($field->getPrevious());
359 /// Delete the field
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);
376 if ($key) {
377 $i = $this->findKeyInArray($keyname);
378 $prevkey = NULL;
379 $nextkey = NULL;
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
384 if ($prevkey) {
385 $prevkey->setNext($key->getNext());
387 if ($nextkey) {
388 $nextkey->setPrevious($key->getPrevious());
390 /// Delete the key
391 unset($this->keys[$i]);
392 /// Reorder the Keys
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);
407 if ($index) {
408 $i = $this->findIndexInArray($indexname);
409 $previndex = NULL;
410 $nextindex = NULL;
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
415 if ($previndex) {
416 $previndex->setNext($index->getNext());
418 if ($nextindex) {
419 $nextindex->setPrevious($index->getPrevious());
421 /// Delete the index
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) {
437 global $CFG;
439 $result = true;
441 /// Debug the table
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']);
449 } else {
450 $this->errormsg = 'Missing NAME attribute';
451 $this->debug($this->errormsg);
452 $result = false;
454 if (isset($xmlarr['@']['COMMENT'])) {
455 $this->comment = trim($xmlarr['@']['COMMENT']);
456 } else if (!empty($CFG->xmldbdisablecommentchecking)) {
457 $this->comment = '';
458 } else {
459 $this->errormsg = 'Missing COMMENT attribute';
460 $this->debug($this->errormsg);
461 $result = false;
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
474 continue;
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);
483 $result = false;
486 } else {
487 $this->errormsg = 'Missing FIELDS section';
488 $this->debug($this->errormsg);
489 $result = false;
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);
498 $result = false;
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);
505 $result = false;
507 /// Order fields
508 if ($result && !$this->orderFields($this->fields)) {
509 $this->errormsg = 'Error ordering the fields';
510 $this->debug($this->errormsg);
511 $result = false;
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
519 continue;
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);
528 $result = false;
531 } else {
532 $this->errormsg = 'Missing KEYS section (at least one PK must exist)';
533 $this->debug($this->errormsg);
534 $result = false;
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);
543 $result = false;
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);
550 $result = false;
552 /// Order keys
553 if ($result && !$this->orderKeys($this->keys)) {
554 $this->errormsg = 'Error ordering the keys';
555 $this->debug($this->errormsg);
556 $result = false;
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
567 continue;
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);
576 $result = false;
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);
587 $result = false;
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);
594 $result = false;
596 /// Order indexes
597 if ($result && !$this->orderIndexes($this->indexes)) {
598 $this->errormsg = 'Error ordering the indexes';
599 $this->debug($this->errormsg);
600 $result = false;
602 /// TODO: Not indexes with repeated fields
603 /// TODO: Check fields exist in table
606 /// Set some attributes
607 if ($result) {
608 $this->loaded = true;
610 $this->calculateHash();
611 return $result;
615 * This function calculate and set the hash of one XMLDBTable
617 function calculateHash($recursive = false) {
618 if (!$this->loaded) {
619 $this->hash = NULL;
620 } else {
621 $key = $this->name . $this->comment;
622 if ($this->fields) {
623 foreach ($this->fields as $fie) {
624 $field =& $this->getField($fie->getName());
625 if ($recursive) {
626 $field->calculateHash($recursive);
628 $key .= $field->getHash();
631 if ($this->keys) {
632 foreach ($this->keys as $ke) {
633 $k =& $this->getKey($ke->getName());
634 if ($recursive) {
635 $k->calculateHash($recursive);
637 $key .= $k->getHash();
640 if ($this->indexes) {
641 foreach ($this->indexes as $in) {
642 $index =& $this->getIndex($in->getName());
643 if ($recursive) {
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() {
657 $o = '';
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 . '"';
665 if ($this->next) {
666 $o.= ' NEXT="' . $this->next . '"';
668 $o.= '>' . "\n";
669 /// Now the fields
670 if ($this->fields) {
671 $o.= ' <FIELDS>' . "\n";
672 foreach ($this->fields as $field) {
673 $o.= $field->xmlOutput();
675 $o.= ' </FIELDS>' . "\n";
677 /// Now the keys
678 if ($this->keys) {
679 $o.= ' <KEYS>' . "\n";
680 foreach ($this->keys as $key) {
681 $o.= $key->xmlOutput();
683 $o.= ' </KEYS>' . "\n";
685 /// Now the indexes
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";
695 return $o;
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);
718 return $field;
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);
734 $this->addKey($key);
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() {
758 $errors = array();
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();
771 /// Delegate to keys
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();
787 /// Return decision
788 if (count($errors)) {
789 return $errors;
790 } else {
791 return false;
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) {
801 $results = array();
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);
810 return $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) {
819 $results = array();
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);
828 return $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) {
837 $results = array();
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);
846 return $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) {
855 $results = array();
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);
864 return $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) {
873 $results = array();
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);
882 return $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) {
891 $results = array();
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);
900 return $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) {
909 $results = array();
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);
918 return $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) {
927 $results = array();
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);
936 return $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) {
945 $results = array();
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);
954 return $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) {
963 $results = array();
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);
972 return $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) {
981 $results = array();
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);
990 return $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) {
999 $results = array();
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);
1008 return $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) {
1017 $results = array();
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);
1026 return $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) {
1035 $results = array();
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);
1044 return $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) {
1054 $results = array();
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);
1063 return $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);