19 switch ($field[
'type']) {
21 if (empty($field[
'length']) && array_key_exists(
'default', $field)) {
22 $field[
'length'] = $db->varchar_max_length ?? null;
24 $length = !empty($field[
'length']) ? $field[
'length'] :
false;
25 $fixed = !empty($field[
'fixed']) ? $field[
'fixed'] :
false;
27 return $fixed ? ($length ?
'CHAR(' . $length .
')' :
'CHAR(255)') : ($length ?
'VARCHAR(' . $length .
')' :
'TEXT');
29 if (!empty($field[
'length'])) {
30 $length = $field[
'length'];
33 } elseif ($length <= 65532) {
35 } elseif ($length <= 16777215) {
42 if (!empty($field[
'length'])) {
43 $length = $field[
'length'];
46 } elseif ($length <= 65532) {
48 } elseif ($length <= 16777215) {
55 if (!empty($field[
'length'])) {
56 $length = $field[
'length'];
59 } elseif ($length == 2) {
61 } elseif ($length == 3) {
63 } elseif ($length == 4) {
65 } elseif ($length > 4) {
82 $length = !empty($field[
'length']) ? $field[
'length'] : 18;
83 $scale = !empty($field[
'scale']) ? $field[
'scale'] : $db->options[
'decimal_places'];
85 return 'DECIMAL(' . $length .
',' . $scale .
')';
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;
109 $default =
' DEFAULT ' . $this->
quote($field[
'default'],
'integer');
110 } elseif (empty($field[
'notnull'])) {
111 $default =
' DEFAULT NULL';
114 $notnull = empty($field[
'notnull']) ?
'' :
' NOT NULL';
115 $unsigned = empty($field[
'unsigned']) ?
'' :
' UNSIGNED';
129 $db_type = strtolower($field[
'type']);
130 $db_type = strtok($db_type,
'(), ');
131 if ($db_type ==
'national') {
132 $db_type = strtok(
'(), ');
134 if (!empty($field[
'length'])) {
135 $length = strtok($field[
'length'],
', ');
136 $decimal = strtok(
', ');
138 $length = strtok(
'(), ');
139 $decimal = strtok(
'(), ');
142 $unsigned = $fixed = null;
147 if (preg_match(
'/^(is|has)/', $field[
'name'])) {
150 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
155 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
160 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
166 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
171 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
185 if ($length ==
'1') {
187 if (preg_match(
'/^(is|has)/', $field[
'name'])) {
190 } elseif (strstr($db_type,
'text')) {
192 if ($decimal ==
'binary') {
196 if ($fixed !==
false) {
202 preg_match_all(
'/\'.+\'/U', $field[
'type'], $matches);
205 if (is_array($matches)) {
206 foreach ($matches[0] as $value) {
207 $length = max($length, strlen($value) - 2);
209 if ($length ==
'1' && count($matches[0]) == 2) {
211 if (preg_match(
'/^(is|has)/', $field[
'name'])) {
229 $type[] =
'timestamp';
240 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
246 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
247 if ($decimal !==
false) {
248 $length = $length .
',' . $decimal;
271 if ((
int) $length <= 0) {
275 return array(
$type, $length, $unsigned, $fixed );
getIntegerDeclaration($name, $field)
mapNativeDatatypeInternal($field)
quote($value, $type=null, $quote=true, $escape_wildcards=false)
Class ilDBPdoFieldDefinition.
Class ilDatabaseException.
Class ilDBPdoMySQLFieldDefinition.
getTypeDeclaration($field)