Merge branch '45699-29' of git://github.com/samhemelryk/moodle
[moodle.git] / lib / dml / database_column_info.php
blob4aee79aa35ea3d89a6e8f5910beea18845aa50d1
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * Database column information.
20 * @package core_dml
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();
27 /**
28 * Detailed database field information.
30 * It is based on the adodb library's ADOFieldObject object.
31 * 'column' does mean 'the field' here.
33 * @package core_dml
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 {
38 /**
39 * Name of column - lowercase.
40 * @var string
42 public $name;
44 /**
45 * Driver dependent native data type.
46 * Not standardised, its used to find meta_type.
47 * @var string
49 public $type;
51 /**
52 * Max length:
53 * character type - number of characters
54 * blob - number of bytes
55 * integer - number of digits
56 * float - digits left from floating point
57 * boolean - 1
58 * @var int
60 public $max_length;
62 /**
63 * Scale
64 * float - decimal points
65 * other - null
66 * @var int
68 public $scale;
70 /**
71 * True if not null, false otherwise
72 * @var bool
74 public $not_null;
76 /**
77 * True if column is primary key.
78 * (usually 'id').
79 * @var bool
81 public $primary_key;
83 /**
84 * True if filed autoincrementing
85 * (usually 'id' only)
86 * @var bool
88 public $auto_increment;
90 /**
91 * True if binary
92 * @var bool
94 public $binary;
96 /**
97 * True if integer unsigned, false if signed.
98 * Null for other types
99 * @var integer
100 * @deprecated since 2.3
102 public $unsigned;
105 * True if the default value is defined.
106 * @var bool
108 public $has_default;
111 * The default value (if defined).
112 * @var string
114 public $default_value;
117 * True if field values are unique, false if not.
118 * @var bool
120 public $unique;
123 * Standardised one character column type, uppercased and enumerated as follows:
124 * R - counter (integer primary key)
125 * I - integers
126 * N - numbers (floats)
127 * C - characters and strings
128 * X - texts
129 * B - binary blobs
130 * L - boolean (1 bit)
131 * T - timestamp - unsupported
132 * D - date - unsupported
133 * @var string
135 public $meta_type;
138 * Constructor
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;
154 break;
155 case 'C':
156 $this->auto_increment = false;
157 $this->binary = false;
158 break;