Merge branch 'wip-mdl-30121-m22' of git://github.com/rajeshtaneja/moodle into MOODLE_...
[moodle.git] / lib / dml / database_column_info.php
blobe7e19879db74116498fb6d4292023cd0dac179a3
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
9 //
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/>.
19 /**
20 * Database column information.
22 * @package core
23 * @subpackage dml
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();
30 /**
31 * Detail database field information.
32 * Based on ADOFieldObject.
34 class database_column_info {
35 /**
36 * Name of column - lowercase
38 public $name;
40 /**
41 * Driver dependent native data type
42 * Not standardised - used to find meta_type
44 public $type;
46 /**
47 * Max length:
48 * character type - number of characters
49 * blob - number of bytes
50 * integer - number of digits
51 * float - digits left from floating point
52 * boolean - 1
53 * enums - null
55 public $max_length;
57 /**
58 * Scale
59 * float - decimal points
60 * other - null
62 public $scale;
64 /**
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.
71 public $enums;
73 /**
74 * True if not null, false otherwise
76 public $not_null;
78 /**
79 * True if column is primary key.
80 * (usually 'id').
82 public $primary_key;
84 /**
85 * True if filed autoincrementing
86 * (usually 'id' only)
88 public $auto_increment;
90 /**
91 * True if binary
93 public $binary;
95 /**
96 * True if integer unsigned, false if signed.
97 * Null for other types
99 public $unsigned;
102 * True if default value defined
104 public $has_default;
107 * Default value if defined
109 public $default_value;
112 * True if field values unique, false if not
114 public $unique;
117 * Standardised one character column type, uppercase
118 * R - counter (integer primary key)
119 * I - integers
120 * N - numbers (floats)
121 * C - characters and strings
122 * X - texts
123 * B - binary blobs
124 * L - boolean (1 bit)
125 * T - timestamp - unsupported
126 * D - date - unsupported
128 public $meta_type;
131 * Constructor
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;
148 break;
149 case 'C':
150 $this->auto_increment = false;
151 $this->binary = false;
152 break;