ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
ilDBPdoMySQLFieldDefinition Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilDBPdoMySQLFieldDefinition:
+ Collaboration diagram for ilDBPdoMySQLFieldDefinition:

Public Member Functions

 getTypeDeclaration (array $field)
 
- Public Member Functions inherited from ilDBPdoFieldDefinition
 __construct (\ilDBInterface $ilDBInterface)
 ilDBPdoFieldDefinition constructor. More...
 
 checkTableName (string $table_name)
 
 isReserved (string $table_name)
 
 getAllReserved ()
 
 getReservedMysql ()
 
 setReservedMysql (array $reserved_mysql)
 
 checkColumnName (string $column_name)
 
 checkIndexName (string $a_name)
 
 checkColumnDefinition (array $a_def)
 
 isAllowedAttribute (string $attribute, string $type)
 
 getAvailableTypes ()
 
 setAvailableTypes (array $available_types)
 
 getAllowedAttributes ()
 
 setAllowedAttributes (array $allowed_attributes)
 
 getMaxLength ()
 
 setMaxLength (array $max_length)
 
 getValidTypes ()
 
 getDeclaration (string $type, string $name, $field)
 
 getTypeDeclaration (array $field)
 
 compareDefinition (array $current, array $previous)
 
 quote ($value, ?string $type=null, bool $quote=true, bool $escape_wildcards=false)
 
 writeLOBToFile ($lob, string $file)
 
 destroyLOB ($lob)
 
 matchPattern (array $pattern, $operator=null, $field=null)
 
 patternEscapeString ()
 
 mapNativeDatatype (array $field)
 
 mapPrepareDatatype (string $type)
 

Protected Member Functions

 getIntegerDeclaration (string $name, array $field)
 
 mapNativeDatatypeInternal (array $field)
 
- Protected Member Functions inherited from ilDBPdoFieldDefinition
 getQueryUtils ()
 
 getDBInstance ()
 
 getInternalDeclaration (string $name, array $field)
 
 getDeclarationOptions (array $field)
 
 getCharsetFieldDeclaration (string $charset)
 
 getCollationFieldDeclaration (string $collation)
 
 getIntegerDeclaration (string $name, array $field)
 
 getTextDeclaration (string $name, array $field)
 
 getCLOBDeclaration (string $name, array $field)
 
 getBLOBDeclaration (string $name, array $field)
 
 getBooleanDeclaration (string $name, array $field)
 
 getDateDeclaration (string $name, array $field)
 
 getTimestampDeclaration (string $name, array $field)
 
 getTimeDeclaration (string $name, array $field)
 
 getFloatDeclaration (string $name, array $field)
 
 getDecimalDeclaration (string $name, array $field)
 
 compareIntegerDefinition (array $current, array $previous)
 
 compareTextDefinition (array $current, array $previous)
 
 compareCLOBDefinition (array $current, array $previous)
 
 compareBLOBDefinition (array $current, array $previous)
 
 compareDateDefinition (array $current, array $previous)
 
 compareTimeDefinition (array $current, array $previous)
 
 compareTimestampDefinition (array $current, array $previous)
 
 compareBooleanDefinition (array $current, array $previous)
 
 compareFloatDefinition (array $current, array $previous)
 
 compareDecimalDefinition (array $current, array $previous)
 
 quoteInteger ($value, bool $quote, bool $escape_wildcards)
 
 quoteText (string $value, bool $quote, bool $escape_wildcards)
 
 readFile ($value)
 
 quoteLOB ($value, bool $quote, bool $escape_wildcards)
 
 quoteCLOB ($value, bool $quote, bool $escape_wildcards)
 
 quoteBLOB ($value, bool $quote, bool $escape_wildcards)
 
 quoteBoolean (bool $value, bool $quote, bool $escape_wildcards)
 
 quoteDate (string $value, bool $quote, bool $escape_wildcards)
 
 quoteTimestamp (int $value, bool $quote, bool $escape_wildcards)
 
 quoteTime (int $value, bool $quote, bool $escape_wildcards)
 
 quoteFloat (string $value, bool $quote, bool $escape_wildcards)
 
 quoteDecimal (string $value, bool $quote, bool $escape_wildcards)
 
 retrieveLOB (array &$lob)
 
 readLOB (array $lob, int $length)
 
 endOfLOB (array $lob)
 
 mapNativeDatatypeInternal (array $field)
 

Additional Inherited Members

- Data Fields inherited from ilDBPdoFieldDefinition
array $lobs
 
const DEFAULT_DECIMAL_PLACES = 2
 
const DEFAULT_TEXT_LENGTH = 4000
 
const DEFINITION_COLUMN_NAME = "/^[a-z]+[_a-z0-9]*$/"
 
const DEFINITION_TABLE_NAME = "/^[a-z]+[_a-z0-9]*$/"
 
const INDEX_FORMAT = '%s_idx'
 
const SEQUENCE_COLUMNS_NAME = 'sequence'
 
const SEQUENCE_FORMAT = '%s_seq'
 
const T_BLOB = 'blob'
 
const T_CLOB = 'clob'
 
const T_DATE = 'date'
 
const T_DATETIME = 'datetime'
 
const T_FLOAT = 'float'
 
const T_INTEGER = 'integer'
 
const T_TEXT = 'text'
 
const T_TIME = 'time'
 
const T_TIMESTAMP = 'timestamp'
 
array $allowed_attributes_old
 
array $allowed_attributes
 
- Protected Attributes inherited from ilDBPdoFieldDefinition
ilDBInterface $db_instance
 
array $max_length
 
array $available_types
 
array $reserved_mysql
 
array $reserved_postgres
 
ilMySQLQueryUtils $query_utils = null
 
array $valid_default_values
 
- Static Protected Attributes inherited from ilDBPdoFieldDefinition
static ilDBPdoFieldDefinition $instance
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilDBPdoMySQLFieldDefinition

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 26 of file class.ilDBPdoMySQLFieldDefinition.php.

Member Function Documentation

◆ getIntegerDeclaration()

ilDBPdoMySQLFieldDefinition::getIntegerDeclaration ( string  $name,
array  $field 
)
protected
Exceptions

ilDatabaseException

Reimplemented from ilDBPdoFieldDefinition.

Definition at line 127 of file class.ilDBPdoMySQLFieldDefinition.php.

127 : string
128 {
129 $db = $this->getDBInstance();
130
131 $default = $autoinc = '';
132 if (!empty($field['autoincrement'])) {
133 $autoinc = ' AUTO_INCREMENT PRIMARY KEY';
134 } elseif (array_key_exists('default', $field)) {
135 if ($field['default'] === '') {
136 $field['default'] = empty($field['notnull']) ? null : 0;
137 }
138 $default = ' DEFAULT ' . $this->quote($field['default'], 'integer');
139 } elseif (empty($field['notnull'])) {
140 $default = ' DEFAULT NULL';
141 }
142
143 $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
144 $unsigned = empty($field['unsigned']) ? '' : ' UNSIGNED';
145 $name = $db->quoteIdentifier($name, true);
146
147 return $name . ' ' . $this->getTypeDeclaration($field) . $unsigned . $default . $notnull . $autoinc;
148 }
quote($value, ?string $type=null, bool $quote=true, bool $escape_wildcards=false)
if($format !==null) $name
Definition: metadata.php:247

References $name, ilDBPdoFieldDefinition\getDBInstance(), getTypeDeclaration(), and ilDBPdoFieldDefinition\quote().

+ Here is the call graph for this function:

◆ getTypeDeclaration()

ilDBPdoMySQLFieldDefinition::getTypeDeclaration ( array  $field)

Reimplemented from ilDBPdoFieldDefinition.

Definition at line 28 of file class.ilDBPdoMySQLFieldDefinition.php.

28 : string
29 {
30 $db = $this->getDBInstance();
31
32 switch ($field['type']) {
33 case 'text':
34 if (empty($field['length']) && array_key_exists('default', $field)) {
35 $field['length'] = $db->varchar_max_length ?? null;
36 }
37 $length = empty($field['length']) ? false : $field['length'];
38 $fixed = empty($field['fixed']) ? false : $field['fixed'];
39 if ($fixed) {
40 return $length ? 'CHAR(' . $length . ')' : 'CHAR(255)';
41 }
42 return $length ? 'VARCHAR(' . $length . ')' : 'TEXT';
43
44 case 'clob':
45 if (!empty($field['length'])) {
46 $length = $field['length'];
47 if ($length <= 255) {
48 return 'TINYTEXT';
49 }
50
51 if ($length <= 65532) {
52 return 'TEXT';
53 }
54
55 if ($length <= 16_777_215) {
56 return 'MEDIUMTEXT';
57 }
58 }
59
60 return 'LONGTEXT';
61 case 'blob':
62 if (!empty($field['length'])) {
63 $length = $field['length'];
64 if ($length <= 255) {
65 return 'TINYBLOB';
66 }
67
68 if ($length <= 65532) {
69 return 'BLOB';
70 }
71
72 if ($length <= 16_777_215) {
73 return 'MEDIUMBLOB';
74 }
75 }
76
77 return 'LONGBLOB';
78 case 'integer':
79 if (!empty($field['length'])) {
80 $length = $field['length'];
81 if ($length <= 1) {
82 return 'TINYINT';
83 }
84
85 if ($length === 2) {
86 return 'SMALLINT';
87 }
88
89 if ($length === 3) {
90 return 'MEDIUMINT';
91 }
92
93 if ($length === 4) {
94 return 'INT';
95 }
96
97 if ($length > 4) {
98 return 'BIGINT';
99 }
100 }
101
102 return 'INT';
103 case 'boolean':
104 return 'TINYINT(1)';
105 case 'date':
106 return 'DATE';
107 case 'time':
108 return 'TIME';
109 case 'timestamp':
110 return 'DATETIME';
111 case 'float':
112 return 'DOUBLE';
113 case 'decimal':
114 $length = empty($field['length']) ? 18 : $field['length'];
115 $scale = empty($field['scale']) ? $db->options['decimal_places'] : $field['scale'];
116
117 return 'DECIMAL(' . $length . ',' . $scale . ')';
118 }
119
120 return '';
121 }

References ilDBPdoFieldDefinition\getDBInstance().

Referenced by getIntegerDeclaration().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapNativeDatatypeInternal()

ilDBPdoMySQLFieldDefinition::mapNativeDatatypeInternal ( array  $field)
protected
Exceptions

ilDatabaseException

Reimplemented from ilDBPdoFieldDefinition.

Definition at line 154 of file class.ilDBPdoMySQLFieldDefinition.php.

154 : array
155 {
156 $db_type = strtolower($field['type']);
157 $db_type = strtok($db_type, '(), ');
158 if ($db_type === 'national') {
159 $db_type = strtok('(), ');
160 }
161 if (!empty($field['length'])) {
162 $length = strtok($field['length'], ', ');
163 $decimal = strtok(', ');
164 } else {
165 $length = strtok('(), ');
166 $decimal = strtok('(), ');
167 }
168 $type = array();
169 $unsigned = $fixed = null;
170 switch ($db_type) {
171 case 'tinyint':
172 $type[] = 'integer';
173 $type[] = 'boolean';
174 if (preg_match('/^(is|has)/', $field['name'])) {
175 $type = array_reverse($type);
176 }
177 $unsigned = preg_match('/ unsigned/i', $field['type']);
178 $length = 1;
179 break;
180 case 'smallint':
181 $type[] = 'integer';
182 $unsigned = preg_match('/ unsigned/i', $field['type']);
183 $length = 2;
184 break;
185 case 'mediumint':
186 $type[] = 'integer';
187 $unsigned = preg_match('/ unsigned/i', $field['type']);
188 $length = 3;
189 break;
190 case 'int':
191 case 'integer':
192 $type[] = 'integer';
193 $unsigned = preg_match('/ unsigned/i', $field['type']);
194 $length = 4;
195 break;
196 case 'bigint':
197 $type[] = 'integer';
198 $unsigned = preg_match('/ unsigned/i', $field['type']);
199 $length = 8;
200 break;
201 case 'tinytext':
202 case 'mediumtext':
203 case 'longtext':
204 case 'text':
205 case 'varchar':
206 $fixed = false;
207 // no break
208 case 'string':
209 case 'char':
210 $type[] = 'text';
211 if ($length == '1') {
212 $type[] = 'boolean';
213 if (preg_match('/^(is|has)/', $field['name'])) {
214 $type = array_reverse($type);
215 }
216 } elseif (strpos($db_type, 'text') !== false) {
217 $type[] = 'clob';
218 if ($decimal === 'binary') {
219 $type[] = 'blob';
220 }
221 }
222 if ($fixed !== false) {
223 $fixed = true;
224 }
225 break;
226 case 'enum':
227 $type[] = 'text';
228 preg_match_all('/\'.+\'/U', $field['type'], $matches);
229 $length = 0;
230 $fixed = false;
231 if (is_array($matches)) {
232 foreach ($matches[0] as $value) {
233 $length = max($length, strlen($value) - 2);
234 }
235 if ($length == '1' && count($matches[0]) === 2) {
236 $type[] = 'boolean';
237 if (preg_match('/^(is|has)/', $field['name'])) {
238 $type = array_reverse($type);
239 }
240 }
241 }
242 $type[] = 'integer';
243 // no break
244 case 'set':
245 $fixed = false;
246 $type[] = 'text';
247 $type[] = 'integer';
248 break;
249 case 'date':
250 $type[] = 'date';
251 $length = null;
252 break;
253 case 'datetime':
254 case 'timestamp':
255 $type[] = 'timestamp';
256 $length = null;
257 break;
258 case 'time':
259 $type[] = 'time';
260 $length = null;
261 break;
262 case 'float':
263 case 'double':
264 case 'real':
265 $type[] = 'float';
266 $unsigned = preg_match('/ unsigned/i', $field['type']);
267 break;
268 case 'unknown':
269 case 'decimal':
270 case 'numeric':
271 $type[] = 'decimal';
272 $unsigned = preg_match('/ unsigned/i', $field['type']);
273 if ($decimal !== false) {
274 $length = $length . ',' . $decimal;
275 }
276 break;
277 case 'tinyblob':
278 case 'mediumblob':
279 case 'longblob':
280 case 'blob':
281 $type[] = 'blob';
282 $length = null;
283 break;
284 case 'binary':
285 case 'varbinary':
286 $type[] = 'blob';
287 break;
288 case 'year':
289 $type[] = 'integer';
290 $type[] = 'date';
291 $length = null;
292 break;
293 default:
294 throw new ilDatabaseException('unknown database attribute type: ' . $db_type);
295 }
296
297 if ((int) $length <= 0) {
298 $length = null;
299 }
300
301 return array( $type, $length, $unsigned, $fixed );
302 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type

References $type.


The documentation for this class was generated from the following file: