fixed a large number of typos in comments :-(
[moodle.git] / lib / dml / database_column_info.php
CommitLineData
49926145 1<?php
2
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.
14//
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/>.
17
18
19/**
20 * Database column information.
21 *
22 * @package moodlecore
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
26 */
0a0ea79d 27
28/**
29 * Detail database field information.
30 * Based on ADOFieldObject.
0a0ea79d 31 */
32class database_column_info {
33 /**
34 * Name of column - lowercase
35 */
36 public $name;
37
38 /**
39 * Driver dependent native data type
40 * Not standardised - used to find meta_type
41 */
42 public $type;
43
44 /**
45 * Max length:
46 * character type - number of characters
47 * blob - number of bytes
48 * integer - number of digits
49 * float - digits left from floating point
50 * boolean - 1
51 * enums - null
52 */
53 public $max_length;
54
55 /**
56 * Scale
57 * float - decimal points
58 * other - null
59 */
60 public $scale;
61
62 /**
5fe3f5c3 63 * Enumerated field options,
0a0ea79d 64 * null if not enum type
5fe3f5c3 65 *
66 * For performance reasons this field is optional!
67 * You can use DDL sql_generator::getCheckConstraintsFromDB() if needed.
0a0ea79d 68 */
69 public $enums;
70
71 /**
72 * True if not null, false otherwise
73 */
74 public $not_null;
75
76 /**
77 * True if column is primary key.
78 * (usually 'id').
79 */
80 public $primary_key;
81
82 /**
83 * True if filed autoincrementing
84 * (usually 'id' only)
85 */
86 public $auto_increment;
87
88 /**
89 * True if binary
90 */
91 public $binary;
92
93 /**
94 * True if integer unsigned, false if signed.
95 * Null for other types
96 */
97 public $unsigned;
98
99 /**
100 * True if default value defined
101 */
102 public $has_default;
103
104 /**
105 * Default value if defined
106 */
107 public $default_value;
108
109 /**
72e949b8 110 * True if field values unique, false if not
0a0ea79d 111 */
112 public $unique;
113
114 /**
862d54c3 115 * Standardised one character column type, uppercase
0a0ea79d 116 * R - counter (integer primary key)
117 * I - integers
118 * N - numbers (floats)
119 * C - characters and strings
120 * X - texts
121 * B - binary blobs
122 * L - boolean (1 bit)
123 * T - timestamp - unsupported
124 * D - date - unsupported
125 */
126 public $meta_type;
127
128 /**
862d54c3 129 * Constructor
0a0ea79d 130 * @param $data mixed object or array with properties
131 */
132 public function __construct($data) {
133 foreach ($data as $key=>$value) {
134 if (array_key_exists($key, $this)) {
135 $this->$key = $value;
136 }
137 }
72e949b8 138
139 switch ($this->meta_type) {
140 case 'R': // normalise counters (usually 'id')
141 $this->auto_increment = true;
142 $this->binary = false;
143 $this->has_default = false;
144 $this->default_value = null;
145 $this->unique = true;
6321dbf0 146 break;
72e949b8 147 case 'C':
148 $this->auto_increment = false;
149 $this->binary = false;
6321dbf0 150 break;
72e949b8 151 }
0a0ea79d 152 }
153}