ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilDBPdoMySQLFieldDefinition Class Reference

Class ilDBPdoMySQLFieldDefinition. More...

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

Public Member Functions

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

Protected Member Functions

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

Additional Inherited Members

- Data Fields inherited from ilDBPdoFieldDefinition
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'
 
 $allowed_attributes_old
 
 $allowed_attributes
 
- Protected Attributes inherited from ilDBPdoFieldDefinition
 $db_instance
 
 $max_length
 
 $available_types
 
 $reserved_mysql
 
 $reserved_postgres
 
 $query_utils
 
 $valid_default_values
 
- Static Protected Attributes inherited from ilDBPdoFieldDefinition
static $instance
 

Detailed Description

Member Function Documentation

◆ getIntegerDeclaration()

ilDBPdoMySQLFieldDefinition::getIntegerDeclaration (   $name,
  $field 
)
protected
Parameters
$name
$field
Returns
\ilDBPdo|string
Exceptions

ilDatabaseException

Reimplemented from ilDBPdoFieldDefinition.

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

99 {
100 $db = $this->getDBInstance();
101
102 $default = $autoinc = '';
103 if (!empty($field['autoincrement'])) {
104 $autoinc = ' AUTO_INCREMENT PRIMARY KEY';
105 } elseif (array_key_exists('default', $field)) {
106 if ($field['default'] === '') {
107 $field['default'] = empty($field['notnull']) ? null : 0;
108 }
109 $default = ' DEFAULT ' . $this->quote($field['default'], 'integer');
110 } elseif (empty($field['notnull'])) {
111 $default = ' DEFAULT NULL';
112 }
113
114 $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
115 $unsigned = empty($field['unsigned']) ? '' : ' UNSIGNED';
116 $name = $db->quoteIdentifier($name, true);
117
118 return $name . ' ' . $this->getTypeDeclaration($field) . $unsigned . $default . $notnull . $autoinc;
119 }
quote($value, $type=null, $quote=true, $escape_wildcards=false)
if($format !==null) $name
Definition: metadata.php:230

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

+ Here is the call graph for this function:

◆ getTypeDeclaration()

ilDBPdoMySQLFieldDefinition::getTypeDeclaration (   $field)
Parameters
$field
Returns
\ilDBPdo|string

Reimplemented from ilDBPdoFieldDefinition.

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

16 {
17 $db = $this->getDBInstance();
18
19 switch ($field['type']) {
20 case 'text':
21 if (empty($field['length']) && array_key_exists('default', $field)) {
22 $field['length'] = $db->varchar_max_length ?? null;
23 }
24 $length = !empty($field['length']) ? $field['length'] : false;
25 $fixed = !empty($field['fixed']) ? $field['fixed'] : false;
26
27 return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)') : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
28 case 'clob':
29 if (!empty($field['length'])) {
30 $length = $field['length'];
31 if ($length <= 255) {
32 return 'TINYTEXT';
33 } elseif ($length <= 65532) {
34 return 'TEXT';
35 } elseif ($length <= 16777215) {
36 return 'MEDIUMTEXT';
37 }
38 }
39
40 return 'LONGTEXT';
41 case 'blob':
42 if (!empty($field['length'])) {
43 $length = $field['length'];
44 if ($length <= 255) {
45 return 'TINYBLOB';
46 } elseif ($length <= 65532) {
47 return 'BLOB';
48 } elseif ($length <= 16777215) {
49 return 'MEDIUMBLOB';
50 }
51 }
52
53 return 'LONGBLOB';
54 case 'integer':
55 if (!empty($field['length'])) {
56 $length = $field['length'];
57 if ($length <= 1) {
58 return 'TINYINT';
59 } elseif ($length == 2) {
60 return 'SMALLINT';
61 } elseif ($length == 3) {
62 return 'MEDIUMINT';
63 } elseif ($length == 4) {
64 return 'INT';
65 } elseif ($length > 4) {
66 return 'BIGINT';
67 }
68 }
69
70 return 'INT';
71 case 'boolean':
72 return 'TINYINT(1)';
73 case 'date':
74 return 'DATE';
75 case 'time':
76 return 'TIME';
77 case 'timestamp':
78 return 'DATETIME';
79 case 'float':
80 return 'DOUBLE';
81 case 'decimal':
82 $length = !empty($field['length']) ? $field['length'] : 18;
83 $scale = !empty($field['scale']) ? $field['scale'] : $db->options['decimal_places'];
84
85 return 'DECIMAL(' . $length . ',' . $scale . ')';
86 }
87
88 return '';
89 }

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 (   $field)
protected
Parameters
$field
Returns
array
Exceptions

ilDatabaseException

Reimplemented from ilDBPdoFieldDefinition.

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

128 {
129 $db_type = strtolower($field['type']);
130 $db_type = strtok($db_type, '(), ');
131 if ($db_type == 'national') {
132 $db_type = strtok('(), ');
133 }
134 if (!empty($field['length'])) {
135 $length = strtok($field['length'], ', ');
136 $decimal = strtok(', ');
137 } else {
138 $length = strtok('(), ');
139 $decimal = strtok('(), ');
140 }
141 $type = array();
142 $unsigned = $fixed = null;
143 switch ($db_type) {
144 case 'tinyint':
145 $type[] = 'integer';
146 $type[] = 'boolean';
147 if (preg_match('/^(is|has)/', $field['name'])) {
148 $type = array_reverse($type);
149 }
150 $unsigned = preg_match('/ unsigned/i', $field['type']);
151 $length = 1;
152 break;
153 case 'smallint':
154 $type[] = 'integer';
155 $unsigned = preg_match('/ unsigned/i', $field['type']);
156 $length = 2;
157 break;
158 case 'mediumint':
159 $type[] = 'integer';
160 $unsigned = preg_match('/ unsigned/i', $field['type']);
161 $length = 3;
162 break;
163 case 'int':
164 case 'integer':
165 $type[] = 'integer';
166 $unsigned = preg_match('/ unsigned/i', $field['type']);
167 $length = 4;
168 break;
169 case 'bigint':
170 $type[] = 'integer';
171 $unsigned = preg_match('/ unsigned/i', $field['type']);
172 $length = 8;
173 break;
174 case 'tinytext':
175 case 'mediumtext':
176 case 'longtext':
177 case 'text':
178 case 'text':
179 case 'varchar':
180 $fixed = false;
181 // no break
182 case 'string':
183 case 'char':
184 $type[] = 'text';
185 if ($length == '1') {
186 $type[] = 'boolean';
187 if (preg_match('/^(is|has)/', $field['name'])) {
188 $type = array_reverse($type);
189 }
190 } elseif (strstr($db_type, 'text')) {
191 $type[] = 'clob';
192 if ($decimal == 'binary') {
193 $type[] = 'blob';
194 }
195 }
196 if ($fixed !== false) {
197 $fixed = true;
198 }
199 break;
200 case 'enum':
201 $type[] = 'text';
202 preg_match_all('/\'.+\'/U', $field['type'], $matches);
203 $length = 0;
204 $fixed = false;
205 if (is_array($matches)) {
206 foreach ($matches[0] as $value) {
207 $length = max($length, strlen($value) - 2);
208 }
209 if ($length == '1' && count($matches[0]) == 2) {
210 $type[] = 'boolean';
211 if (preg_match('/^(is|has)/', $field['name'])) {
212 $type = array_reverse($type);
213 }
214 }
215 }
216 $type[] = 'integer';
217 // no break
218 case 'set':
219 $fixed = false;
220 $type[] = 'text';
221 $type[] = 'integer';
222 break;
223 case 'date':
224 $type[] = 'date';
225 $length = null;
226 break;
227 case 'datetime':
228 case 'timestamp':
229 $type[] = 'timestamp';
230 $length = null;
231 break;
232 case 'time':
233 $type[] = 'time';
234 $length = null;
235 break;
236 case 'float':
237 case 'double':
238 case 'real':
239 $type[] = 'float';
240 $unsigned = preg_match('/ unsigned/i', $field['type']);
241 break;
242 case 'unknown':
243 case 'decimal':
244 case 'numeric':
245 $type[] = 'decimal';
246 $unsigned = preg_match('/ unsigned/i', $field['type']);
247 if ($decimal !== false) {
248 $length = $length . ',' . $decimal;
249 }
250 break;
251 case 'tinyblob':
252 case 'mediumblob':
253 case 'longblob':
254 case 'blob':
255 $type[] = 'blob';
256 $length = null;
257 break;
258 case 'binary':
259 case 'varbinary':
260 $type[] = 'blob';
261 break;
262 case 'year':
263 $type[] = 'integer';
264 $type[] = 'date';
265 $length = null;
266 break;
267 default:
268 throw new ilDatabaseException('unknown database attribute type: ' . $db_type);
269 }
270
271 if ((int) $length <= 0) {
272 $length = null;
273 }
274
275 return array( $type, $length, $unsigned, $fixed );
276 }
Class ilDatabaseException.
$type

References $type.


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