ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilDBPdoMySQLFieldDefinition Class Reference

Class ilDBPdoMySQLFieldDefinition. More...

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

Public Member Functions

 getTypeDeclaration (array $field)
 
- Public Member Functions inherited from ilDBPdoFieldDefinition
 __construct (protected \ilDBInterface $db_instance)
 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, array $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
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

Member Function Documentation

◆ getIntegerDeclaration()

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

ilDatabaseException

Reimplemented from ilDBPdoFieldDefinition.

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

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

References 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 29 of file class.ilDBPdoMySQLFieldDefinition.php.

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

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 156 of file class.ilDBPdoMySQLFieldDefinition.php.

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

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