2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Database column information.
21 * @copyright 2008 Petr Skoda (http://skodak.org)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
28 * Detailed database field information.
30 * It is based on the adodb library's ADOFieldObject object.
31 * 'column' does mean 'the field' here.
34 * @copyright 2008 Petr Skoda (http://skodak.org)
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class database_column_info
{
39 * Name of column - lowercase.
45 * Driver dependent native data type.
46 * Not standardised, its used to find meta_type.
53 * character type - number of characters
54 * blob - number of bytes
55 * integer - number of digits
56 * float - digits left from floating point
64 * float - decimal points
71 * True if not null, false otherwise
77 * True if column is primary key.
84 * True if filed autoincrementing
88 public $auto_increment;
97 * True if integer unsigned, false if signed.
98 * Null for other types
100 * @deprecated since 2.3
105 * True if the default value is defined.
111 * The default value (if defined).
114 public $default_value;
117 * True if field values are unique, false if not.
123 * Standardised one character column type, uppercased and enumerated as follows:
124 * R - counter (integer primary key)
126 * N - numbers (floats)
127 * C - characters and strings
130 * L - boolean (1 bit)
131 * T - timestamp - unsupported
132 * D - date - unsupported
139 * @param mixed $data object or array with properties
141 public function __construct($data) {
142 foreach ($data as $key=>$value) {
143 if (property_exists($this, $key)) {
144 $this->$key = $value;
148 switch ($this->meta_type
) {
149 case 'R': // normalise counters (usually 'id')
150 $this->binary
= false;
151 $this->has_default
= false;
152 $this->default_value
= null;
153 $this->unique
= true;
156 $this->auto_increment
= false;
157 $this->binary
= false;