"MDL-12304, fix double text"
[moodle-linuxchix.git] / lib / xmldb / classes / XMLDBField.class.php
blob0ffca5588a3dac59c91521bebee39b104218daab
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) 1999 onwards 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 Field
29 class XMLDBField extends XMLDBObject {
31 var $type;
32 var $length;
33 var $unsigned;
34 var $notnull;
35 var $default;
36 var $sequence;
37 var $enum;
38 var $enumvalues;
39 var $decimals;
41 /**
42 * Creates one new XMLDBField
44 function XMLDBField($name) {
45 parent::XMLDBObject($name);
46 $this->type = NULL;
47 $this->length = NULL;
48 $this->unsigned = true;
49 $this->notnull = false;
50 $this->default = NULL;
51 $this->sequence = false;
52 $this->enum = false;
53 $this->enumvalues = NULL;
54 $this->decimals = NULL;
57 /**
58 * Set all the attributes of one XMLDBField
60 * @param string type XMLDB_TYPE_INTEGER, XMLDB_TYPE_NUMBER, XMLDB_TYPE_CHAR, XMLDB_TYPE_TEXT, XMLDB_TYPE_BINARY
61 * @param string precision length for integers and chars, two-comma separated numbers for numbers and 'small', 'medium', 'big' for texts and binaries
62 * @param string unsigned XMLDB_UNSIGNED or null (or false)
63 * @param string notnull XMLDB_NOTNULL or null (or false)
64 * @param string sequence XMLDB_SEQUENCE or null (or false)
65 * @param string enum XMLDB_ENUM or null (or false)
66 * @param array enumvalues an array of possible values if XMLDB_ENUM is set
67 * @param string default meaningful default o null (or false)
69 function setAttributes($type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $enum=null, $enumvalues=null, $default=null, $previous=null) {
70 $this->type = $type;
71 /// Try to split the precision into length and decimals and apply
72 /// each one as needed
73 $precisionarr = explode(',', $precision);
74 if (isset($precisionarr[0])) {
75 $this->length = trim($precisionarr[0]);
77 if (isset($precisionarr[1])) {
78 $this->decimals = trim($precisionarr[1]);
80 $this->precision = $type;
81 $this->unsigned = !empty($unsigned) ? true : false;
82 $this->notnull = !empty($notnull) ? true : false;
83 $this->sequence = !empty($sequence) ? true : false;
84 $this->enum = !empty($enum) ? true : false;
85 /// Accept both quoted and non-quoted vales (quoting them)a
86 if (is_array($enumvalues)) {
87 $this->enumvalues = array();
88 foreach ($enumvalues as $value) {
89 /// trim each value quotes
90 $value = trim($value, "'");
91 /// add them back
92 $value = "'" . $value . "'";
93 $this->enumvalues[] = $value;
96 $this->setDefault($default);
98 $this->previous = $previous;
102 * Get the type
104 function getType() {
105 return $this->type;
109 * Get the length
111 function getLength() {
112 return $this->length;
116 * Get the decimals
118 function getDecimals() {
119 return $this->decimals;
123 * Get the notnull
125 function getNotNull() {
126 return $this->notnull;
130 * Get the unsigned
132 function getUnsigned() {
133 return $this->unsigned;
137 * Get the sequence
139 function getSequence() {
140 return $this->sequence;
144 * Get the enum
146 function getEnum() {
147 return $this->enum;
151 * Get the enumvalues
153 function getEnumValues() {
154 return $this->enumvalues;
158 * Get the default
160 function getDefault() {
161 return $this->default;
165 * Set the field type
167 function setType($type) {
168 $this->type = $type;
172 * Set the field length
174 function setLength($length) {
175 $this->length = $length;
179 * Set the field decimals
181 function setDecimals($decimals) {
182 $this->decimals = $decimals;
186 * Set the field unsigned
188 function setUnsigned($unsigned=true) {
189 $this->unsigned = $unsigned;
193 * Set the field notnull
195 function setNotNull($notnull=true) {
196 $this->notnull = $notnull;
200 * Set the field sequence
202 function setSequence($sequence=true) {
203 $this->sequence = $sequence;
207 * Set the field enum
209 function setEnum($enum=true) {
210 $this->enum = $enum;
214 * Set the field enumvalues, quoting unquoted values
216 function setEnumValues($enumvalues) {
217 if (is_array($enumvalues)) {
218 $this->enumvalues = array();
219 foreach ($enumvalues as $value) {
220 /// trim each value quotes
221 $value = trim($value, "'");
222 /// add them back
223 $value = "'" . $value . "'";
224 $this->enumvalues[] = $value;
230 * Set the field default
232 function setDefault($default) {
233 /// Check, warn and auto-fix '' (empty) defaults for CHAR NOT NULL columns, changing them
234 /// to NULL so XMLDB will apply the proper default
235 if ($this->type == XMLDB_TYPE_CHAR && $this->notnull && $default === '') {
236 $this->errormsg = 'XMLDB has detected one CHAR NOT NULL column (' . $this->name . ") with '' (empty string) as DEFAULT value. This type of columns must have one meaningful DEFAULT declared or none (NULL). XMLDB have fixed it automatically changing it to none (NULL). The process will continue ok and proper defaults will be created accordingly with each DB requirements. Please fix it in source (XML and/or upgrade script) to avoid this message to be displayed.";
237 $this->debug($this->errormsg);
238 $default = NULL;
240 $this->default = $default;
244 * Load data from XML to the table
246 function arr2XMLDBField($xmlarr) {
248 $result = true;
250 /// Debug the table
251 /// traverse_xmlize($xmlarr); //Debug
252 /// print_object ($GLOBALS['traverse_array']); //Debug
253 /// $GLOBALS['traverse_array']=""; //Debug
255 /// Process table attributes (name, type, length, unsigned,
256 /// notnull, sequence, enum, enumvalues, decimals, comment,
257 /// previous, next)
258 if (isset($xmlarr['@']['NAME'])) {
259 $this->name = trim($xmlarr['@']['NAME']);
260 } else {
261 $this->errormsg = 'Missing NAME attribute';
262 $this->debug($this->errormsg);
263 $result = false;
266 if (isset($xmlarr['@']['TYPE'])) {
267 /// Check for valid type
268 $type = $this->getXMLDBFieldType(trim($xmlarr['@']['TYPE']));
269 if ($type) {
270 $this->type = $type;
271 } else {
272 $this->errormsg = 'Invalid TYPE attribute';
273 $this->debug($this->errormsg);
274 $result = false;
276 } else {
277 $this->errormsg = 'Missing TYPE attribute';
278 $this->debug($this->errormsg);
279 $result = false;
282 if (isset($xmlarr['@']['LENGTH'])) {
283 $length = trim($xmlarr['@']['LENGTH']);
284 /// Check for integer values
285 if ($this->type == XMLDB_TYPE_INTEGER ||
286 $this->type == XMLDB_TYPE_NUMBER ||
287 $this->type == XMLDB_TYPE_CHAR) {
288 if (!(is_numeric($length)&&(intval($length)==floatval($length)))) {
289 $this->errormsg = 'Incorrect LENGTH attribute for int, number or char fields';
290 $this->debug($this->errormsg);
291 $result = false;
292 } else if (!$length) {
293 $this->errormsg = 'Zero LENGTH attribute';
294 $this->debug($this->errormsg);
295 $result = false;
298 /// Check for big, medium, small to be applied to text and binary
299 if ($this->type == XMLDB_TYPE_TEXT ||
300 $this->type == XMLDB_TYPE_BINARY) {
301 if (!$length) {
302 $length == 'big';
304 if ($length != 'big' &&
305 $length != 'medium' &&
306 $length != 'small') {
307 $this->errormsg = 'Incorrect LENGTH attribute for text and binary fields (only big, medium and small allowed)';
308 $this->debug($this->errormsg);
309 $result = false;
312 /// Finally, set the length
313 $this->length = $length;
316 if (isset($xmlarr['@']['UNSIGNED'])) {
317 $unsigned = strtolower(trim($xmlarr['@']['UNSIGNED']));
318 if ($unsigned == 'true') {
319 $this->unsigned = true;
320 } else if ($unsigned == 'false') {
321 $this->unsigned = false;
322 } else {
323 $this->errormsg = 'Incorrect UNSIGNED attribute (true/false allowed)';
324 $this->debug($this->errormsg);
325 $result = false;
329 if (isset($xmlarr['@']['NOTNULL'])) {
330 $notnull = strtolower(trim($xmlarr['@']['NOTNULL']));
331 if ($notnull == 'true') {
332 $this->notnull = true;
333 } else if ($notnull == 'false') {
334 $this->notnull = false;
335 } else {
336 $this->errormsg = 'Incorrect NOTNULL attribute (true/false allowed)';
337 $this->debug($this->errormsg);
338 $result = false;
342 if (isset($xmlarr['@']['SEQUENCE'])) {
343 $sequence = strtolower(trim($xmlarr['@']['SEQUENCE']));
344 if ($sequence == 'true') {
345 $this->sequence = true;
346 } else if ($sequence == 'false') {
347 $this->sequence = false;
348 } else {
349 $this->errormsg = 'Incorrect SEQUENCE attribute (true/false allowed)';
350 $this->debug($this->errormsg);
351 $result = false;
355 if (isset($xmlarr['@']['DEFAULT'])) {
356 $this->setDefault(trim($xmlarr['@']['DEFAULT']));
359 if (isset($xmlarr['@']['ENUM'])) {
360 $enum = strtolower(trim($xmlarr['@']['ENUM']));
361 if ($enum == 'true') {
362 $this->enum = true;
363 } else if ($enum == 'false') {
364 $this->enum = false;
365 } else {
366 $this->errormsg = 'Incorrect ENUM attribute (true/false allowed)';
367 $this->debug($this->errormsg);
368 $result = false;
372 if (isset($xmlarr['@']['ENUMVALUES'])) {
373 $enumvalues = trim($xmlarr['@']['ENUMVALUES']);
374 if (!$this->enum) {
375 $this->errormsg = 'Wrong ENUMVALUES attribute (not ENUM)';
376 $this->debug($this->errormsg);
377 $result = false;
378 $this->enumvalues = $enumvalues;
379 } else {
380 /// Check we have a valid list (comma separated of quoted values)
381 $enumarr = explode(',',$enumvalues);
382 if ($enumarr) {
383 foreach ($enumarr as $key => $enumelement) {
384 /// Clear some spaces
385 $enumarr[$key] = trim($enumelement);
386 $enumelement = trim($enumelement);
387 /// Skip if under error
388 if (!$result) {
389 continue;
391 /// Look for quoted strings
392 if (substr($enumelement, 0, 1) != "'" ||
393 substr($enumelement, -1, 1) != "'") {
394 $this->errormsg = 'Incorrect ENUMVALUES attribute (some value is not properly quoted)';
395 $this->debug($this->errormsg);
396 $result = false;
399 } else {
400 $this->errormsg = 'Incorrect ENUMVALUES attribute (comma separated of quoted values)';
401 $this->debug($this->errormsg);
402 $result = false;
405 } else if ($this->enum) {
406 $this->errormsg = 'Incorrect ENUMVALUES attribute (field is not declared as ENUM)';
407 $this->debug($this->errormsg);
408 $result = false;
410 /// Finally, set the value
411 if ($this->enum) {
412 $this->enumvalues = $enumarr;
415 $decimals = NULL;
416 if (isset($xmlarr['@']['DECIMALS'])) {
417 $decimals = trim($xmlarr['@']['DECIMALS']);
418 /// Check for integer values
419 if ($this->type == XMLDB_TYPE_NUMBER ||
420 $this->type == XMLDB_TYPE_FLOAT) {
421 if (!(is_numeric($decimals)&&(intval($decimals)==floatval($decimals)))) {
422 $this->errormsg = 'Incorrect DECIMALS attribute for number field';
423 $this->debug($this->errormsg);
424 $result = false;
425 } else if ($this->length <= $decimals){
426 $this->errormsg = 'Incorrect DECIMALS attribute (bigget than length)';
427 $this->debug($this->errormsg);
428 $result = false;
430 } else {
431 $this->errormsg = 'Incorrect DECIMALS attribute for non-number field';
432 $this->debug($this->errormsg);
433 $result = false;
435 } else {
436 if ($this->type == XMLDB_TYPE_NUMBER) {
437 $decimals = 0;
440 // Finally, set the decimals
441 if ($this->type == XMLDB_TYPE_NUMBER ||
442 $this->type == XMLDB_TYPE_FLOAT) {
443 $this->decimals = $decimals;
446 if (isset($xmlarr['@']['COMMENT'])) {
447 $this->comment = trim($xmlarr['@']['COMMENT']);
450 if (isset($xmlarr['@']['PREVIOUS'])) {
451 $this->previous = trim($xmlarr['@']['PREVIOUS']);
454 if (isset($xmlarr['@']['NEXT'])) {
455 $this->next = trim($xmlarr['@']['NEXT']);
458 /// Set some attributes
459 if ($result) {
460 $this->loaded = true;
462 $this->calculateHash();
463 return $result;
467 * This function returns the correct XMLDB_TYPE_XXX value for the
468 * string passed as argument
470 function getXMLDBFieldType($type) {
472 $result = XMLDB_TYPE_INCORRECT;
474 switch (strtolower($type)) {
475 case 'int':
476 $result = XMLDB_TYPE_INTEGER;
477 break;
478 case 'number':
479 $result = XMLDB_TYPE_NUMBER;
480 break;
481 case 'float':
482 $result = XMLDB_TYPE_FLOAT;
483 break;
484 case 'char':
485 $result = XMLDB_TYPE_CHAR;
486 break;
487 case 'text':
488 $result = XMLDB_TYPE_TEXT;
489 break;
490 case 'binary':
491 $result = XMLDB_TYPE_BINARY;
492 break;
493 case 'datetime':
494 $result = XMLDB_TYPE_DATETIME;
495 break;
497 /// Return the normalized XMLDB_TYPE
498 return $result;
502 * This function returns the correct name value for the
503 * XMLDB_TYPE_XXX passed as argument
505 function getXMLDBTypeName($type) {
507 $result = "";
509 switch (strtolower($type)) {
510 case XMLDB_TYPE_INTEGER:
511 $result = 'int';
512 break;
513 case XMLDB_TYPE_NUMBER:
514 $result = 'number';
515 break;
516 case XMLDB_TYPE_FLOAT:
517 $result = 'float';
518 break;
519 case XMLDB_TYPE_CHAR:
520 $result = 'char';
521 break;
522 case XMLDB_TYPE_TEXT:
523 $result = 'text';
524 break;
525 case XMLDB_TYPE_BINARY:
526 $result = 'binary';
527 break;
528 case XMLDB_TYPE_DATETIME:
529 $result = 'datetime';
530 break;
532 /// Return the normalized name
533 return $result;
537 * This function calculate and set the hash of one XMLDBField
539 function calculateHash($recursive = false) {
540 if (!$this->loaded) {
541 $this->hash = NULL;
542 } else {
543 $key = $this->name . $this->type . $this->length .
544 $this->unsigned . $this->notnull . $this->sequence .
545 $this->decimals . $this->comment;
546 if ($this->enum) {
547 $key .= implode(', ',$this->enumvalues);
549 $this->hash = md5($key);
554 *This function will output the XML text for one field
556 function xmlOutput() {
557 $o = '';
558 $o.= ' <FIELD NAME="' . $this->name . '"';
559 $o.= ' TYPE="' . $this->getXMLDBTypeName($this->type) . '"';
560 if ($this->length) {
561 $o.= ' LENGTH="' . $this->length . '"';
563 if ($this->notnull) {
564 $notnull = 'true';
565 } else {
566 $notnull = 'false';
568 $o.= ' NOTNULL="' . $notnull . '"';
569 if ($this->unsigned) {
570 $unsigned = 'true';
571 } else {
572 $unsigned = 'false';
574 if ($this->type == XMLDB_TYPE_INTEGER ||
575 $this->type == XMLDB_TYPE_NUMBER ||
576 $this->type == XMLDB_TYPE_FLOAT) {
577 if ($this->unsigned) {
578 $unsigned = 'true';
579 } else {
580 $unsigned = 'false';
582 $o.= ' UNSIGNED="' . $unsigned . '"';
584 if (!$this->sequence && $this->default !== NULL) {
585 $o.= ' DEFAULT="' . $this->default . '"';
587 if ($this->sequence) {
588 $sequence = 'true';
589 } else {
590 $sequence = 'false';
592 $o.= ' SEQUENCE="' . $sequence . '"';
593 if ($this->enum) {
594 $enum = 'true';
595 } else {
596 $enum = 'false';
598 $o.= ' ENUM="' . $enum . '"';
599 if ($this->enum) {
600 $o.= ' ENUMVALUES="' . implode(', ', $this->enumvalues) . '"';
602 if ($this->decimals !== NULL) {
603 $o.= ' DECIMALS="' . $this->decimals . '"';
605 if ($this->comment) {
606 $o.= ' COMMENT="' . htmlspecialchars($this->comment) . '"';
608 if ($this->previous) {
609 $o.= ' PREVIOUS="' . $this->previous . '"';
611 if ($this->next) {
612 $o.= ' NEXT="' . $this->next . '"';
614 $o.= '/>' . "\n";
616 return $o;
620 * This function will set all the attributes of the XMLDBField object
621 * based on information passed in one ADOField
623 function setFromADOField($adofield) {
625 /// Calculate the XMLDB_TYPE
626 switch (strtolower($adofield->type)) {
627 case 'int':
628 case 'tinyint':
629 case 'smallint':
630 case 'bigint':
631 case 'integer':
632 $this->type = XMLDB_TYPE_INTEGER;
633 break;
634 case 'number':
635 case 'decimal':
636 case 'dec':
637 case 'numeric':
638 $this->type = XMLDB_TYPE_NUMBER;
639 break;
640 case 'float':
641 case 'double':
642 $this->type = XMLDB_TYPE_FLOAT;
643 break;
644 case 'char':
645 case 'varchar':
646 case 'enum':
647 $this->type = XMLDB_TYPE_CHAR;
648 break;
649 case 'text':
650 case 'tinytext':
651 case 'mediumtext':
652 case 'longtext':
653 $this->type = XMLDB_TYPE_TEXT;
654 break;
655 case 'blob':
656 case 'tinyblob':
657 case 'mediumblob':
658 case 'longblob':
659 $this->type = XMLDB_TYPE_BINARY;
660 break;
661 case 'datetime':
662 case 'timestamp':
663 $this->type = XMLDB_TYPE_DATETIME;
664 break;
665 default:
666 $this->type = XMLDB_TYPE_TEXT;
668 /// Calculate the length of the field
669 if ($adofield->max_length > 0 &&
670 ($this->type == XMLDB_TYPE_INTEGER ||
671 $this->type == XMLDB_TYPE_NUMBER ||
672 $this->type == XMLDB_TYPE_FLOAT ||
673 $this->type == XMLDB_TYPE_CHAR)) {
674 $this->length = $adofield->max_length;
676 if ($this->type == XMLDB_TYPE_TEXT) {
677 switch (strtolower($adofield->type)) {
678 case 'tinytext':
679 case 'text':
680 $this->length = 'small';
681 break;
682 case 'mediumtext':
683 $this->length = 'medium';
684 break;
685 case 'longtext':
686 $this->length = 'big';
687 break;
688 default:
689 $this->length = 'small';
692 if ($this->type == XMLDB_TYPE_BINARY) {
693 switch (strtolower($adofield->type)) {
694 case 'tinyblob':
695 case 'blob':
696 $this->length = 'small';
697 break;
698 case 'mediumblob':
699 $this->length = 'medium';
700 break;
701 case 'longblob':
702 $this->length = 'big';
703 break;
704 default:
705 $this->length = 'small';
708 /// Calculate the decimals of the field
709 if ($adofield->max_length > 0 &&
710 $adofield->scale &&
711 ($this->type == XMLDB_TYPE_NUMBER ||
712 $this->type == XMLDB_TYPE_FLOAT)) {
713 $this->decimals = $adofield->scale;
715 /// Calculate the unsigned field
716 if ($adofield->unsigned &&
717 ($this->type == XMLDB_TYPE_INTEGER ||
718 $this->type == XMLDB_TYPE_NUMBER ||
719 $this->type == XMLDB_TYPE_FLOAT)) {
720 $this->unsigned = true;
722 /// Calculate the notnull field
723 if ($adofield->not_null) {
724 $this->notnull = true;
726 /// Calculate the default field
727 if ($adofield->has_default) {
728 $this->default = $adofield->default_value;
730 /// Calculate the sequence field
731 if ($adofield->auto_increment) {
732 $this->sequence = true;
733 /// Sequence fields are always unsigned
734 $this->unsigned = true;
736 /// Calculate the enum and enumvalues field
737 if ($adofield->type == 'enum') {
738 $this->enum = true;
739 $this->enumvalues = $adofield->enums;
741 /// Some more fields
742 $this->loaded = true;
743 $this->changed = true;
747 * Returns the PHP code needed to define one XMLDBField
749 function getPHP($includeprevious=true) {
751 $result = '';
753 /// The XMLDBTYPE
754 switch ($this->getType()) {
755 case XMLDB_TYPE_INTEGER:
756 $result .= 'XMLDB_TYPE_INTEGER' . ', ';
757 break;
758 case XMLDB_TYPE_NUMBER:
759 $result .= 'XMLDB_TYPE_NUMBER' . ', ';
760 break;
761 case XMLDB_TYPE_FLOAT:
762 $result .= 'XMLDB_TYPE_FLOAT' . ', ';
763 break;
764 case XMLDB_TYPE_CHAR:
765 $result .= 'XMLDB_TYPE_CHAR' . ', ';
766 break;
767 case XMLDB_TYPE_TEXT:
768 $result .= 'XMLDB_TYPE_TEXT' . ', ';
769 break;
770 case XMLDB_TYPE_BINARY:
771 $result .= 'XMLDB_TYPE_BINARY' . ', ';
772 break;
773 case XMLDB_TYPE_DATETIME:
774 $result .= 'XMLDB_TYPE_DATETIME' . ', ';
775 break;
776 case XMLDB_TYPE_TIMESTAMP:
777 $result .= 'XMLDB_TYPE_TIMESTAMP' . ', ';
778 break;
780 /// The length
781 $length = $this->getLength();
782 $decimals = $this->getDecimals();
783 if (!empty($length)) {
784 $result .= "'" . $length;
785 if (!empty($decimals)) {
786 $result .= ', ' . $decimals;
788 $result .= "', ";
789 } else {
790 $result .= 'null, ';
792 /// Unsigned (only applicable to numbers)
793 $unsigned = $this->getUnsigned();
794 if (!empty($unsigned) &&
795 ($this->getType() == XMLDB_TYPE_INTEGER || $this->getType() == XMLDB_TYPE_NUMBER || $this->getType() == XMLDB_TYPE_FLOAT)) {
796 $result .= 'XMLDB_UNSIGNED' . ', ';
797 } else {
798 $result .= 'null, ';
800 /// Not Null
801 $notnull = $this->getNotnull();
802 if (!empty($notnull)) {
803 $result .= 'XMLDB_NOTNULL' . ', ';
804 } else {
805 $result .= 'null, ';
807 /// Sequence
808 $sequence = $this->getSequence();
809 if (!empty($sequence)) {
810 $result .= 'XMLDB_SEQUENCE' . ', ';
811 } else {
812 $result .= 'null, ';
814 /// Enum
815 $enum = $this->getEnum();
816 if (!empty($enum)) {
817 $result .= 'XMLDB_ENUM' . ', ';
818 } else {
819 $result .= 'null, ';
821 /// Enumvalues
822 $enumvalues = $this->getEnumValues();
823 if (!empty($enumvalues)) {
824 $result .= 'array(' . implode(', ', $enumvalues) . '), ';
825 } else {
826 $result .= 'null, ';
828 /// Default
829 $default = $this->getDefault();
830 if ($default !== null && !$this->getSequence()) {
831 $result .= "'" . $default . "'";
832 } else {
833 $result .= 'null';
835 /// Previous (decided by parameter)
836 if ($includeprevious) {
837 $previous = $this->getPrevious();
838 if (!empty($previous)) {
839 $result .= ", '" . $previous . "'";
840 } else {
841 $result .= ', null';
844 /// Return result
845 return $result;
849 * Shows info in a readable format
851 function readableInfo() {
852 $o = '';
853 /// type
854 $o .= $this->getXMLDBTypeName($this->type);
855 /// length
856 if ($this->type == XMLDB_TYPE_INTEGER ||
857 $this->type == XMLDB_TYPE_NUMBER ||
858 $this->type == XMLDB_TYPE_FLOAT ||
859 $this->type == XMLDB_TYPE_CHAR) {
860 if ($this->length) {
861 $o .= ' (' . $this->length;
862 if ($this->type == XMLDB_TYPE_NUMBER ||
863 $this->type == XMLDB_TYPE_FLOAT) {
864 if ($this->decimals !== NULL) {
865 $o .= ', ' . $this->decimals;
868 $o .= ')';
871 if ($this->type == XMLDB_TYPE_TEXT ||
872 $this->type == XMLDB_TYPE_BINARY) {
873 $o .= ' (' . $this->length . ')';
875 /// enum
876 if ($this->enum) {
877 $o .= ' enum(' . implode(', ', $this->enumvalues) . ')';
879 /// unsigned
880 if ($this->type == XMLDB_TYPE_INTEGER ||
881 $this->type == XMLDB_TYPE_NUMBER ||
882 $this->type == XMLDB_TYPE_FLOAT) {
883 if ($this->unsigned) {
884 $o .= ' unsigned';
885 } else {
886 $o .= ' signed';
889 /// not null
890 if ($this->notnull) {
891 $o .= ' not null';
893 /// default
894 if ($this->default !== NULL) {
895 $o .= ' default ';
896 if ($this->type == XMLDB_TYPE_CHAR ||
897 $this->type == XMLDB_TYPE_TEXT) {
898 $o .= "'" . $this->default . "'";
899 } else {
900 $o .= $this->default;
903 /// sequence
904 if ($this->sequence) {
905 $o .= ' auto-numbered';
908 return $o;