ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 99 of file class.ilDBPdoMySQLFieldDefinition.php.

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

References $default, $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 16 of file class.ilDBPdoMySQLFieldDefinition.php.

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

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

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

References $type.


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