ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
ilDBPdoMySQLFieldDefinition Class Reference

Class ilDBPdoMySQLFieldDefinition. More...

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

Public Member Functions

 __construct (protected \ilDBInterface $db_instance)
 
 checkTableName (string $table_name)
 
 isReserved (string $table_name)
 
 getAllReserved ()
 
 getReservedMysql ()
 
 setReservedMysql (array $reserved_mysql)
 
 checkColumnName (string $column_name)
 
 checkIndexName (string $a_name)
 
 checkColumnDefinition (array $a_def)
 
 isAllowedAttribute (string $attribute, string $type)
 
 getAvailableTypes ()
 
 setAvailableTypes (array $available_types)
 
 getAllowedAttributes ()
 
 setAllowedAttributes (array $allowed_attributes)
 
 getMaxLength ()
 
 setMaxLength (array $max_length)
 
 getValidTypes ()
 
 getDeclaration (string $type, string $name, array $field)
 
 compareDefinition (array $current, array $previous)
 
 quote ($value, ?string $type=null, bool $quote=true, bool $escape_wildcards=false)
 
 writeLOBToFile ($lob, string $file)
 
 destroyLOB ($lob)
 
 matchPattern (array $pattern, $operator=null, $field=null)
 
 patternEscapeString ()
 
 mapNativeDatatype (array $field)
 
 mapPrepareDatatype (string $type)
 
 getTypeDeclaration (array $field)
 
 checkTableName (string $table_name)
 
 isReserved (string $table_name)
 
 getAllReserved ()
 
 getReservedMysql ()
 
 setReservedMysql (array $reserved_mysql)
 
 checkColumnName (string $column_name)
 
 checkIndexName (string $a_name)
 
 checkColumnDefinition (array $a_def)
 
 isAllowedAttribute (string $attribute, string $type)
 
 getAvailableTypes ()
 
 setAvailableTypes (array $available_types)
 
 getAllowedAttributes ()
 
 setAllowedAttributes (array $allowed_attributes)
 
 getMaxLength ()
 
 setMaxLength (array $max_length)
 
 getValidTypes ()
 
 getDeclaration (string $type, string $name, array $field)
 
 getTypeDeclaration (array $field)
 
 compareDefinition (array $current, array $previous)
 
 quote ($value, ?string $type=null, bool $quote=true, bool $escape_wildcards=false)
 
 writeLOBToFile ($lob, string $file)
 
 destroyLOB ($lob)
 
 matchPattern (array $pattern, $operator=null, $field=null)
 
 patternEscapeString ()
 
 mapNativeDatatype (array $field)
 
 mapPrepareDatatype (string $type)
 

Data Fields

array $lobs
 
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]*$/"
 
array $allowed_attributes_old
 
array $allowed_attributes
 
- Data Fields inherited from ILIAS\Database\FieldDefinition
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'
 

Protected Attributes

array $max_length
 
array $available_types
 
array $reserved_mysql
 
array $reserved_postgres
 
ilMySQLQueryUtils $query_utils = null
 
array $valid_default_values
 

Static Protected Attributes

static self $instance
 

Private Member Functions

 getDBInstance ()
 
 mapNativeDatatypeInternal (array $field)
 

Private Attributes

const MAX_TABLE_IDENTIFIER_LENGTH = 63
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilDBPdoMySQLFieldDefinition::__construct ( protected \ilDBInterface  $db_instance)

Definition at line 815 of file ilDBPdoMySQLFieldDefinition.php.

816 {
817 }

Member Function Documentation

◆ checkColumnDefinition()

ilDBPdoMySQLFieldDefinition::checkColumnDefinition ( array  $a_def)
Exceptions

ilDatabaseException

Implements ILIAS\Database\FieldDefinition.

Definition at line 935 of file ilDBPdoMySQLFieldDefinition.php.

935 : bool
936 {
937 // check valid type
938 if (!in_array($a_def["type"], $this->getAvailableTypes(), true)) {
939 switch ($a_def["type"]) {
940 case "boolean":
941 throw new ilDatabaseException("Invalid column type '" . $a_def["type"] . "'. Use integer(1) instead.");
942
943 case "decimal":
944 throw new ilDatabaseException("Invalid column type '" . $a_def["type"] . "'. Use float or integer instead.");
945
946 default:
947 throw new ilDatabaseException("Invalid column type '" . $a_def["type"] . "'. Allowed types are: "
948 . implode(', ', $this->getAvailableTypes()));
949 }
950 }
951
952 // check used attributes
954 foreach (array_keys($a_def) as $k) {
955 if ($k !== "type" && !in_array($k, $allowed_attributes[$a_def["type"]], true)) {
956 throw new ilDatabaseException("Attribute '" . $k . "' is not allowed for column type '" . $a_def["type"] . "'.");
957 }
958 }
959
960 // type specific checks
961 $max_length = $this->getMaxLength();
962 switch ($a_def["type"]) {
963 case self::T_TEXT:
964 if ((!isset($a_def["length"]) || $a_def["length"] < 1 || $a_def["length"] > $max_length[self::T_TEXT]) && isset($a_def["length"])) {
965 throw new ilDatabaseException("Invalid length '" . $a_def["length"] . "' for type text." . " Length must be >=1 and <= "
966 . $max_length[self::T_TEXT] . ".");
967 }
968 break;
969
970 case self::T_INTEGER:
971 if (isset($a_def["length"]) && !in_array((int) $a_def["length"], $max_length[self::T_INTEGER], true)) {
972 throw new ilDatabaseException("Invalid length '" . $a_def["length"] . "' for type integer." . " Length must be "
973 . implode(', ', $max_length[self::T_INTEGER]) . " (bytes).");
974 }
975 if ($a_def["unsigned"] ?? null) {
976 throw new ilDatabaseException("Unsigned attribut must not be true for type integer.");
977 }
978 break;
979 }
980
981 return true;
982 }
Class ilDatabaseException.

References $allowed_attributes, $max_length, getAllowedAttributes(), getAvailableTypes(), getMaxLength(), ILIAS\Database\FieldDefinition\T_INTEGER, and ILIAS\Database\FieldDefinition\T_TEXT.

+ Here is the call graph for this function:

◆ checkColumnName()

ilDBPdoMySQLFieldDefinition::checkColumnName ( string  $column_name)
Exceptions

ilDatabaseException

Implements ILIAS\Database\FieldDefinition.

Definition at line 890 of file ilDBPdoMySQLFieldDefinition.php.

890 : bool
891 {
892 if (!preg_match("/^[a-z]+[_a-z0-9]*$/", $column_name)) {
893 throw new ilDatabaseException("Invalid column name '" . $column_name
894 . "'. Column name must only contain _a-z0-9 and must start with a-z.");
895 }
896
897 if ($this->isReserved($column_name)) {
898 throw new ilDatabaseException("Invalid column name '" . $column_name . "' (Reserved Word).");
899 }
900
901 if (stripos($column_name, "sys_") === 0) {
902 throw new ilDatabaseException("Invalid column name '" . $column_name . "'. Name must not start with 'sys_'.");
903 }
904
905 if (strlen($column_name) > 30) {
906 throw new ilDatabaseException("Invalid column name '" . $column_name . "'. Maximum column identifer length is 30 bytes.");
907 }
908
909 return true;
910 }

References isReserved().

+ Here is the call graph for this function:

◆ checkIndexName()

ilDBPdoMySQLFieldDefinition::checkIndexName ( string  $a_name)
Exceptions

ilDatabaseException

Implements ILIAS\Database\FieldDefinition.

Definition at line 915 of file ilDBPdoMySQLFieldDefinition.php.

915 : bool
916 {
917 if (!preg_match("/^[a-z]+[_a-z0-9]*$/", $a_name)) {
918 throw new ilDatabaseException("Invalid column name '" . $a_name . "'. Column name must only contain _a-z0-9 and must start with a-z.");
919 }
920
921 if ($this->isReserved($a_name)) {
922 throw new ilDatabaseException("Invalid column name '" . $a_name . "' (Reserved Word).");
923 }
924
925 if (strlen($a_name) > 3) {
926 throw new ilDatabaseException("Invalid index name '" . $a_name . "'. Maximum index identifer length is 3 bytes.");
927 }
928
929 return true;
930 }

References isReserved().

+ Here is the call graph for this function:

◆ checkTableName()

ilDBPdoMySQLFieldDefinition::checkTableName ( string  $table_name)
Exceptions

ilDatabaseException

Implements ILIAS\Database\FieldDefinition.

Definition at line 835 of file ilDBPdoMySQLFieldDefinition.php.

835 : bool
836 {
837 if (!preg_match(self::DEFINITION_TABLE_NAME, $table_name)) {
838 throw new ilDatabaseException('Table name must only contain _a-z0-9 and must start with a-z.');
839 }
840
841 if ($this->isReserved($table_name)) {
842 throw new ilDatabaseException("Invalid table name '" . $table_name . "' (Reserved Word).");
843 }
844
845 if (stripos($table_name, "sys_") === 0) {
846 throw new ilDatabaseException("Invalid table name '" . $table_name . "'. Name must not start with 'sys_'.");
847 }
848
849 if (strlen($table_name) > self::MAX_TABLE_IDENTIFIER_LENGTH) {
850 throw new ilDatabaseException("Invalid table name '" . $table_name
851 . "'. Maximum table identifer length is " . self::MAX_TABLE_IDENTIFIER_LENGTH . " bytes.");
852 }
853
854 return true;
855 }

References isReserved().

+ Here is the call graph for this function:

◆ compareDefinition()

ilDBPdoMySQLFieldDefinition::compareDefinition ( array  $current,
array  $previous 
)
Exceptions

ilDatabaseException

Returns
array<string, bool>

Implements ILIAS\Database\FieldDefinition.

Definition at line 1097 of file ilDBPdoMySQLFieldDefinition.php.

1097 : array
1098 {
1099 $type = empty($current['type']) ? null : $current['type'];
1100
1101 if (!method_exists($this, "compare{$type}Definition")) {
1102 $db = $this->getDBInstance();
1103
1104 if (!empty($db->options['datatype_map_callback'][$type])) {
1105 $parameter = ['current' => $current, 'previous' => $previous];
1106
1107 return call_user_func_array(
1108 $db->options['datatype_map_callback'][$type],
1109 [&$db, __FUNCTION__, $parameter]
1110 );
1111 }
1112
1113 throw new ilDatabaseException('type "' . $current['type'] . '" is not yet supported');
1114 }
1115
1116 if (empty($previous['type']) || $previous['type'] != $type) {
1117 return $current;
1118 }
1119
1120 $change = $this->{"compare{$type}Definition"}($current, $previous);
1121
1122 if ($previous['type'] != $type) {
1123 $change['type'] = true;
1124 }
1125
1126 $previous_notnull = empty($previous['notnull']) ? false : $previous['notnull'];
1127 $notnull = empty($current['notnull']) ? false : $current['notnull'];
1128 if ($previous_notnull !== $notnull) {
1129 $change['notnull'] = true;
1130 }
1131
1132 $alt = $previous_notnull ? '' : null;
1133 $previous_default = array_key_exists(
1134 'default',
1135 $previous
1136 ) ? $previous['default'] : $alt;
1137 $alt = $notnull ? '' : null;
1138 $default = array_key_exists('default', $current) ? $current['default'] : $alt;
1139 if ($previous_default !== $default) {
1140 $change['default'] = true;
1141 }
1142
1143 return $change;
1144 }

References getDBInstance().

+ Here is the call graph for this function:

◆ destroyLOB()

ilDBPdoMySQLFieldDefinition::destroyLOB (   $lob)
Parameters
resource$lob

Implements ILIAS\Database\FieldDefinition.

Definition at line 1185 of file ilDBPdoMySQLFieldDefinition.php.

1185 : bool
1186 {
1187 $lob_data = stream_get_meta_data($lob);
1188 $lob_index = $lob_data['wrapper_data']->lob_index;
1189 fclose($lob);
1190 if (isset($this->lobs[$lob_index])) {
1191 unset($this->lobs[$lob_index]);
1192 }
1193
1194 return true;
1195 }

◆ getAllowedAttributes()

ilDBPdoMySQLFieldDefinition::getAllowedAttributes ( )
Returns
array<string, string[]>

Implements ILIAS\Database\FieldDefinition.

Definition at line 1008 of file ilDBPdoMySQLFieldDefinition.php.

1008 : array
1009 {
1011 }

References $allowed_attributes.

Referenced by checkColumnDefinition().

+ Here is the caller graph for this function:

◆ getAllReserved()

ilDBPdoMySQLFieldDefinition::getAllReserved ( )
Returns
string[]

Implements ILIAS\Database\FieldDefinition.

Definition at line 865 of file ilDBPdoMySQLFieldDefinition.php.

865 : array
866 {
867 return $this->getReservedMysql();
868 }

References getReservedMysql().

+ Here is the call graph for this function:

◆ getAvailableTypes()

ilDBPdoMySQLFieldDefinition::getAvailableTypes ( )
Returns
string[]

Implements ILIAS\Database\FieldDefinition.

Definition at line 992 of file ilDBPdoMySQLFieldDefinition.php.

992 : array
993 {
995 }

References $available_types.

Referenced by checkColumnDefinition().

+ Here is the caller graph for this function:

◆ getDBInstance()

ilDBPdoMySQLFieldDefinition::getDBInstance ( )
private

Definition at line 1031 of file ilDBPdoMySQLFieldDefinition.php.

1032 {
1033 return $this->db_instance;
1034 }
Interface ilDBInterface.

Referenced by compareDefinition(), getDeclaration(), getTypeDeclaration(), getValidTypes(), mapNativeDatatype(), mapPrepareDatatype(), matchPattern(), quote(), and writeLOBToFile().

+ Here is the caller graph for this function:

◆ getDeclaration()

ilDBPdoMySQLFieldDefinition::getDeclaration ( string  $type,
string  $name,
array  $field 
)
Returns
mixed
Exceptions

ilDatabaseException

Implements ILIAS\Database\FieldDefinition.

Definition at line 1068 of file ilDBPdoMySQLFieldDefinition.php.

1069 {
1070 $db = $this->getDBInstance();
1071
1072 if (!empty($db->options['datatype_map'][$type])) {
1073 $type = $db->options['datatype_map'][$type];
1074 if (!empty($db->options['datatype_map_callback'][$type])) {
1075 $parameter = ['type' => $type, 'name' => $name, 'field' => $field];
1076
1077 return call_user_func_array(
1078 $db->options['datatype_map_callback'][$type],
1079 [&$db, __FUNCTION__, $parameter]
1080 );
1081 }
1082 $field['type'] = $type;
1083 }
1084
1085 if (!method_exists($this, "get{$type}Declaration")) {
1086 throw new ilDatabaseException('type not defined: ' . $type);
1087 }
1088
1089 return $this->{"get{$type}Declaration"}($name, $field);
1090 }

References getDBInstance().

+ Here is the call graph for this function:

◆ getMaxLength()

ilDBPdoMySQLFieldDefinition::getMaxLength ( )

Implements ILIAS\Database\FieldDefinition.

Definition at line 1021 of file ilDBPdoMySQLFieldDefinition.php.

1021 : array
1022 {
1023 return $this->max_length;
1024 }

References $max_length.

Referenced by checkColumnDefinition().

+ Here is the caller graph for this function:

◆ getReservedMysql()

ilDBPdoMySQLFieldDefinition::getReservedMysql ( )
Returns
string[]

Implements ILIAS\Database\FieldDefinition.

Definition at line 873 of file ilDBPdoMySQLFieldDefinition.php.

873 : array
874 {
876 }

References $reserved_mysql.

Referenced by getAllReserved().

+ Here is the caller graph for this function:

◆ getTypeDeclaration()

ilDBPdoMySQLFieldDefinition::getTypeDeclaration ( array  $field)

Implements ILIAS\Database\FieldDefinition.

Definition at line 1286 of file ilDBPdoMySQLFieldDefinition.php.

1286 : string
1287 {
1288 $db = $this->getDBInstance();
1289
1290 switch ($field['type']) {
1291 case 'text':
1292 if (empty($field['length']) && array_key_exists('default', $field)) {
1293 $field['length'] = $db->varchar_max_length ?? null;
1294 }
1295 $length = empty($field['length']) ? false : $field['length'];
1296 $fixed = empty($field['fixed']) ? false : $field['fixed'];
1297 if ($fixed) {
1298 return $length ? 'CHAR(' . $length . ')' : 'CHAR(255)';
1299 }
1300 return $length ? 'VARCHAR(' . $length . ')' : 'TEXT';
1301
1302 case 'clob':
1303 if (!empty($field['length'])) {
1304 $length = $field['length'];
1305 if ($length <= 255) {
1306 return 'TINYTEXT';
1307 }
1308
1309 if ($length <= 65532) {
1310 return 'TEXT';
1311 }
1312
1313 if ($length <= 16_777_215) {
1314 return 'MEDIUMTEXT';
1315 }
1316 }
1317
1318 return 'LONGTEXT';
1319 case 'blob':
1320 if (!empty($field['length'])) {
1321 $length = $field['length'];
1322 if ($length <= 255) {
1323 return 'TINYBLOB';
1324 }
1325
1326 if ($length <= 65532) {
1327 return 'BLOB';
1328 }
1329
1330 if ($length <= 16_777_215) {
1331 return 'MEDIUMBLOB';
1332 }
1333 }
1334
1335 return 'LONGBLOB';
1336 case 'integer':
1337 if (!empty($field['length'])) {
1338 $length = $field['length'];
1339 if ($length <= 1) {
1340 return 'TINYINT';
1341 }
1342
1343 if ($length === 2) {
1344 return 'SMALLINT';
1345 }
1346
1347 if ($length === 3) {
1348 return 'MEDIUMINT';
1349 }
1350
1351 if ($length === 4) {
1352 return 'INT';
1353 }
1354
1355 if ($length > 4) {
1356 return 'BIGINT';
1357 }
1358 }
1359
1360 return 'INT';
1361 case 'boolean':
1362 return 'TINYINT(1)';
1363 case 'date':
1364 return 'DATE';
1365 case 'time':
1366 return 'TIME';
1367 case 'timestamp':
1368 return 'DATETIME';
1369 case 'float':
1370 return 'DOUBLE';
1371 case 'decimal':
1372 $length = empty($field['length']) ? 18 : $field['length'];
1373 // @Todo: Change property access to method call.
1374 $scale = empty($field['scale']) ? $db->options['decimal_places'] : $field['scale'];
1375
1376 return 'DECIMAL(' . $length . ',' . $scale . ')';
1377 }
1378
1379 return '';
1380 }

References getDBInstance().

+ Here is the call graph for this function:

◆ getValidTypes()

ilDBPdoMySQLFieldDefinition::getValidTypes ( )
Returns
string[]

Implements ILIAS\Database\FieldDefinition.

Definition at line 1039 of file ilDBPdoMySQLFieldDefinition.php.

1039 : array
1040 {
1042 $db = $this->getDBInstance();
1043
1044 if (!empty($db->options['datatype_map'])) {
1045 foreach ($db->options['datatype_map'] as $type => $mapped_type) {
1046 if (array_key_exists($mapped_type, $types)) {
1047 $types[$type] = $types[$mapped_type];
1048 } elseif (!empty($db->options['datatype_map_callback'][$type])) {
1049 $parameter = ['type' => $type, 'mapped_type' => $mapped_type];
1050 $default = call_user_func_array(
1051 $db->options['datatype_map_callback'][$type],
1052 [&$db, __FUNCTION__, $parameter]
1053 );
1054 $types[$type] = $default;
1055 }
1056 }
1057 }
1058
1059 return $types;
1060 }

References $valid_default_values, and getDBInstance().

+ Here is the call graph for this function:

◆ isAllowedAttribute()

ilDBPdoMySQLFieldDefinition::isAllowedAttribute ( string  $attribute,
string  $type 
)

Implements ILIAS\Database\FieldDefinition.

Definition at line 984 of file ilDBPdoMySQLFieldDefinition.php.

984 : bool
985 {
986 return in_array($attribute, $this->allowed_attributes[$type], true);
987 }

◆ isReserved()

ilDBPdoMySQLFieldDefinition::isReserved ( string  $table_name)

Implements ILIAS\Database\FieldDefinition.

Definition at line 857 of file ilDBPdoMySQLFieldDefinition.php.

857 : bool
858 {
859 return false;
860 }

Referenced by checkColumnName(), checkIndexName(), and checkTableName().

+ Here is the caller graph for this function:

◆ mapNativeDatatype()

ilDBPdoMySQLFieldDefinition::mapNativeDatatype ( array  $field)
Returns
mixed

Implements ILIAS\Database\FieldDefinition.

Definition at line 1252 of file ilDBPdoMySQLFieldDefinition.php.

1253 {
1254 $db = $this->getDBInstance();
1255 $db_type = strtok($field['type'], '(), ');
1256 if (!empty($db->options['nativetype_map_callback'][$db_type])) {
1257 return call_user_func_array($db->options['nativetype_map_callback'][$db_type], [$db, $field]);
1258 }
1259
1260 return $this->mapNativeDatatypeInternal($field);
1261 }

References getDBInstance(), and mapNativeDatatypeInternal().

+ Here is the call graph for this function:

◆ mapNativeDatatypeInternal()

ilDBPdoMySQLFieldDefinition::mapNativeDatatypeInternal ( array  $field)
private
Exceptions

ilDatabaseException

Definition at line 1385 of file ilDBPdoMySQLFieldDefinition.php.

1385 : array
1386 {
1387 $db_type = strtolower((string) $field['type']);
1388 $db_type = strtok($db_type, '(), ');
1389 if ($db_type === 'national') {
1390 $db_type = strtok('(), ');
1391 }
1392 if (!empty($field['length'])) {
1393 $length = strtok($field['length'], ', ');
1394 $decimal = strtok(', ');
1395 } else {
1396 $length = strtok('(), ');
1397 $decimal = strtok('(), ');
1398 }
1399 $type = [];
1400 $unsigned = $fixed = null;
1401 switch ($db_type) {
1402 case 'tinyint':
1403 $type[] = 'integer';
1404 $type[] = 'boolean';
1405 if (preg_match('/^(is|has)/', (string) $field['name'])) {
1406 $type = array_reverse($type);
1407 }
1408 $unsigned = preg_match('/ unsigned/i', (string) $field['type']);
1409 $length = 1;
1410 break;
1411 case 'smallint':
1412 $type[] = 'integer';
1413 $unsigned = preg_match('/ unsigned/i', (string) $field['type']);
1414 $length = 2;
1415 break;
1416 case 'mediumint':
1417 $type[] = 'integer';
1418 $unsigned = preg_match('/ unsigned/i', (string) $field['type']);
1419 $length = 3;
1420 break;
1421 case 'int':
1422 case 'integer':
1423 $type[] = 'integer';
1424 $unsigned = preg_match('/ unsigned/i', (string) $field['type']);
1425 $length = 4;
1426 break;
1427 case 'bigint':
1428 $type[] = 'integer';
1429 $unsigned = preg_match('/ unsigned/i', (string) $field['type']);
1430 $length = 8;
1431 break;
1432 case 'tinytext':
1433 case 'mediumtext':
1434 case 'longtext':
1435 case 'text':
1436 case 'varchar':
1437 $fixed = false;
1438 // no break
1439 case 'string':
1440 case 'char':
1441 $type[] = 'text';
1442 if ($length == '1') {
1443 $type[] = 'boolean';
1444 if (preg_match('/^(is|has)/', (string) $field['name'])) {
1445 $type = array_reverse($type);
1446 }
1447 } elseif (str_contains($db_type, 'text')) {
1448 $type[] = 'clob';
1449 if ($decimal === 'binary') {
1450 $type[] = 'blob';
1451 }
1452 }
1453 if ($fixed !== false) {
1454 $fixed = true;
1455 }
1456 break;
1457 case 'enum':
1458 $type[] = 'text';
1459 preg_match_all('/\'.+\'/U', (string) $field['type'], $matches);
1460 $length = 0;
1461 $fixed = false;
1462 if (is_array($matches)) {
1463 foreach ($matches[0] as $value) {
1464 $length = max($length, strlen($value) - 2);
1465 }
1466 if ($length == '1' && count($matches[0]) === 2) {
1467 $type[] = 'boolean';
1468 if (preg_match('/^(is|has)/', (string) $field['name'])) {
1469 $type = array_reverse($type);
1470 }
1471 }
1472 }
1473 $type[] = 'integer';
1474 // no break
1475 case 'set':
1476 $fixed = false;
1477 $type[] = 'text';
1478 $type[] = 'integer';
1479 break;
1480 case 'date':
1481 $type[] = 'date';
1482 $length = null;
1483 break;
1484 case 'datetime':
1485 case 'timestamp':
1486 $type[] = 'timestamp';
1487 $length = null;
1488 break;
1489 case 'time':
1490 $type[] = 'time';
1491 $length = null;
1492 break;
1493 case 'float':
1494 case 'double':
1495 case 'real':
1496 $type[] = 'float';
1497 $unsigned = preg_match('/ unsigned/i', (string) $field['type']);
1498 break;
1499 case 'unknown':
1500 case 'decimal':
1501 case 'numeric':
1502 $type[] = 'decimal';
1503 $unsigned = preg_match('/ unsigned/i', (string) $field['type']);
1504 if ($decimal !== false) {
1505 $length = $length . ',' . $decimal;
1506 }
1507 break;
1508 case 'tinyblob':
1509 case 'mediumblob':
1510 case 'longblob':
1511 case 'blob':
1512 $type[] = 'blob';
1513 $length = null;
1514 break;
1515 case 'binary':
1516 case 'varbinary':
1517 $type[] = 'blob';
1518 break;
1519 case 'year':
1520 $type[] = 'integer';
1521 $type[] = 'date';
1522 $length = null;
1523 break;
1524 default:
1525 throw new ilDatabaseException('unknown database attribute type: ' . $db_type);
1526 }
1527
1528 if ((int) $length <= 0) {
1529 $length = null;
1530 }
1531
1532 return [ $type, $length, $unsigned, $fixed ];
1533 }

Referenced by mapNativeDatatype().

+ Here is the caller graph for this function:

◆ mapPrepareDatatype()

ilDBPdoMySQLFieldDefinition::mapPrepareDatatype ( string  $type)
Returns
mixed

Implements ILIAS\Database\FieldDefinition.

Definition at line 1266 of file ilDBPdoMySQLFieldDefinition.php.

1267 {
1268 $db = $this->getDBInstance();
1269
1270 if (!empty($db->options['datatype_map'][$type])) {
1271 $type = $db->options['datatype_map'][$type];
1272 if (!empty($db->options['datatype_map_callback'][$type])) {
1273 $parameter = ['type' => $type];
1274
1275 return call_user_func_array(
1276 $db->options['datatype_map_callback'][$type],
1277 [&$db, __FUNCTION__, $parameter]
1278 );
1279 }
1280 }
1281
1282 return $type;
1283 }

References getDBInstance().

+ Here is the call graph for this function:

◆ matchPattern()

ilDBPdoMySQLFieldDefinition::matchPattern ( array  $pattern,
  $operator = null,
  $field = null 
)
Exceptions

ilDatabaseException

Implements ILIAS\Database\FieldDefinition.

Definition at line 1201 of file ilDBPdoMySQLFieldDefinition.php.

1201 : string
1202 {
1203 $db = $this->getDBInstance();
1204
1205 $match = '';
1206 if (!is_null($operator)) {
1207 $operator = strtoupper((string) $operator);
1208 switch ($operator) {
1209 // case insensitive
1210 case 'ILIKE':
1211 if (is_null($field)) {
1212 throw new ilDatabaseException('case insensitive LIKE matching requires passing the field name');
1213 }
1214 $db->loadModule('Function');
1215 $match = $db->lower($field) . ' LIKE ';
1216 break;
1217 // case sensitive
1218 case 'LIKE':
1219 $match = is_null($field) ? 'LIKE ' : $field . ' LIKE ';
1220 break;
1221 default:
1222 throw new ilDatabaseException('not a supported operator type:' . $operator);
1223 }
1224 }
1225 $match .= "'";
1226 foreach ($pattern as $key => $value) {
1227 if ($key % 2 !== 0) {
1228 $match .= $value;
1229 } else {
1230 if ($operator === 'ILIKE') {
1231 $value = strtolower((string) $value);
1232 }
1233 // @Todo: ilDBPdo::escape & escapePattern do nothing, probably quote instead.
1234 $escaped = $db->escape($value);
1235 $match .= $db->escapePattern($escaped);
1236 }
1237 }
1238 $match .= "'";
1239 $match .= $this->patternEscapeString();
1240
1241 return $match;
1242 }

References getDBInstance(), and patternEscapeString().

+ Here is the call graph for this function:

◆ patternEscapeString()

ilDBPdoMySQLFieldDefinition::patternEscapeString ( )

Implements ILIAS\Database\FieldDefinition.

Definition at line 1244 of file ilDBPdoMySQLFieldDefinition.php.

1244 : string
1245 {
1246 return '';
1247 }

Referenced by matchPattern().

+ Here is the caller graph for this function:

◆ quote()

ilDBPdoMySQLFieldDefinition::quote (   $value,
?string  $type = null,
bool  $quote = true,
bool  $escape_wildcards = false 
)
Parameters
mixed$value

Implements ILIAS\Database\FieldDefinition.

Definition at line 1149 of file ilDBPdoMySQLFieldDefinition.php.

1149 : string
1150 {
1151 return $this->getDBInstance()->quote($value, $type ?? '');
1152 }

References getDBInstance().

+ Here is the call graph for this function:

◆ setAllowedAttributes()

ilDBPdoMySQLFieldDefinition::setAllowedAttributes ( array  $allowed_attributes)
Parameters
array<string,string[]>$allowed_attributes

Implements ILIAS\Database\FieldDefinition.

Definition at line 1016 of file ilDBPdoMySQLFieldDefinition.php.

1016 : void
1017 {
1018 $this->allowed_attributes = $allowed_attributes;
1019 }

References $allowed_attributes.

◆ setAvailableTypes()

ilDBPdoMySQLFieldDefinition::setAvailableTypes ( array  $available_types)
Parameters
string[]$available_types

Implements ILIAS\Database\FieldDefinition.

Definition at line 1000 of file ilDBPdoMySQLFieldDefinition.php.

1000 : void
1001 {
1002 $this->available_types = $available_types;
1003 }

References $available_types.

◆ setMaxLength()

ilDBPdoMySQLFieldDefinition::setMaxLength ( array  $max_length)

Implements ILIAS\Database\FieldDefinition.

Definition at line 1026 of file ilDBPdoMySQLFieldDefinition.php.

1026 : void
1027 {
1028 $this->max_length = $max_length;
1029 }

References $max_length.

◆ setReservedMysql()

ilDBPdoMySQLFieldDefinition::setReservedMysql ( array  $reserved_mysql)
Parameters
string[]$reserved_mysql

Implements ILIAS\Database\FieldDefinition.

Definition at line 881 of file ilDBPdoMySQLFieldDefinition.php.

881 : void
882 {
883 $this->reserved_mysql = $reserved_mysql;
884 }

References $reserved_mysql.

◆ writeLOBToFile()

ilDBPdoMySQLFieldDefinition::writeLOBToFile (   $lob,
string  $file 
)
Parameters
resource$lob
Exceptions

ilDatabaseException

Implements ILIAS\Database\FieldDefinition.

Definition at line 1159 of file ilDBPdoMySQLFieldDefinition.php.

1159 : bool
1160 {
1161 $db = $this->getDBInstance();
1162
1163 if (preg_match('/^(\w+:\/\/)(.*)$/', $file, $match) && $match[1] === 'file://') {
1164 $file = $match[2];
1165 }
1166
1167 $fp = @fopen($file, 'wb');
1168 while (!@feof($lob)) {
1169 $result = @fread($lob, $db->options['lob_buffer_length']);
1170 $read = strlen($result);
1171 if (@fwrite($fp, $result, $read) !== $read) {
1172 @fclose($fp);
1173
1174 throw new ilDatabaseException('could not write to the output file');
1175 }
1176 }
1177 @fclose($fp);
1178
1179 return true;
1180 }

References getDBInstance().

+ Here is the call graph for this function:

Field Documentation

◆ $allowed_attributes

array ilDBPdoMySQLFieldDefinition::$allowed_attributes
Initial value:
= [
"text" => ["length", "notnull", "default", "fixed"],
"integer" => ["length", "notnull", "default", "unsigned"],
"float" => ["notnull", "default"],
"date" => ["notnull", "default"],
"time" => ["notnull", "default"],
"timestamp" => ["notnull", "default"],
"clob" => ["length", "notnull", "default"],
"blob" => ["length", "notnull", "default"],
]

Definition at line 55 of file ilDBPdoMySQLFieldDefinition.php.

Referenced by checkColumnDefinition(), getAllowedAttributes(), and setAllowedAttributes().

◆ $allowed_attributes_old

array ilDBPdoMySQLFieldDefinition::$allowed_attributes_old
Initial value:
= [
self::T_TEXT => ['length', 'notnull', 'default', 'fixed'],
self::T_INTEGER => ['length', 'notnull', 'default', 'unsigned'],
self::T_FLOAT => ['notnull', 'default'],
self::T_DATE => ['notnull', 'default'],
self::T_TIME => ['notnull', 'default'],
self::T_TIMESTAMP => ['notnull', 'default'],
self::T_CLOB => ['notnull', 'default'],
self::T_BLOB => ['notnull', 'default'],
]

Definition at line 42 of file ilDBPdoMySQLFieldDefinition.php.

◆ $available_types

◆ $instance

self ilDBPdoMySQLFieldDefinition::$instance
staticprotected

Definition at line 38 of file ilDBPdoMySQLFieldDefinition.php.

◆ $lobs

array ilDBPdoMySQLFieldDefinition::$lobs

Definition at line 30 of file ilDBPdoMySQLFieldDefinition.php.

◆ $max_length

array ilDBPdoMySQLFieldDefinition::$max_length
protected
Initial value:
= [
self::T_INTEGER => [1, 2, 3, 4, 8],
self::T_TEXT => 4000,
]

Definition at line 65 of file ilDBPdoMySQLFieldDefinition.php.

Referenced by checkColumnDefinition(), getMaxLength(), and setMaxLength().

◆ $query_utils

ilMySQLQueryUtils ilDBPdoMySQLFieldDefinition::$query_utils = null
protected

Definition at line 813 of file ilDBPdoMySQLFieldDefinition.php.

◆ $reserved_mysql

array ilDBPdoMySQLFieldDefinition::$reserved_mysql
protected

Definition at line 85 of file ilDBPdoMySQLFieldDefinition.php.

Referenced by getReservedMysql(), and setReservedMysql().

◆ $reserved_postgres

array ilDBPdoMySQLFieldDefinition::$reserved_postgres
protected

Definition at line 715 of file ilDBPdoMySQLFieldDefinition.php.

◆ $valid_default_values

array ilDBPdoMySQLFieldDefinition::$valid_default_values
protected
Initial value:
= [
'text' => '',
'boolean' => true,
'integer' => 0,
'decimal' => 0.0,
'float' => 0.0,
'timestamp' => '1970-01-01 00:00:00',
'time' => '00:00:00',
'date' => '1970-01-01',
'clob' => '',
'blob' => '',
]

Definition at line 819 of file ilDBPdoMySQLFieldDefinition.php.

Referenced by getValidTypes().

◆ DEFAULT_DECIMAL_PLACES

const ilDBPdoMySQLFieldDefinition::DEFAULT_DECIMAL_PLACES = 2

Definition at line 31 of file ilDBPdoMySQLFieldDefinition.php.

◆ DEFAULT_TEXT_LENGTH

const ilDBPdoMySQLFieldDefinition::DEFAULT_TEXT_LENGTH = 4000

Definition at line 32 of file ilDBPdoMySQLFieldDefinition.php.

◆ DEFINITION_COLUMN_NAME

const ilDBPdoMySQLFieldDefinition::DEFINITION_COLUMN_NAME = "/^[a-z]+[_a-z0-9]*$/"

Definition at line 33 of file ilDBPdoMySQLFieldDefinition.php.

◆ DEFINITION_TABLE_NAME

const ilDBPdoMySQLFieldDefinition::DEFINITION_TABLE_NAME = "/^[a-z]+[_a-z0-9]*$/"

Definition at line 34 of file ilDBPdoMySQLFieldDefinition.php.

◆ MAX_TABLE_IDENTIFIER_LENGTH

const ilDBPdoMySQLFieldDefinition::MAX_TABLE_IDENTIFIER_LENGTH = 63
private

Definition at line 36 of file ilDBPdoMySQLFieldDefinition.php.


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