2 require_once(
'./Services/Database/classes/PDO/FieldDefinition/class.ilDBPdoFieldDefinition.php');
20 switch ($field[
'type']) {
22 if (empty($field[
'length']) && array_key_exists(
'default', $field)) {
23 $field[
'length'] = $db->varchar_max_length;
25 $length = !empty($field[
'length']) ? $field[
'length'] :
false;
26 $fixed = !empty($field[
'fixed']) ? $field[
'fixed'] :
false;
28 return $fixed ? ($length ?
'CHAR(' . $length .
')' :
'CHAR(255)') : ($length ?
'VARCHAR(' . $length .
')' :
'TEXT');
30 if (!empty($field[
'length'])) {
31 $length = $field[
'length'];
34 } elseif ($length <= 65532) {
36 } elseif ($length <= 16777215) {
43 if (!empty($field[
'length'])) {
44 $length = $field[
'length'];
47 } elseif ($length <= 65532) {
49 } elseif ($length <= 16777215) {
56 if (!empty($field[
'length'])) {
57 $length = $field[
'length'];
60 } elseif ($length == 2) {
62 } elseif ($length == 3) {
64 } elseif ($length == 4) {
66 } elseif ($length > 4) {
83 $length = !empty($field[
'length']) ? $field[
'length'] : 18;
84 $scale = !empty($field[
'scale']) ? $field[
'scale'] : $db->options[
'decimal_places'];
86 return 'DECIMAL(' . $length .
',' . $scale .
')';
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;
110 $default =
' DEFAULT ' . $this->
quote($field[
'default'],
'integer');
111 } elseif (empty($field[
'notnull'])) {
115 $notnull = empty($field[
'notnull']) ?
'' :
' NOT NULL';
116 $unsigned = empty($field[
'unsigned']) ?
'' :
' UNSIGNED';
130 $db_type = strtolower($field[
'type']);
131 $db_type = strtok($db_type,
'(), ');
132 if ($db_type ==
'national') {
133 $db_type = strtok(
'(), ');
135 if (!empty($field[
'length'])) {
136 $length = strtok($field[
'length'],
', ');
137 $decimal = strtok(
', ');
139 $length = strtok(
'(), ');
140 $decimal = strtok(
'(), ');
143 $unsigned = $fixed = null;
148 if (preg_match(
'/^(is|has)/', $field[
'name'])) {
151 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
156 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
161 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
167 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
172 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
186 if ($length ==
'1') {
188 if (preg_match(
'/^(is|has)/', $field[
'name'])) {
191 } elseif (strstr($db_type,
'text')) {
193 if ($decimal ==
'binary') {
197 if ($fixed !==
false) {
203 preg_match_all(
'/\'.+\'/U', $field[
'type'], $matches);
206 if (is_array($matches)) {
207 foreach ($matches[0] as $value) {
208 $length = max($length, strlen($value) - 2);
210 if ($length ==
'1' && count($matches[0]) == 2) {
212 if (preg_match(
'/^(is|has)/', $field[
'name'])) {
230 $type[] =
'timestamp';
241 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
247 $unsigned = preg_match(
'/ unsigned/i', $field[
'type']);
248 if ($decimal !==
false) {
249 $length = $length .
',' . $decimal;
272 if ((
int) $length <= 0) {
276 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)