3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
20 * Database column information.
24 * @copyright 2008 Petr Skoda (http://skodak.org)
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') ||
die();
31 * Detail database field information.
32 * Based on ADOFieldObject.
34 class database_column_info
{
36 * Name of column - lowercase
41 * Driver dependent native data type
42 * Not standardised - used to find meta_type
48 * character type - number of characters
49 * blob - number of bytes
50 * integer - number of digits
51 * float - digits left from floating point
59 * float - decimal points
65 * Enumerated field options,
66 * null if not enum type
68 * For performance reasons this field is optional!
69 * You can use DDL sql_generator::getCheckConstraintsFromDB() if needed.
74 * True if not null, false otherwise
79 * True if column is primary key.
85 * True if filed autoincrementing
88 public $auto_increment;
96 * True if integer unsigned, false if signed.
97 * Null for other types
102 * True if default value defined
107 * Default value if defined
109 public $default_value;
112 * True if field values unique, false if not
117 * Standardised one character column type, uppercase
118 * R - counter (integer primary key)
120 * N - numbers (floats)
121 * C - characters and strings
124 * L - boolean (1 bit)
125 * T - timestamp - unsupported
126 * D - date - unsupported
132 * @param $data mixed object or array with properties
134 public function __construct($data) {
135 foreach ($data as $key=>$value) {
136 if (property_exists($this, $key)) {
137 $this->$key = $value;
141 switch ($this->meta_type
) {
142 case 'R': // normalise counters (usually 'id')
143 $this->auto_increment
= true;
144 $this->binary
= false;
145 $this->has_default
= false;
146 $this->default_value
= null;
147 $this->unique
= true;
150 $this->auto_increment
= false;
151 $this->binary
= false;