ILIAS  release_7 Revision v7.30-3-g800a261c036
ilDBPdoFieldDefinition Class Reference

Class ilDBPdoFieldDefinition. More...

+ Inheritance diagram for ilDBPdoFieldDefinition:
+ Collaboration diagram for ilDBPdoFieldDefinition:

Public Member Functions

 __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)
 

Data Fields

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 Member Functions

 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)
 

Protected Attributes

 $db_instance
 
 $max_length
 
 $available_types
 
 $reserved_mysql
 
 $reserved_postgres
 
 $query_utils
 
 $valid_default_values
 

Static Protected Attributes

static $instance
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilDBPdoFieldDefinition::__construct ( \ilDBInterface  $ilDBInterface)

ilDBPdoFieldDefinition constructor.

Parameters
\ilDBInterface$ilDBInterface

Definition at line 821 of file class.ilDBPdoFieldDefinition.php.

822 {
823 $this->db_instance = $ilDBInterface;
824 }

Member Function Documentation

◆ baseConvertResult()

ilDBPdoFieldDefinition::baseConvertResult (   $value,
  $type,
  $rtrim = true 
)
protected
Parameters
$value
$type
bool$rtrim
Returns
bool|float|int|resource|string
Exceptions

ilDatabaseException

Definition at line 1175 of file class.ilDBPdoFieldDefinition.php.

1176 {
1177 throw new ilDatabaseException("deprecated");
1178 switch ($type) {
1179 case 'text':
1180 if ($rtrim) {
1181 $value = rtrim($value);
1182 }
1183
1184 return $value;
1185 case 'integer':
1186 return intval($value);
1187 case 'boolean':
1188 return !empty($value);
1189 case 'decimal':
1190 return $value;
1191 case 'float':
1192 return doubleval($value);
1193 case 'date':
1194 return $value;
1195 case 'time':
1196 return $value;
1197 case 'timestamp':
1198 return $value;
1199 case 'clob':
1200 case 'blob':
1201 $this->lobs[] = array(
1202 'buffer' => null,
1203 'position' => 0,
1204 'lob_index' => null,
1205 'endOfLOB' => false,
1206 'resource' => $value,
1207 'value' => null,
1208 'loaded' => false,
1209 );
1210 end($this->lobs);
1211 $lob_index = key($this->lobs);
1212 $this->lobs[$lob_index]['lob_index'] = $lob_index;
1213
1214 return fopen('MDB2LOB://' . $lob_index . '@' . $this->db_index, 'r+');
1215 }
1216
1217 throw new ilDatabaseException('attempt to convert result value to an unknown type :' . $type);
1218 }
Class ilDatabaseException.
$type

References $type.

Referenced by convertResult().

+ Here is the caller graph for this function:

◆ checkColumnDefinition()

ilDBPdoFieldDefinition::checkColumnDefinition (   $a_def)
Parameters
$a_def
Returns
bool
Exceptions

ilDatabaseException

Definition at line 995 of file class.ilDBPdoFieldDefinition.php.

996 {
997 // check valid type
998 if (!in_array($a_def["type"], $this->getAvailableTypes())) {
999 switch ($a_def["type"]) {
1000 case "boolean":
1001 throw new ilDatabaseException("Invalid column type '" . $a_def["type"] . "'. Use integer(1) instead.");
1002 break;
1003
1004 case "decimal":
1005 throw new ilDatabaseException("Invalid column type '" . $a_def["type"] . "'. Use float or integer instead.");
1006 break;
1007
1008 default:
1009 throw new ilDatabaseException("Invalid column type '" . $a_def["type"] . "'. Allowed types are: "
1010 . implode(', ', $this->getAvailableTypes()));
1011 }
1012 }
1013
1014 // check used attributes
1016 foreach ($a_def as $k => $v) {
1017 if ($k != "type" && !in_array($k, $allowed_attributes[$a_def["type"]])) {
1018 throw new ilDatabaseException("Attribute '" . $k . "' is not allowed for column type '" . $a_def["type"] . "'.");
1019 }
1020 }
1021
1022 // type specific checks
1023 $max_length = $this->getMaxLength();
1024 switch ($a_def["type"]) {
1025 case self::T_TEXT:
1026 if (!isset($a_def["length"]) || $a_def["length"] < 1 || $a_def["length"] > $max_length[self::T_TEXT]) {
1027 if (isset($a_def["length"])) {
1028 throw new ilDatabaseException("Invalid length '" . $a_def["length"] . "' for type text." . " Length must be >=1 and <= "
1029 . $max_length[self::T_TEXT] . ".");
1030 }
1031 }
1032 break;
1033
1034 case self::T_INTEGER:
1035 if (isset($a_def["length"]) && !in_array($a_def["length"], $max_length[self::T_INTEGER])) {
1036 throw new ilDatabaseException("Invalid length '" . $a_def["length"] . "' for type integer." . " Length must be "
1037 . implode(', ', $max_length[self::T_INTEGER]) . " (bytes).");
1038 }
1039 if ($a_def["unsigned"] ?? null) {
1040 throw new ilDatabaseException("Unsigned attribut must not be true for type integer.");
1041 }
1042 break;
1043 }
1044
1045 return true;
1046 }

References $allowed_attributes, $max_length, getAllowedAttributes(), getAvailableTypes(), getMaxLength(), T_INTEGER, and T_TEXT.

+ Here is the call graph for this function:

◆ checkColumnName()

ilDBPdoFieldDefinition::checkColumnName (   $column_name)
Parameters
$column_name
Returns
bool
Exceptions

ilDatabaseException

Definition at line 944 of file class.ilDBPdoFieldDefinition.php.

945 {
946 if (!preg_match("/^[a-z]+[_a-z0-9]*$/", $column_name)) {
947 throw new ilDatabaseException("Invalid column name '" . $column_name
948 . "'. Column name must only contain _a-z0-9 and must start with a-z.");
949 }
950
951 if ($this->isReserved($column_name)) {
952 throw new ilDatabaseException("Invalid column name '" . $column_name . "' (Reserved Word).");
953 }
954
955 if (strtolower(substr($column_name, 0, 4)) == "sys_") {
956 throw new ilDatabaseException("Invalid column name '" . $column_name . "'. Name must not start with 'sys_'.");
957 }
958
959 if (strlen($column_name) > 30) {
960 throw new ilDatabaseException("Invalid column name '" . $column_name . "'. Maximum column identifer length is 30 bytes.");
961 }
962
963 return true;
964 }

References isReserved().

+ Here is the call graph for this function:

◆ checkIndexName()

ilDBPdoFieldDefinition::checkIndexName (   $a_name)
Parameters
$a_name
Returns
bool
Exceptions

ilDatabaseException

Definition at line 972 of file class.ilDBPdoFieldDefinition.php.

973 {
974 if (!preg_match("/^[a-z]+[_a-z0-9]*$/", $a_name)) {
975 throw new ilDatabaseException("Invalid column name '" . $a_name . "'. Column name must only contain _a-z0-9 and must start with a-z.");
976 }
977
978 if ($this->isReserved($a_name)) {
979 throw new ilDatabaseException("Invalid column name '" . $a_name . "' (Reserved Word).");
980 }
981
982 if (strlen($a_name) > 3) {
983 throw new ilDatabaseException("Invalid index name '" . $a_name . "'. Maximum index identifer length is 3 bytes.");
984 }
985
986 return true;
987 }

References isReserved().

+ Here is the call graph for this function:

◆ checkResultTypes()

ilDBPdoFieldDefinition::checkResultTypes (   $types)
protected
Parameters
$types
Returns
array|\ilDBInterface
Exceptions

ilDatabaseException

Definition at line 1152 of file class.ilDBPdoFieldDefinition.php.

1153 {
1154 $types = is_array($types) ? $types : array( $types );
1155 foreach ($types as $key => $type) {
1156 if (!isset($this->valid_default_values[$type])) {
1157 $db = $this->getDBInstance();
1158 if (empty($db->options['datatype_map'][$type])) {
1159 throw new ilDatabaseException($type . ' for ' . $key . ' is not a supported column type');
1160 }
1161 }
1162 }
1163
1164 return $types;
1165 }

References $type, and getDBInstance().

+ Here is the call graph for this function:

◆ checkTableName()

ilDBPdoFieldDefinition::checkTableName (   $table_name)
Parameters
$table_name
Returns
bool
Exceptions

ilDatabaseException

Definition at line 862 of file class.ilDBPdoFieldDefinition.php.

863 {
864 if (!preg_match(self::DEFINITION_TABLE_NAME, $table_name)) {
865 throw new ilDatabaseException('Table name must only contain _a-z0-9 and must start with a-z.');
866 }
867
868 if ($this->isReserved($table_name)) {
869 throw new ilDatabaseException("Invalid table name '" . $table_name . "' (Reserved Word).");
870 }
871
872 if (strtolower(substr($table_name, 0, 4)) == "sys_") {
873 throw new ilDatabaseException("Invalid table name '" . $table_name . "'. Name must not start with 'sys_'.");
874 }
875
876 if (strlen($table_name) > 22) {
877 throw new ilDatabaseException("Invalid table name '" . $table_name . "'. Maximum table identifer length is 22 bytes.");
878 }
879
880 return true;
881 }

References isReserved().

+ Here is the call graph for this function:

◆ compareBLOBDefinition()

ilDBPdoFieldDefinition::compareBLOBDefinition (   $current,
  $previous 
)
protected
Parameters
$current
$previous
Returns
array

Definition at line 1702 of file class.ilDBPdoFieldDefinition.php.

1703 {
1704 return $this->compareTextDefinition($current, $previous);
1705 }
compareTextDefinition($current, $previous)

References compareTextDefinition().

+ Here is the call graph for this function:

◆ compareBooleanDefinition()

ilDBPdoFieldDefinition::compareBooleanDefinition (   $current,
  $previous 
)
protected
Parameters
$current
$previous
Returns
array

Definition at line 1746 of file class.ilDBPdoFieldDefinition.php.

1747 {
1748 return array();
1749 }

◆ compareCLOBDefinition()

ilDBPdoFieldDefinition::compareCLOBDefinition (   $current,
  $previous 
)
protected
Parameters
$current
$previous
Returns
array

Definition at line 1691 of file class.ilDBPdoFieldDefinition.php.

1692 {
1693 return $this->compareTextDefinition($current, $previous);
1694 }

References compareTextDefinition().

+ Here is the call graph for this function:

◆ compareDateDefinition()

ilDBPdoFieldDefinition::compareDateDefinition (   $current,
  $previous 
)
protected
Parameters
$current
$previous
Returns
array

Definition at line 1713 of file class.ilDBPdoFieldDefinition.php.

1714 {
1715 return array();
1716 }

◆ compareDecimalDefinition()

ilDBPdoFieldDefinition::compareDecimalDefinition (   $current,
  $previous 
)
protected
Parameters
$current
$previous
Returns
array

Definition at line 1768 of file class.ilDBPdoFieldDefinition.php.

1769 {
1770 return array();
1771 }

◆ compareDefinition()

ilDBPdoFieldDefinition::compareDefinition (   $current,
  $previous 
)
Parameters
$current
$previous
Returns
\ilDBPdo|mixed
Exceptions

ilDatabaseException

Definition at line 1597 of file class.ilDBPdoFieldDefinition.php.

1598 {
1599 $type = !empty($current['type']) ? $current['type'] : null;
1600
1601 if (!method_exists($this, "compare{$type}Definition")) {
1602 $db = $this->getDBInstance();
1603
1604 if (!empty($db->options['datatype_map_callback'][$type])) {
1605 $parameter = array( 'current' => $current, 'previous' => $previous );
1606 $change = call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1607
1608 return $change;
1609 }
1610
1611 throw new ilDatabaseException('type "' . $current['type'] . '" is not yet supported');
1612 }
1613
1614 if (empty($previous['type']) || $previous['type'] != $type) {
1615 return $current;
1616 }
1617
1618 $change = $this->{"compare{$type}Definition"}($current, $previous);
1619
1620 if ($previous['type'] != $type) {
1621 $change['type'] = true;
1622 }
1623
1624 $previous_notnull = !empty($previous['notnull']) ? $previous['notnull'] : false;
1625 $notnull = !empty($current['notnull']) ? $current['notnull'] : false;
1626 if ($previous_notnull != $notnull) {
1627 $change['notnull'] = true;
1628 }
1629
1630 $previous_default = array_key_exists('default', $previous) ? $previous['default'] : ($previous_notnull ? '' : null);
1631 $default = array_key_exists('default', $current) ? $current['default'] : ($notnull ? '' : null);
1632 if ($previous_default !== $default) {
1633 $change['default'] = true;
1634 }
1635
1636 return $change;
1637 }

References $type, and getDBInstance().

+ Here is the call graph for this function:

◆ compareFloatDefinition()

ilDBPdoFieldDefinition::compareFloatDefinition (   $current,
  $previous 
)
protected
Parameters
$current
$previous
Returns
array

Definition at line 1757 of file class.ilDBPdoFieldDefinition.php.

1758 {
1759 return array();
1760 }

◆ compareIntegerDefinition()

ilDBPdoFieldDefinition::compareIntegerDefinition (   $current,
  $previous 
)
protected
Parameters
$current
$previous
Returns
array

Definition at line 1645 of file class.ilDBPdoFieldDefinition.php.

1646 {
1647 $change = array();
1648 $previous_unsigned = !empty($previous['unsigned']) ? $previous['unsigned'] : false;
1649 $unsigned = !empty($current['unsigned']) ? $current['unsigned'] : false;
1650 if ($previous_unsigned != $unsigned) {
1651 $change['unsigned'] = true;
1652 }
1653 $previous_autoincrement = !empty($previous['autoincrement']) ? $previous['autoincrement'] : false;
1654 $autoincrement = !empty($current['autoincrement']) ? $current['autoincrement'] : false;
1655 if ($previous_autoincrement != $autoincrement) {
1656 $change['autoincrement'] = true;
1657 }
1658
1659 return $change;
1660 }

◆ compareTextDefinition()

ilDBPdoFieldDefinition::compareTextDefinition (   $current,
  $previous 
)
protected
Parameters
$current
$previous
Returns
array

Definition at line 1668 of file class.ilDBPdoFieldDefinition.php.

1669 {
1670 $change = array();
1671 $previous_length = !empty($previous['length']) ? $previous['length'] : 0;
1672 $length = !empty($current['length']) ? $current['length'] : 0;
1673 if ($previous_length != $length) {
1674 $change['length'] = true;
1675 }
1676 $previous_fixed = !empty($previous['fixed']) ? $previous['fixed'] : 0;
1677 $fixed = !empty($current['fixed']) ? $current['fixed'] : 0;
1678 if ($previous_fixed != $fixed) {
1679 $change['fixed'] = true;
1680 }
1681
1682 return $change;
1683 }

Referenced by compareBLOBDefinition(), and compareCLOBDefinition().

+ Here is the caller graph for this function:

◆ compareTimeDefinition()

ilDBPdoFieldDefinition::compareTimeDefinition (   $current,
  $previous 
)
protected
Parameters
$current
$previous
Returns
array

Definition at line 1724 of file class.ilDBPdoFieldDefinition.php.

1725 {
1726 return array();
1727 }

◆ compareTimestampDefinition()

ilDBPdoFieldDefinition::compareTimestampDefinition (   $current,
  $previous 
)
protected
Parameters
$current
$previous
Returns
array

Definition at line 1735 of file class.ilDBPdoFieldDefinition.php.

1736 {
1737 return array();
1738 }

◆ convertResult()

ilDBPdoFieldDefinition::convertResult (   $value,
  $type,
  $rtrim = true 
)
Parameters
$value
$type
bool$rtrim
Returns
bool|float|int|mixed|null|resource|string
Exceptions

ilDatabaseException

Definition at line 1228 of file class.ilDBPdoFieldDefinition.php.

1229 {
1230 throw new ilDatabaseException("deprecated");
1231 if (is_null($value)) {
1232 return null;
1233 }
1234 $db = $this->getDBInstance();
1235
1236 if (!empty($db->options['datatype_map'][$type])) {
1237 $type = $db->options['datatype_map'][$type];
1238 if (!empty($db->options['datatype_map_callback'][$type])) {
1239 $parameter = array( 'type' => $type, 'value' => $value, 'rtrim' => $rtrim );
1240
1241 return call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1242 }
1243 }
1244
1245 return $this->baseConvertResult($value, $type, $rtrim);
1246 }
baseConvertResult($value, $type, $rtrim=true)

References $type, baseConvertResult(), and getDBInstance().

Referenced by convertResultRow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convertResultRow()

ilDBPdoFieldDefinition::convertResultRow (   $types,
  $row,
  $rtrim = true 
)
Parameters
$types
$row
bool$rtrim
Returns
bool|float|int|mixed|null|resource|string

Definition at line 1255 of file class.ilDBPdoFieldDefinition.php.

1256 {
1257 throw new ilDatabaseException("deprecated");
1258 $types = $this->sortResultFieldTypes(array_keys($row), $types);
1259 foreach ($row as $key => $value) {
1260 if (empty($types[$key])) {
1261 continue;
1262 }
1263 $value = $this->convertResult($row[$key], $types[$key], $rtrim);
1264
1265 $row[$key] = $value;
1266 }
1267
1268 return $row;
1269 }
convertResult($value, $type, $rtrim=true)

References convertResult(), and sortResultFieldTypes().

+ Here is the call graph for this function:

◆ destroyLOB()

ilDBPdoFieldDefinition::destroyLOB (   $lob)
Parameters
$lob
Returns
bool

Definition at line 2156 of file class.ilDBPdoFieldDefinition.php.

2157 {
2158 $lob_data = stream_get_meta_data($lob);
2159 $lob_index = $lob_data['wrapper_data']->lob_index;
2160 fclose($lob);
2161 if (isset($this->lobs[$lob_index])) {
2162 $this->destroyLOBInternal($this->lobs[$lob_index]);
2163 unset($this->lobs[$lob_index]);
2164 }
2165
2166 return true;
2167 }

References destroyLOBInternal().

+ Here is the call graph for this function:

◆ destroyLOBInternal()

ilDBPdoFieldDefinition::destroyLOBInternal ( $lob)
protected
Parameters
$lob
Returns
bool

Definition at line 2174 of file class.ilDBPdoFieldDefinition.php.

2175 {
2176 return true;
2177 }

Referenced by destroyLOB().

+ Here is the caller graph for this function:

◆ endOfLOB()

ilDBPdoFieldDefinition::endOfLOB (   $lob)
protected
Parameters
$lob
Returns
mixed

Definition at line 2146 of file class.ilDBPdoFieldDefinition.php.

2147 {
2148 return $lob['endOfLOB'];
2149 }

◆ getAllowedAttributes()

ilDBPdoFieldDefinition::getAllowedAttributes ( )
Returns
array

Definition at line 1081 of file class.ilDBPdoFieldDefinition.php.

1082 {
1084 }

References $allowed_attributes.

Referenced by checkColumnDefinition().

+ Here is the caller graph for this function:

◆ getAllReserved()

ilDBPdoFieldDefinition::getAllReserved ( )
Returns
array

Definition at line 897 of file class.ilDBPdoFieldDefinition.php.

References getReservedMysql(), and getReservedPostgres().

+ Here is the call graph for this function:

◆ getAvailableTypes()

ilDBPdoFieldDefinition::getAvailableTypes ( )
Returns
array

Definition at line 1063 of file class.ilDBPdoFieldDefinition.php.

References $available_types.

Referenced by checkColumnDefinition().

+ Here is the caller graph for this function:

◆ getBLOBDeclaration()

ilDBPdoFieldDefinition::getBLOBDeclaration (   $name,
  $field 
)
protected
Parameters
$name
$field
Returns
\ilDBPdo|string

Definition at line 1514 of file class.ilDBPdoFieldDefinition.php.

1515 {
1516 $db = $this->getDBInstance();
1517
1518 $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
1519 $name = $db->quoteIdentifier($name, true);
1520
1521 return $name . ' ' . $this->getTypeDeclaration($field) . $notnull;
1522 }
if($format !==null) $name
Definition: metadata.php:230

References $name, getDBInstance(), and getTypeDeclaration().

+ Here is the call graph for this function:

◆ getBooleanDeclaration()

ilDBPdoFieldDefinition::getBooleanDeclaration (   $name,
  $field 
)
protected
Parameters
$name
$field
Returns
\ilDBInterface|string

Definition at line 1530 of file class.ilDBPdoFieldDefinition.php.

1531 {
1532 return $this->getInternalDeclaration($name, $field);
1533 }

References $name, and getInternalDeclaration().

+ Here is the call graph for this function:

◆ getCharsetFieldDeclaration()

ilDBPdoFieldDefinition::getCharsetFieldDeclaration (   $charset)
protected
Parameters
$charset
Returns
string

Definition at line 1447 of file class.ilDBPdoFieldDefinition.php.

1448 {
1449 return '';
1450 }

Referenced by getDeclarationOptions().

+ Here is the caller graph for this function:

◆ getCLOBDeclaration()

ilDBPdoFieldDefinition::getCLOBDeclaration (   $name,
  $field 
)
protected
Parameters
$name
$field
Returns
\ilDBPdo|string

Definition at line 1498 of file class.ilDBPdoFieldDefinition.php.

1499 {
1500 $db = $this->getDBInstance();
1501
1502 $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
1503 $name = $db->quoteIdentifier($name, true);
1504
1505 return $name . ' ' . $this->getTypeDeclaration($field) . $notnull;
1506 }

References $name, getDBInstance(), and getTypeDeclaration().

+ Here is the call graph for this function:

◆ getCollationFieldDeclaration()

ilDBPdoFieldDefinition::getCollationFieldDeclaration (   $collation)
protected
Parameters
$collation
Returns
string

Definition at line 1457 of file class.ilDBPdoFieldDefinition.php.

1458 {
1459 return '';
1460 }

Referenced by getDeclarationOptions().

+ Here is the caller graph for this function:

◆ getDateDeclaration()

ilDBPdoFieldDefinition::getDateDeclaration (   $name,
  $field 
)
protected
Parameters
$name
$field
Returns
\ilDBInterface|string

Definition at line 1541 of file class.ilDBPdoFieldDefinition.php.

1542 {
1543 return $this->getInternalDeclaration($name, $field);
1544 }

References $name, and getInternalDeclaration().

+ Here is the call graph for this function:

◆ getDBInstance()

◆ getDecimalDeclaration()

ilDBPdoFieldDefinition::getDecimalDeclaration (   $name,
  $field 
)
protected
Parameters
$name
$field
Returns
\ilDBInterface|string

Definition at line 1585 of file class.ilDBPdoFieldDefinition.php.

1586 {
1587 return $this->getInternalDeclaration($name, $field);
1588 }

References $name, and getInternalDeclaration().

+ Here is the call graph for this function:

◆ getDeclaration()

ilDBPdoFieldDefinition::getDeclaration (   $type,
  $name,
  $field 
)
Parameters
$type
$name
$field
Returns
\ilDBInterface|mixed
Exceptions

ilDatabaseException

Definition at line 1321 of file class.ilDBPdoFieldDefinition.php.

1322 {
1323 $db = $this->getDBInstance();
1324
1325 if (!empty($db->options['datatype_map'][$type])) {
1326 $type = $db->options['datatype_map'][$type];
1327 if (!empty($db->options['datatype_map_callback'][$type])) {
1328 $parameter = array( 'type' => $type, 'name' => $name, 'field' => $field );
1329
1330 return call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1331 }
1332 $field['type'] = $type;
1333 }
1334
1335 if (!method_exists($this, "get{$type}Declaration")) {
1336 throw new ilDatabaseException('type not defined: ' . $type);
1337 }
1338
1339 return $this->{"get{$type}Declaration"}($name, $field);
1340 }

References $name, $type, and getDBInstance().

+ Here is the call graph for this function:

◆ getDeclarationOptions()

ilDBPdoFieldDefinition::getDeclarationOptions (   $field)
protected
Parameters
$field
Returns
\ilDBPdo|string
Exceptions

ilDatabaseException

Definition at line 1403 of file class.ilDBPdoFieldDefinition.php.

1404 {
1405 $charset = empty($field['charset']) ? '' : ' ' . $this->getCharsetFieldDeclaration($field['charset']);
1406
1407 $default = '';
1408 if (array_key_exists('default', $field)) {
1409 if ($field['default'] === '') {
1410 $db = $this->getDBInstance();
1411
1412 if (empty($field['notnull'])) {
1413 $field['default'] = null;
1414 } else {
1416 $field['default'] = $valid_default_values[$field['type']];
1417 }
1418 if ($field['default'] === ''
1419 && isset($db->options["portability"])
1420 && ($db->options['portability'] & 32)
1421 ) {
1422 $field['default'] = ' ';
1423 }
1424 }
1425 $default = ' DEFAULT ' . $this->quote($field['default'], $field['type']);
1426 } elseif (empty($field['notnull'])) {
1427 $default = ' DEFAULT NULL';
1428 }
1429
1430 $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
1431 // alex patch 28 Nov 2011 start
1432 if (isset($field["notnull"]) && $field['notnull'] === false) {
1433 $notnull = " NULL";
1434 }
1435 // alex patch 28 Nov 2011 end
1436
1437 $collation = empty($field['collation']) ? '' : ' ' . $this->getCollationFieldDeclaration($field['collation']);
1438
1439 return $charset . $default . $notnull . $collation;
1440 }
quote($value, $type=null, $quote=true, $escape_wildcards=false)

References $valid_default_values, getCharsetFieldDeclaration(), getCollationFieldDeclaration(), getDBInstance(), getValidTypes(), and quote().

+ Here is the call graph for this function:

◆ getFloatDeclaration()

ilDBPdoFieldDefinition::getFloatDeclaration (   $name,
  $field 
)
protected
Parameters
$name
$field
Returns
\ilDBInterface|string

Definition at line 1574 of file class.ilDBPdoFieldDefinition.php.

1575 {
1576 return $this->getInternalDeclaration($name, $field);
1577 }

References $name, and getInternalDeclaration().

+ Here is the call graph for this function:

◆ getIntegerDeclaration()

ilDBPdoFieldDefinition::getIntegerDeclaration (   $name,
  $field 
)
protected
Parameters
$name
$field
Returns
\ilDBInterface|\ilDBPdo|mixed
Exceptions

ilDatabaseException

Reimplemented in ilDBPdoMySQLFieldDefinition, and ilDBPdoPostgresFieldDefinition.

Definition at line 1469 of file class.ilDBPdoFieldDefinition.php.

1470 {
1471 if (!empty($field['unsigned'])) {
1472 $db = $this->getDBInstance();
1473
1474 $db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer";
1475 }
1476
1477 return $this->getInternalDeclaration($name, $field);
1478 }

References $name, getDBInstance(), and getInternalDeclaration().

+ Here is the call graph for this function:

◆ getInternalDeclaration()

ilDBPdoFieldDefinition::getInternalDeclaration (   $name,
  $field 
)
protected
Parameters
$name
$field
Returns
\ilDBInterface|string

Definition at line 1387 of file class.ilDBPdoFieldDefinition.php.

1388 {
1389 $db = $this->getDBInstance();
1390
1391 $name = $db->quoteIdentifier($name, true);
1392 $declaration_options = $db->getFieldDefinition()->getDeclarationOptions($field);
1393
1394 return $name . ' ' . $this->getTypeDeclaration($field) . $declaration_options;
1395 }

References $name, getDBInstance(), and getTypeDeclaration().

Referenced by getBooleanDeclaration(), getDateDeclaration(), getDecimalDeclaration(), getFloatDeclaration(), getIntegerDeclaration(), getTextDeclaration(), getTimeDeclaration(), and getTimestampDeclaration().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMaxLength()

ilDBPdoFieldDefinition::getMaxLength ( )
Returns
array

Definition at line 1099 of file class.ilDBPdoFieldDefinition.php.

1100 {
1101 return $this->max_length;
1102 }

References $max_length.

Referenced by checkColumnDefinition().

+ Here is the caller graph for this function:

◆ getQueryUtils()

ilDBPdoFieldDefinition::getQueryUtils ( )
protected
Returns
\ilMySQLQueryUtils

Definition at line 830 of file class.ilDBPdoFieldDefinition.php.

831 {
832 if (!$this->query_utils) {
833 $this->query_utils = new ilMySQLQueryUtils($this->db_instance);
834 }
835
836 return $this->query_utils;
837 }
Class ilMySQLQueryUtils.

References $query_utils.

◆ getReservedMysql()

ilDBPdoFieldDefinition::getReservedMysql ( )
Returns
array

Definition at line 906 of file class.ilDBPdoFieldDefinition.php.

References $reserved_mysql.

Referenced by getAllReserved().

+ Here is the caller graph for this function:

◆ getReservedPostgres()

ilDBPdoFieldDefinition::getReservedPostgres ( )
Returns
array

Definition at line 924 of file class.ilDBPdoFieldDefinition.php.

References $reserved_postgres.

Referenced by getAllReserved().

+ Here is the caller graph for this function:

◆ getTextDeclaration()

ilDBPdoFieldDefinition::getTextDeclaration (   $name,
  $field 
)
protected
Parameters
$name
$field
Returns
\ilDBInterface|mixed
Exceptions

ilDatabaseException

Definition at line 1487 of file class.ilDBPdoFieldDefinition.php.

1488 {
1489 return $this->getInternalDeclaration($name, $field);
1490 }

References $name, and getInternalDeclaration().

+ Here is the call graph for this function:

◆ getTimeDeclaration()

ilDBPdoFieldDefinition::getTimeDeclaration (   $name,
  $field 
)
protected
Parameters
$name
$field
Returns
\ilDBInterface|string

Definition at line 1563 of file class.ilDBPdoFieldDefinition.php.

1564 {
1565 return $this->getInternalDeclaration($name, $field);
1566 }

References $name, and getInternalDeclaration().

+ Here is the call graph for this function:

◆ getTimestampDeclaration()

ilDBPdoFieldDefinition::getTimestampDeclaration (   $name,
  $field 
)
protected
Parameters
$name
$field
Returns
\ilDBInterface|string

Definition at line 1552 of file class.ilDBPdoFieldDefinition.php.

1553 {
1554 return $this->getInternalDeclaration($name, $field);
1555 }

References $name, and getInternalDeclaration().

+ Here is the call graph for this function:

◆ getTypeDeclaration()

ilDBPdoFieldDefinition::getTypeDeclaration (   $field)
Parameters
$field
Returns
\ilDBInterface|string

Reimplemented in ilDBPdoMySQLFieldDefinition, and ilDBPdoPostgresFieldDefinition.

Definition at line 1347 of file class.ilDBPdoFieldDefinition.php.

1348 {
1349 $db = $this->getDBInstance();
1350
1351 switch ($field['type']) {
1352 case 'text':
1353 $length = !empty($field['length']) ? $field['length'] : $db->options['default_text_field_length'];
1354 $fixed = !empty($field['fixed']) ? $field['fixed'] : false;
1355
1356 return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(' . $db->options['default_text_field_length']
1357 . ')') : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
1358 case 'clob':
1359 return 'TEXT';
1360 case 'blob':
1361 return 'TEXT';
1362 case 'integer':
1363 return 'INT';
1364 case 'boolean':
1365 return 'INT';
1366 case 'date':
1367 return 'CHAR (' . strlen('YYYY-MM-DD') . ')';
1368 case 'time':
1369 return 'CHAR (' . strlen('HH:MM:SS') . ')';
1370 case 'timestamp':
1371 return 'CHAR (' . strlen('YYYY-MM-DD HH:MM:SS') . ')';
1372 case 'float':
1373 return 'TEXT';
1374 case 'decimal':
1375 return 'TEXT';
1376 }
1377
1378 return '';
1379 }

References getDBInstance().

Referenced by getBLOBDeclaration(), getCLOBDeclaration(), and getInternalDeclaration().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getValidTypes()

ilDBPdoFieldDefinition::getValidTypes ( )
Returns
array

Definition at line 1126 of file class.ilDBPdoFieldDefinition.php.

1127 {
1129 $db = $this->getDBInstance();
1130
1131 if (!empty($db->options['datatype_map'])) {
1132 foreach ($db->options['datatype_map'] as $type => $mapped_type) {
1133 if (array_key_exists($mapped_type, $types)) {
1134 $types[$type] = $types[$mapped_type];
1135 } elseif (!empty($db->options['datatype_map_callback'][$type])) {
1136 $parameter = array( 'type' => $type, 'mapped_type' => $mapped_type );
1137 $default = call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1138 $types[$type] = $default;
1139 }
1140 }
1141 }
1142
1143 return $types;
1144 }

References $type, $valid_default_values, and getDBInstance().

Referenced by getDeclarationOptions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ implodeArray()

ilDBPdoFieldDefinition::implodeArray (   $array,
  $type = false 
)
Parameters
$array
bool$type
Returns
string
Exceptions

ilDatabaseException

Definition at line 2186 of file class.ilDBPdoFieldDefinition.php.

2187 {
2188 if (!is_array($array) || empty($array)) {
2189 return 'NULL';
2190 }
2191 if ($type) {
2192 foreach ($array as $value) {
2193 $return[] = $this->quote($value, $type);
2194 }
2195 } else {
2196 $return = $array;
2197 }
2198
2199 return implode(', ', $return);
2200 }

References $type, and quote().

+ Here is the call graph for this function:

◆ isAllowedAttribute()

ilDBPdoFieldDefinition::isAllowedAttribute (   $attribute,
  $type 
)
Parameters
$attribute
$type
Returns
bool

Definition at line 1054 of file class.ilDBPdoFieldDefinition.php.

1055 {
1056 return in_array($attribute, $this->allowed_attributes[$type]);
1057 }

References $type.

◆ isReserved()

ilDBPdoFieldDefinition::isReserved (   $table_name)
Parameters
$table_name
Returns
bool

Definition at line 888 of file class.ilDBPdoFieldDefinition.php.

889 {
890 return false;
891 }

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

+ Here is the caller graph for this function:

◆ mapNativeDatatype()

ilDBPdoFieldDefinition::mapNativeDatatype (   $field)
Parameters
$field
Returns
\ilDBPdo|mixed

Definition at line 2266 of file class.ilDBPdoFieldDefinition.php.

2267 {
2268 $db = $this->getDBInstance();
2269 $db_type = strtok($field['type'], '(), ');
2270 if (!empty($db->options['nativetype_map_callback'][$db_type])) {
2271 return call_user_func_array($db->options['nativetype_map_callback'][$db_type], array( $db, $field ));
2272 }
2273
2274 return $this->mapNativeDatatypeInternal($field);
2275 }
mapNativeDatatypeInternal($field)

References getDBInstance(), and mapNativeDatatypeInternal().

+ Here is the call graph for this function:

◆ mapNativeDatatypeInternal()

ilDBPdoFieldDefinition::mapNativeDatatypeInternal (   $field)
abstractprotected
Parameters
$field
Returns
\ilDBPdo
Exceptions

ilDatabaseException

Reimplemented in ilDBPdoMySQLFieldDefinition, and ilDBPdoPostgresFieldDefinition.

Referenced by mapNativeDatatype().

+ Here is the caller graph for this function:

◆ mapPrepareDatatype()

ilDBPdoFieldDefinition::mapPrepareDatatype (   $type)
Parameters
$type
Returns
\ilDBPdo|mixed

Definition at line 2290 of file class.ilDBPdoFieldDefinition.php.

2291 {
2292 $db = $this->getDBInstance();
2293
2294 if (!empty($db->options['datatype_map'][$type])) {
2295 $type = $db->options['datatype_map'][$type];
2296 if (!empty($db->options['datatype_map_callback'][$type])) {
2297 $parameter = array( 'type' => $type );
2298
2299 return call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
2300 }
2301 }
2302
2303 return $type;
2304 }

References $type, and getDBInstance().

+ Here is the call graph for this function:

◆ matchPattern()

ilDBPdoFieldDefinition::matchPattern (   $pattern,
  $operator = null,
  $field = null 
)
Parameters
$pattern
null$operator
null$field
Returns
\ilDBPdo|string
Exceptions

ilDatabaseException

Definition at line 2210 of file class.ilDBPdoFieldDefinition.php.

2211 {
2212 $db = $this->getDBInstance();
2213
2214 $match = '';
2215 if (!is_null($operator)) {
2216 $operator = strtoupper($operator);
2217 switch ($operator) {
2218 // case insensitive
2219 case 'ILIKE':
2220 if (is_null($field)) {
2221 throw new ilDatabaseException('case insensitive LIKE matching requires passing the field name');
2222 }
2223 $db->loadModule('Function', null, true);
2224 $match = $db->function->lower($field) . ' LIKE ';
2225 break;
2226 // case sensitive
2227 case 'LIKE':
2228 $match = is_null($field) ? 'LIKE ' : $field . ' LIKE ';
2229 break;
2230 default:
2231 throw new ilDatabaseException('not a supported operator type:' . $operator);
2232 }
2233 }
2234 $match .= "'";
2235 foreach ($pattern as $key => $value) {
2236 if ($key % 2) {
2237 $match .= $value;
2238 } else {
2239 if ($operator === 'ILIKE') {
2240 $value = strtolower($value);
2241 }
2242 $escaped = $db->escape($value);
2243 $match .= $db->escapePattern($escaped);
2244 }
2245 }
2246 $match .= "'";
2247 $match .= $this->patternEscapeString();
2248
2249 return $match;
2250 }

References getDBInstance(), and patternEscapeString().

+ Here is the call graph for this function:

◆ patternEscapeString()

ilDBPdoFieldDefinition::patternEscapeString ( )
Returns
string

Definition at line 2256 of file class.ilDBPdoFieldDefinition.php.

2257 {
2258 return '';
2259 }

Referenced by matchPattern(), and quote().

+ Here is the caller graph for this function:

◆ quote()

ilDBPdoFieldDefinition::quote (   $value,
  $type = null,
  $quote = true,
  $escape_wildcards = false 
)
Parameters
$value
null$type
bool$quote
bool$escape_wildcards
Returns
\ilDBPdo|mixed|string
Exceptions

ilDatabaseException

Definition at line 1782 of file class.ilDBPdoFieldDefinition.php.

1783 {
1784 $db = $this->getDBInstance();
1785
1786 return $db->quote($value, $type);
1787
1788 if (is_null($value)
1789 || ($value === '' && $db->options['portability'])
1790 ) {
1791 if (!$quote) {
1792 return null;
1793 }
1794
1795 return 'NULL';
1796 }
1797
1798 if (is_null($type)) {
1799 switch (gettype($value)) {
1800 case 'integer':
1801 $type = 'integer';
1802 break;
1803 case 'double':
1804 // todo: default to decimal as float is quite unusual
1805 // $type = 'float';
1806 $type = 'decimal';
1807 break;
1808 case 'boolean':
1809 $type = 'boolean';
1810 break;
1811 case 'array':
1812 $value = serialize($value);
1813 // no break
1814 case 'object':
1815 $type = 'text';
1816 break;
1817 default:
1818 if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/', $value)) {
1819 $type = 'timestamp';
1820 } elseif (preg_match('/^\d{2}:\d{2}$/', $value)) {
1821 $type = 'time';
1822 } elseif (preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) {
1823 $type = 'date';
1824 } else {
1825 $type = 'text';
1826 }
1827 break;
1828 }
1829 } elseif (!empty($db->options['datatype_map'][$type])) {
1830 $type = $db->options['datatype_map'][$type];
1831 if (!empty($db->options['datatype_map_callback'][$type])) {
1832 $parameter = array( 'type' => $type, 'value' => $value, 'quote' => $quote, 'escape_wildcards' => $escape_wildcards );
1833
1834 return call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1835 }
1836 }
1837
1838 if (!method_exists($this, "quote{$type}")) {
1839 throw new ilDatabaseException('type not defined: ' . $type);
1840 }
1841 $value = $this->{"quote{$type}"}($value, $quote, $escape_wildcards);
1842 if ($quote && $escape_wildcards && $db->string_quoting['escape_pattern']
1843 && $db->string_quoting['escape'] !== $db->string_quoting['escape_pattern']
1844 ) {
1845 $value .= $this->patternEscapeString();
1846 }
1847
1848 return $value;
1849 }

References $type, getDBInstance(), and patternEscapeString().

Referenced by getDeclarationOptions(), ilDBPdoMySQLFieldDefinition\getIntegerDeclaration(), ilDBPdoPostgresFieldDefinition\getIntegerDeclaration(), and implodeArray().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quoteBLOB()

ilDBPdoFieldDefinition::quoteBLOB (   $value,
  $quote,
  $escape_wildcards 
)
protected
Parameters
$value
$quote
$escape_wildcards
Returns
\ilDBPdo|string

Definition at line 1949 of file class.ilDBPdoFieldDefinition.php.

1950 {
1951 return $this->quoteLOB($value, $quote, $escape_wildcards);
1952 }
quoteLOB($value, $quote, $escape_wildcards)

References quoteLOB().

+ Here is the call graph for this function:

◆ quoteBoolean()

ilDBPdoFieldDefinition::quoteBoolean (   $value,
  $quote,
  $escape_wildcards 
)
protected
Parameters
$value
$quote
$escape_wildcards
Returns
int

Definition at line 1961 of file class.ilDBPdoFieldDefinition.php.

1962 {
1963 return ($value ? 1 : 0);
1964 }

◆ quoteCLOB()

ilDBPdoFieldDefinition::quoteCLOB (   $value,
  $quote,
  $escape_wildcards 
)
protected
Parameters
$value
$quote
$escape_wildcards
Returns
\ilDBPdo|string

Definition at line 1937 of file class.ilDBPdoFieldDefinition.php.

1938 {
1939 return $this->quoteLOB($value, $quote, $escape_wildcards);
1940 }

References quoteLOB().

+ Here is the call graph for this function:

◆ quoteDate()

ilDBPdoFieldDefinition::quoteDate (   $value,
  $quote,
  $escape_wildcards 
)
protected
Parameters
$value
$quote
$escape_wildcards
Returns
\ilDBPdo|string

Definition at line 1973 of file class.ilDBPdoFieldDefinition.php.

1974 {
1975 if ($value === 'CURRENT_DATE') {
1976 $db = $this->getDBInstance();
1977
1978 return 'CURRENT_DATE';
1979 }
1980
1981 return $this->quoteText($value, $quote, $escape_wildcards);
1982 }
quoteText($value, $quote, $escape_wildcards)

References getDBInstance(), and quoteText().

+ Here is the call graph for this function:

◆ quoteDecimal()

ilDBPdoFieldDefinition::quoteDecimal (   $value,
  $quote,
  $escape_wildcards 
)
protected
Parameters
$value
$quote
$escape_wildcards
Returns
mixed|string

Definition at line 2058 of file class.ilDBPdoFieldDefinition.php.

2059 {
2060 $value = (string) $value;
2061 $value = preg_replace('/[^\d\.,\-+eE]/', '', $value);
2062 if (preg_match('/[^.0-9]/', $value)) {
2063 if (strpos($value, ',')) {
2064 // 1000,00
2065 if (!strpos($value, '.')) {
2066 // convert the last "," to a "."
2067 $value = strrev(str_replace(',', '.', strrev($value)));
2068 // 1.000,00
2069 } elseif (strpos($value, '.') && strpos($value, '.') < strpos($value, ',')) {
2070 $value = str_replace('.', '', $value);
2071 // convert the last "," to a "."
2072 $value = strrev(str_replace(',', '.', strrev($value)));
2073 // 1,000.00
2074 } else {
2075 $value = str_replace(',', '', $value);
2076 }
2077 }
2078 }
2079
2080 return $value;
2081 }

Referenced by quoteFloat().

+ Here is the caller graph for this function:

◆ quoteFloat()

ilDBPdoFieldDefinition::quoteFloat (   $value,
  $quote,
  $escape_wildcards 
)
protected
Parameters
$value
$quote
$escape_wildcards
Returns
string

Definition at line 2037 of file class.ilDBPdoFieldDefinition.php.

2038 {
2039 if (preg_match('/^(.*)e([-+])(\d+)$/i', $value, $matches)) {
2040 $decimal = $this->quoteDecimal($matches[1], $quote, $escape_wildcards);
2041 $sign = $matches[2];
2042 $exponent = str_pad($matches[3], 2, '0', STR_PAD_LEFT);
2043 $value = $decimal . 'E' . $sign . $exponent;
2044 } else {
2045 $value = $this->quoteDecimal($value, $quote, $escape_wildcards);
2046 }
2047
2048 return $value;
2049 }
quoteDecimal($value, $quote, $escape_wildcards)

References quoteDecimal().

+ Here is the call graph for this function:

◆ quoteInteger()

ilDBPdoFieldDefinition::quoteInteger (   $value,
  $quote,
  $escape_wildcards 
)
protected
Parameters
$value
$quote
$escape_wildcards
Returns
int

Definition at line 1858 of file class.ilDBPdoFieldDefinition.php.

1859 {
1860 return (int) $value;
1861 }

◆ quoteLOB()

ilDBPdoFieldDefinition::quoteLOB (   $value,
  $quote,
  $escape_wildcards 
)
protected
Parameters
$value
$quote
$escape_wildcards
Returns
\ilDBPdo|string

Definition at line 1923 of file class.ilDBPdoFieldDefinition.php.

1924 {
1925 $value = $this->readFile($value);
1926
1927 return $this->quoteText($value, $quote, $escape_wildcards);
1928 }

References quoteText(), and readFile().

Referenced by quoteBLOB(), and quoteCLOB().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quoteText()

ilDBPdoFieldDefinition::quoteText (   $value,
  $quote,
  $escape_wildcards 
)
protected
Parameters
$value
$quote
$escape_wildcards
Returns
\ilDBPdo|string

Definition at line 1870 of file class.ilDBPdoFieldDefinition.php.

1871 {
1872 if (!$quote) {
1873 return $value;
1874 }
1875
1876 $db = $this->getDBInstance();
1877
1878 $value = $db->escape($value, $escape_wildcards);
1879
1880 return "'" . $value . "'";
1881 }

References getDBInstance().

Referenced by quoteDate(), quoteLOB(), quoteTime(), and quoteTimestamp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quoteTime()

ilDBPdoFieldDefinition::quoteTime (   $value,
  $quote,
  $escape_wildcards 
)
protected
Parameters
$value
$quote
$escape_wildcards
Returns
\ilDBPdo|string

Definition at line 2014 of file class.ilDBPdoFieldDefinition.php.

2015 {
2016 throw new ilDatabaseException("deprecated");
2017 if ($value === 'CURRENT_TIME') {
2018 $db = $this->getDBInstance();
2019
2020 if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
2021 return $db->function->now('time');
2022 }
2023
2024 return 'CURRENT_TIME';
2025 }
2026
2027 return $this->quoteText($value, $quote, $escape_wildcards);
2028 }

References getDBInstance(), and quoteText().

+ Here is the call graph for this function:

◆ quoteTimestamp()

ilDBPdoFieldDefinition::quoteTimestamp (   $value,
  $quote,
  $escape_wildcards 
)
protected
Parameters
$value
$quote
$escape_wildcards
Returns
\ilDBPdo|string

Definition at line 1991 of file class.ilDBPdoFieldDefinition.php.

1992 {
1993 throw new ilDatabaseException("deprecated");
1994 if ($value === 'CURRENT_TIMESTAMP') {
1995 $db = $this->getDBInstance();
1996
1997 if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
1998 return $db->function->now('timestamp');
1999 }
2000
2001 return 'CURRENT_TIMESTAMP';
2002 }
2003
2004 return $this->quoteText($value, $quote, $escape_wildcards);
2005 }

References getDBInstance(), and quoteText().

+ Here is the call graph for this function:

◆ readFile()

ilDBPdoFieldDefinition::readFile (   $value)
protected
Parameters
$value
Returns
\ilDBPdo|string

Definition at line 1888 of file class.ilDBPdoFieldDefinition.php.

1889 {
1890 $close = false;
1891 if (preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) {
1892 $close = true;
1893 if ($match[1] == 'file://') {
1894 $value = $match[2];
1895 }
1896 // do not try to open urls
1897 #$value = @fopen($value, 'r');
1898 }
1899
1900 if (is_resource($value)) {
1901 $db = $this->getDBInstance();
1902
1903 $fp = $value;
1904 $value = '';
1905 while (!@feof($fp)) {
1906 $value .= @fread($fp, $db->options['lob_buffer_length']);
1907 }
1908 if ($close) {
1909 @fclose($fp);
1910 }
1911 }
1912
1913 return $value;
1914 }

References getDBInstance().

Referenced by quoteLOB().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readLOB()

ilDBPdoFieldDefinition::readLOB (   $lob,
  $length 
)
protected
Parameters
$lob
$length
Returns
string

Definition at line 2136 of file class.ilDBPdoFieldDefinition.php.

2137 {
2138 return substr($lob['value'], $lob['position'], $length);
2139 }

◆ retrieveLOB()

ilDBPdoFieldDefinition::retrieveLOB ( $lob)
protected
Parameters
$lob
Returns
bool

Definition at line 2120 of file class.ilDBPdoFieldDefinition.php.

2121 {
2122 if (is_null($lob['value'])) {
2123 $lob['value'] = $lob['resource'];
2124 }
2125 $lob['loaded'] = true;
2126
2127 return true;
2128 }

◆ setAllowedAttributes()

ilDBPdoFieldDefinition::setAllowedAttributes (   $allowed_attributes)
Parameters
array$allowed_attributes

Definition at line 1090 of file class.ilDBPdoFieldDefinition.php.

1091 {
1092 $this->allowed_attributes = $allowed_attributes;
1093 }

References $allowed_attributes.

◆ setAvailableTypes()

ilDBPdoFieldDefinition::setAvailableTypes (   $available_types)
Parameters
array$available_types

Definition at line 1072 of file class.ilDBPdoFieldDefinition.php.

1073 {
1074 $this->available_types = $available_types;
1075 }

References $available_types.

◆ setMaxLength()

ilDBPdoFieldDefinition::setMaxLength (   $max_length)
Parameters
array$max_length

Definition at line 1108 of file class.ilDBPdoFieldDefinition.php.

1109 {
1110 $this->max_length = $max_length;
1111 }

References $max_length.

◆ setReservedMysql()

ilDBPdoFieldDefinition::setReservedMysql (   $reserved_mysql)
Parameters
array$reserved_mysql

Definition at line 915 of file class.ilDBPdoFieldDefinition.php.

916 {
917 $this->reserved_mysql = $reserved_mysql;
918 }

References $reserved_mysql.

◆ setReservedPostgres()

ilDBPdoFieldDefinition::setReservedPostgres (   $reserved_postgres)
Parameters
array$reserved_postgres

Definition at line 933 of file class.ilDBPdoFieldDefinition.php.

934 {
935 $this->reserved_postgres = $reserved_postgres;
936 }

References $reserved_postgres.

◆ sortResultFieldTypes()

ilDBPdoFieldDefinition::sortResultFieldTypes (   $columns,
  $types 
)
protected
Parameters
$columns
$types
Returns
array

Definition at line 1279 of file class.ilDBPdoFieldDefinition.php.

1280 {
1281 $n_cols = count($columns);
1282 $n_types = count($types);
1283 if ($n_cols > $n_types) {
1284 for ($i = $n_cols - $n_types; $i >= 0; $i--) {
1285 $types[] = null;
1286 }
1287 }
1288 $sorted_types = array();
1289 foreach ($columns as $col) {
1290 $sorted_types[$col] = null;
1291 }
1292 foreach ($types as $name => $type) {
1293 if (array_key_exists($name, $sorted_types)) {
1294 $sorted_types[$name] = $type;
1295 unset($types[$name]);
1296 }
1297 }
1298 // if there are left types in the array, fill the null values of the
1299 // sorted array with them, in order.
1300 if (count($types)) {
1301 reset($types);
1302 foreach (array_keys($sorted_types) as $k) {
1303 if (is_null($sorted_types[$k])) {
1304 $sorted_types[$k] = current($types);
1305 next($types);
1306 }
1307 }
1308 }
1309
1310 return $sorted_types;
1311 }
if(! $in) $columns
Definition: Utf8Test.php:45
$i
Definition: metadata.php:24

References $columns, $i, $name, and $type.

Referenced by convertResultRow().

+ Here is the caller graph for this function:

◆ writeLOBToFile()

ilDBPdoFieldDefinition::writeLOBToFile (   $lob,
  $file 
)
Parameters
$lob
$file
Returns
bool|\ilDBPdo
Exceptions

ilDatabaseException

Definition at line 2090 of file class.ilDBPdoFieldDefinition.php.

2091 {
2092 $db = $this->getDBInstance();
2093
2094 if (preg_match('/^(\w+:\/\/)(.*)$/', $file, $match)) {
2095 if ($match[1] == 'file://') {
2096 $file = $match[2];
2097 }
2098 }
2099
2100 $fp = @fopen($file, 'wb');
2101 while (!@feof($lob)) {
2102 $result = @fread($lob, $db->options['lob_buffer_length']);
2103 $read = strlen($result);
2104 if (@fwrite($fp, $result, $read) != $read) {
2105 @fclose($fp);
2106
2107 throw new ilDatabaseException('could not write to the output file');
2108 }
2109 }
2110 @fclose($fp);
2111
2112 return true;
2113 }
$result

References $result, and getDBInstance().

+ Here is the call graph for this function:

Field Documentation

◆ $allowed_attributes

ilDBPdoFieldDefinition::$allowed_attributes
Initial value:
= array(
"text" => array( "length", "notnull", "default", "fixed" ),
"integer" => array( "length", "notnull", "default", "unsigned" ),
"float" => array( "notnull", "default" ),
"date" => array( "notnull", "default" ),
"time" => array( "notnull", "default" ),
"timestamp" => array( "notnull", "default" ),
"clob" => array( "length", "notnull", "default" ),
"blob" => array( "length", "notnull", "default" ),
)

Definition at line 46 of file class.ilDBPdoFieldDefinition.php.

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

◆ $allowed_attributes_old

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

Definition at line 33 of file class.ilDBPdoFieldDefinition.php.

◆ $available_types

ilDBPdoFieldDefinition::$available_types
protected
Initial value:
= array(
self::T_TEXT,
self::T_INTEGER,
self::T_FLOAT,
self::T_DATE,
self::T_TIME,
self::T_TIMESTAMP,
self::T_CLOB,
self::T_BLOB,
)

Definition at line 70 of file class.ilDBPdoFieldDefinition.php.

Referenced by getAvailableTypes(), and setAvailableTypes().

◆ $db_instance

ilDBPdoFieldDefinition::$db_instance
protected

Definition at line 59 of file class.ilDBPdoFieldDefinition.php.

Referenced by getDBInstance().

◆ $instance

ilDBPdoFieldDefinition::$instance
staticprotected

Definition at line 29 of file class.ilDBPdoFieldDefinition.php.

◆ $max_length

ilDBPdoFieldDefinition::$max_length
protected
Initial value:
= array(
self::T_INTEGER => array( 1, 2, 3, 4, 8 ),
self::T_TEXT => 4000,
)

Definition at line 63 of file class.ilDBPdoFieldDefinition.php.

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

◆ $query_utils

ilDBPdoFieldDefinition::$query_utils
protected

Definition at line 813 of file class.ilDBPdoFieldDefinition.php.

Referenced by getQueryUtils().

◆ $reserved_mysql

ilDBPdoFieldDefinition::$reserved_mysql
protected

Definition at line 83 of file class.ilDBPdoFieldDefinition.php.

Referenced by getReservedMysql(), and setReservedMysql().

◆ $reserved_postgres

ilDBPdoFieldDefinition::$reserved_postgres
protected

Definition at line 713 of file class.ilDBPdoFieldDefinition.php.

Referenced by getReservedPostgres(), and setReservedPostgres().

◆ $valid_default_values

ilDBPdoFieldDefinition::$valid_default_values
protected
Initial value:
= array(
'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 843 of file class.ilDBPdoFieldDefinition.php.

Referenced by getDeclarationOptions(), and getValidTypes().

◆ DEFAULT_DECIMAL_PLACES

const ilDBPdoFieldDefinition::DEFAULT_DECIMAL_PLACES = 2

Definition at line 10 of file class.ilDBPdoFieldDefinition.php.

◆ DEFAULT_TEXT_LENGTH

const ilDBPdoFieldDefinition::DEFAULT_TEXT_LENGTH = 4000

Definition at line 11 of file class.ilDBPdoFieldDefinition.php.

◆ DEFINITION_COLUMN_NAME

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

Definition at line 12 of file class.ilDBPdoFieldDefinition.php.

◆ DEFINITION_TABLE_NAME

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

Definition at line 13 of file class.ilDBPdoFieldDefinition.php.

◆ INDEX_FORMAT

const ilDBPdoFieldDefinition::INDEX_FORMAT = '%s_idx'

◆ SEQUENCE_COLUMNS_NAME

const ilDBPdoFieldDefinition::SEQUENCE_COLUMNS_NAME = 'sequence'

Definition at line 15 of file class.ilDBPdoFieldDefinition.php.

◆ SEQUENCE_FORMAT

const ilDBPdoFieldDefinition::SEQUENCE_FORMAT = '%s_seq'

Definition at line 16 of file class.ilDBPdoFieldDefinition.php.

Referenced by ilDBPdo\getSequenceName().

◆ T_BLOB

const ilDBPdoFieldDefinition::T_BLOB = 'blob'

Definition at line 17 of file class.ilDBPdoFieldDefinition.php.

◆ T_CLOB

const ilDBPdoFieldDefinition::T_CLOB = 'clob'

Definition at line 18 of file class.ilDBPdoFieldDefinition.php.

◆ T_DATE

const ilDBPdoFieldDefinition::T_DATE = 'date'

Definition at line 19 of file class.ilDBPdoFieldDefinition.php.

◆ T_DATETIME

const ilDBPdoFieldDefinition::T_DATETIME = 'datetime'

Definition at line 20 of file class.ilDBPdoFieldDefinition.php.

◆ T_FLOAT

const ilDBPdoFieldDefinition::T_FLOAT = 'float'

Definition at line 21 of file class.ilDBPdoFieldDefinition.php.

◆ T_INTEGER

const ilDBPdoFieldDefinition::T_INTEGER = 'integer'

Definition at line 22 of file class.ilDBPdoFieldDefinition.php.

Referenced by checkColumnDefinition().

◆ T_TEXT

const ilDBPdoFieldDefinition::T_TEXT = 'text'

Definition at line 23 of file class.ilDBPdoFieldDefinition.php.

Referenced by checkColumnDefinition().

◆ T_TIME

const ilDBPdoFieldDefinition::T_TIME = 'time'

Definition at line 24 of file class.ilDBPdoFieldDefinition.php.

◆ T_TIMESTAMP

const ilDBPdoFieldDefinition::T_TIMESTAMP = 'timestamp'

Definition at line 25 of file class.ilDBPdoFieldDefinition.php.


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