2 require_once(
'./Services/Database/classes/PDO/FieldDefinition/class.ilDBPdoFieldDefinition.php');
18 switch ($field[
'type']) {
20 if (empty($field[
'length']) && array_key_exists(
'default', $field)) {
21 $field[
'length'] = $db->varchar_max_length;
23 $length = !empty($field[
'length']) ? $field[
'length'] :
false;
24 $fixed = !empty($field[
'fixed']) ? $field[
'fixed'] :
false;
26 return $fixed ? ($length ?
'CHAR(' . $length .
')' :
'CHAR(255)') : ($length ?
'VARCHAR(' . $length .
')' :
'TEXT');
28 if (!empty($field[
'length'])) {
29 $length = $field[
'length'];
32 } elseif ($length <= 65532) {
34 } elseif ($length <= 16777215) {
41 if (!empty($field[
'length'])) {
42 $length = $field[
'length'];
45 } elseif ($length <= 65532) {
47 } elseif ($length <= 16777215) {
54 if (!empty($field[
'length'])) {
55 $length = $field[
'length'];
58 } elseif ($length == 2) {
60 } elseif ($length == 3) {
62 } elseif ($length == 4) {
64 } elseif ($length > 4) {
81 $length = !empty($field[
'length']) ? $field[
'length'] : 18;
82 $scale = !empty($field[
'scale']) ? $field[
'scale'] : $db->options[
'decimal_places'];
84 return 'DECIMAL(' . $length .
',' . $scale .
')';
100 $default = $autoinc =
'';
101 if (!empty($field[
'autoincrement'])) {
102 $autoinc =
' AUTO_INCREMENT PRIMARY KEY';
103 } elseif (array_key_exists(
'default', $field)) {
104 if ($field[
'default'] ===
'') {
105 $field[
'default'] = empty($field[
'notnull']) ? null : 0;
107 $default =
' DEFAULT ' . $this->
quote($field[
'default'],
'integer');
108 } elseif (empty($field[
'notnull'])) {
109 $default =
' DEFAULT NULL';
112 $notnull = empty($field[
'notnull']) ?
'' :
' NOT NULL';
113 $unsigned = empty($field[
'unsigned']) ?
'' :
' UNSIGNED';
114 $name = $db->quoteIdentifier($name,
true);
116 return $name .
' ' . $this->
getTypeDeclaration($field) . $unsigned . $default . $notnull . $autoinc;
126 $db_type = strtolower($field[
'type']);
127 $db_type = strtok($db_type,
'(), ');
128 if ($db_type ==
'national') {
129 $db_type = strtok(
'(), ');
131 if (!empty($field[
'length'])) {
132 $length = strtok($field[
'length'],
', ');
133 $decimal = strtok(
', ');
135 $length = strtok(
'(), ');
136 $decimal = strtok(
'(), ');
139 $unsigned = $fixed = null;
144 if (preg_match(
'/^(is|has)/', $field[
'name'])) {
145 $type = array_reverse($type);
147 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
152 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
157 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
163 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
168 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
181 if ($length ==
'1') {
183 if (preg_match(
'/^(is|has)/', $field[
'name'])) {
184 $type = array_reverse($type);
186 } elseif (strstr($db_type,
'text')) {
188 if ($decimal ==
'binary') {
192 if ($fixed !==
false) {
198 preg_match_all(
'/\'.+\'/U', $field[
'type'], $matches);
201 if (is_array($matches)) {
202 foreach ($matches[0] as $value) {
203 $length = max($length, strlen($value) - 2);
205 if ($length ==
'1' && count($matches[0]) == 2) {
207 if (preg_match(
'/^(is|has)/', $field[
'name'])) {
208 $type = array_reverse($type);
224 $type[] =
'timestamp';
235 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
241 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
242 if ($decimal !==
false) {
243 $length = $length .
',' . $decimal;
266 if ((
int)$length <= 0) {
270 return array( $type, $length, $unsigned, $fixed );
getIntegerDeclaration($name, $field)
mapNativeDatatypeInternal($field)
quote($value, $type=null, $quote=true, $escape_wildcards=false)
Class ilDBPdoFieldDefinition.
Class ilDatabaseException.
Create styles array
The data for the language used.
Class ilDBPdoMySQLFieldDefinition.
getTypeDeclaration($field)