ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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

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

References $type.

Referenced by convertResult().

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

◆ checkColumnDefinition()

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

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

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

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 ($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 (!in_array($a_def["length"], $max_length[self::T_INTEGER])) {
1036  if (isset($a_def["length"])) {
1037  throw new ilDatabaseException("Invalid length '" . $a_def["length"] . "' for type integer." . " Length must be "
1038  . implode(', ', $max_length[self::T_INTEGER]) . " (bytes).");
1039  }
1040  }
1041  if ($a_def["unsigned"]) {
1042  throw new ilDatabaseException("Unsigned attribut must not be true for type integer.");
1043  }
1044  break;
1045  }
1046 
1047  return true;
1048  }
Class ilDatabaseException.
+ Here is the call graph for this function:

◆ checkColumnName()

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

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

References isReserved().

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  }
Class ilDatabaseException.
+ Here is the call graph for this function:

◆ checkIndexName()

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

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

References isReserved().

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  }
Class ilDatabaseException.
+ Here is the call graph for this function:

◆ checkResultTypes()

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

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

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

1155  {
1156  $types = is_array($types) ? $types : array( $types );
1157  foreach ($types as $key => $type) {
1158  if (!isset($this->valid_default_values[$type])) {
1159  $db = $this->getDBInstance();
1160  if (empty($db->options['datatype_map'][$type])) {
1161  throw new ilDatabaseException($type . ' for ' . $key . ' is not a supported column type');
1162  }
1163  }
1164  }
1165 
1166  return $types;
1167  }
$type
Class ilDatabaseException.
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ checkTableName()

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

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

References isReserved().

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  }
Class ilDatabaseException.
+ Here is the call graph for this function:

◆ compareBLOBDefinition()

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

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

References $current, and compareTextDefinition().

1704  {
1705  return $this->compareTextDefinition($current, $previous);
1706  }
compareTextDefinition($current, $previous)
+ Here is the call graph for this function:

◆ compareBooleanDefinition()

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

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

1748  {
1749  return array();
1750  }

◆ compareCLOBDefinition()

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

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

References $current, and compareTextDefinition().

1693  {
1694  return $this->compareTextDefinition($current, $previous);
1695  }
compareTextDefinition($current, $previous)
+ Here is the call graph for this function:

◆ compareDateDefinition()

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

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

1715  {
1716  return array();
1717  }

◆ compareDecimalDefinition()

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

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

1770  {
1771  return array();
1772  }

◆ compareDefinition()

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

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

References $current, $default, $type, and getDBInstance().

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

◆ compareFloatDefinition()

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

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

1759  {
1760  return array();
1761  }

◆ compareIntegerDefinition()

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

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

References $current.

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

◆ compareTextDefinition()

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

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

References $current.

Referenced by compareBLOBDefinition(), and compareCLOBDefinition().

1670  {
1671  $change = array();
1672  $previous_length = !empty($previous['length']) ? $previous['length'] : 0;
1673  $length = !empty($current['length']) ? $current['length'] : 0;
1674  if ($previous_length != $length) {
1675  $change['length'] = true;
1676  }
1677  $previous_fixed = !empty($previous['fixed']) ? $previous['fixed'] : 0;
1678  $fixed = !empty($current['fixed']) ? $current['fixed'] : 0;
1679  if ($previous_fixed != $fixed) {
1680  $change['fixed'] = true;
1681  }
1682 
1683  return $change;
1684  }
+ Here is the caller graph for this function:

◆ compareTimeDefinition()

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

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

1726  {
1727  return array();
1728  }

◆ compareTimestampDefinition()

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

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

1737  {
1738  return array();
1739  }

◆ convertResult()

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

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

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

Referenced by convertResultRow().

1231  {
1232  throw new ilDatabaseException("deprecated");
1233  if (is_null($value)) {
1234  return null;
1235  }
1236  $db = $this->getDBInstance();
1237 
1238  if (!empty($db->options['datatype_map'][$type])) {
1239  $type = $db->options['datatype_map'][$type];
1240  if (!empty($db->options['datatype_map_callback'][$type])) {
1241  $parameter = array( 'type' => $type, 'value' => $value, 'rtrim' => $rtrim );
1242 
1243  return call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1244  }
1245  }
1246 
1247  return $this->baseConvertResult($value, $type, $rtrim);
1248  }
$type
baseConvertResult($value, $type, $rtrim=true)
Class ilDatabaseException.
+ 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 1257 of file class.ilDBPdoFieldDefinition.php.

References $key, $row, convertResult(), and sortResultFieldTypes().

1258  {
1259  throw new ilDatabaseException("deprecated");
1260  $types = $this->sortResultFieldTypes(array_keys($row), $types);
1261  foreach ($row as $key => $value) {
1262  if (empty($types[$key])) {
1263  continue;
1264  }
1265  $value = $this->convertResult($row[$key], $types[$key], $rtrim);
1266 
1267  $row[$key] = $value;
1268  }
1269 
1270  return $row;
1271  }
Class ilDatabaseException.
$row
$key
Definition: croninfo.php:18
convertResult($value, $type, $rtrim=true)
+ Here is the call graph for this function:

◆ destroyLOB()

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

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

References destroyLOBInternal().

2158  {
2159  $lob_data = stream_get_meta_data($lob);
2160  $lob_index = $lob_data['wrapper_data']->lob_index;
2161  fclose($lob);
2162  if (isset($this->lobs[$lob_index])) {
2163  $this->destroyLOBInternal($this->lobs[$lob_index]);
2164  unset($this->lobs[$lob_index]);
2165  }
2166 
2167  return true;
2168  }
+ Here is the call graph for this function:

◆ destroyLOBInternal()

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

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

Referenced by destroyLOB().

2176  {
2177  return true;
2178  }
+ Here is the caller graph for this function:

◆ endOfLOB()

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

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

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

◆ getAllowedAttributes()

ilDBPdoFieldDefinition::getAllowedAttributes ( )
Returns
array

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

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().

898  {
899  return array_merge($this->getReservedMysql(), $this->getReservedPostgres());
900  }
+ Here is the call graph for this function:

◆ getAvailableTypes()

ilDBPdoFieldDefinition::getAvailableTypes ( )
Returns
array

Definition at line 1065 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
|string

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

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

1516  {
1517  $db = $this->getDBInstance();
1518 
1519  $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
1520  $name = $db->quoteIdentifier($name, true);
1521 
1522  return $name . ' ' . $this->getTypeDeclaration($field) . $notnull;
1523  }
+ Here is the call graph for this function:

◆ getBooleanDeclaration()

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

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

References $name, and getInternalDeclaration().

1532  {
1533  return $this->getInternalDeclaration($name, $field);
1534  }
+ Here is the call graph for this function:

◆ getCharsetFieldDeclaration()

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

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

Referenced by getDeclarationOptions().

1449  {
1450  return '';
1451  }
+ Here is the caller graph for this function:

◆ getCLOBDeclaration()

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

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

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

1500  {
1501  $db = $this->getDBInstance();
1502 
1503  $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
1504  $name = $db->quoteIdentifier($name, true);
1505 
1506  return $name . ' ' . $this->getTypeDeclaration($field) . $notnull;
1507  }
+ Here is the call graph for this function:

◆ getCollationFieldDeclaration()

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

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

Referenced by getDeclarationOptions().

1459  {
1460  return '';
1461  }
+ Here is the caller graph for this function:

◆ getDateDeclaration()

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

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

References $name, and getInternalDeclaration().

1543  {
1544  return $this->getInternalDeclaration($name, $field);
1545  }
+ Here is the call graph for this function:

◆ getDBInstance()

◆ getDecimalDeclaration()

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

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

References $name, and getInternalDeclaration().

1587  {
1588  return $this->getInternalDeclaration($name, $field);
1589  }
+ Here is the call graph for this function:

◆ getDeclaration()

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

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

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

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

◆ getDeclarationOptions()

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

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

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

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

◆ getFloatDeclaration()

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

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

References $name, and getInternalDeclaration().

1576  {
1577  return $this->getInternalDeclaration($name, $field);
1578  }
+ Here is the call graph for this function:

◆ getIntegerDeclaration()

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

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

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

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

◆ getInternalDeclaration()

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

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

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

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

1390  {
1391  $db = $this->getDBInstance();
1392 
1393  $name = $db->quoteIdentifier($name, true);
1394  $declaration_options = $db->getFieldDefinition()->getDeclarationOptions($field);
1395 
1396  return $name . ' ' . $this->getTypeDeclaration($field) . $declaration_options;
1397  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMaxLength()

ilDBPdoFieldDefinition::getMaxLength ( )
Returns
array

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

References $max_length.

Referenced by checkColumnDefinition().

1102  {
1103  return $this->max_length;
1104  }
+ Here is the caller graph for this function:

◆ getQueryUtils()

ilDBPdoFieldDefinition::getQueryUtils ( )
protected
Returns

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

References $query_utils.

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.

◆ 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
|mixed
Exceptions

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

References $name, and getInternalDeclaration().

1489  {
1490  return $this->getInternalDeclaration($name, $field);
1491  }
+ Here is the call graph for this function:

◆ getTimeDeclaration()

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

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

References $name, and getInternalDeclaration().

1565  {
1566  return $this->getInternalDeclaration($name, $field);
1567  }
+ Here is the call graph for this function:

◆ getTimestampDeclaration()

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

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

References $name, and getInternalDeclaration().

1554  {
1555  return $this->getInternalDeclaration($name, $field);
1556  }
+ Here is the call graph for this function:

◆ getTypeDeclaration()

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

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

References getDBInstance().

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

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

◆ getValidTypes()

ilDBPdoFieldDefinition::getValidTypes ( )
Returns
array

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

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

Referenced by getDeclarationOptions().

1129  {
1130  $types = $this->valid_default_values;
1131  $db = $this->getDBInstance();
1132 
1133  if (!empty($db->options['datatype_map'])) {
1134  foreach ($db->options['datatype_map'] as $type => $mapped_type) {
1135  if (array_key_exists($mapped_type, $types)) {
1136  $types[$type] = $types[$mapped_type];
1137  } elseif (!empty($db->options['datatype_map_callback'][$type])) {
1138  $parameter = array( 'type' => $type, 'mapped_type' => $mapped_type );
1139  $default = call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1140  $types[$type] = $default;
1141  }
1142  }
1143  }
1144 
1145  return $types;
1146  }
$type
$default
Definition: build.php:20
+ 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

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

References $type, and quote().

2188  {
2189  if (!is_array($array) || empty($array)) {
2190  return 'NULL';
2191  }
2192  if ($type) {
2193  foreach ($array as $value) {
2194  $return[] = $this->quote($value, $type);
2195  }
2196  } else {
2197  $return = $array;
2198  }
2199 
2200  return implode(', ', $return);
2201  }
quote($value, $type=null, $quote=true, $escape_wildcards=false)
$type
+ Here is the call graph for this function:

◆ isAllowedAttribute()

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

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

References $type.

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

◆ isReserved()

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

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

Referenced by checkColumnName(), checkIndexName(), checkTableName(), and ilDBPdo\isReservedWord().

889  {
890  return false;
891  }
+ Here is the caller graph for this function:

◆ mapNativeDatatype()

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

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

References getDBInstance(), and mapNativeDatatypeInternal().

2268  {
2269  $db = $this->getDBInstance();
2270  $db_type = strtok($field['type'], '(), ');
2271  if (!empty($db->options['nativetype_map_callback'][$db_type])) {
2272  return call_user_func_array($db->options['nativetype_map_callback'][$db_type], array( $db, $field ));
2273  }
2274 
2275  return $this->mapNativeDatatypeInternal($field);
2276  }
mapNativeDatatypeInternal($field)
+ Here is the call graph for this function:

◆ mapNativeDatatypeInternal()

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

Referenced by mapNativeDatatype().

+ Here is the caller graph for this function:

◆ mapPrepareDatatype()

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

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

References $type, and getDBInstance().

2292  {
2293  $db = $this->getDBInstance();
2294 
2295  if (!empty($db->options['datatype_map'][$type])) {
2296  $type = $db->options['datatype_map'][$type];
2297  if (!empty($db->options['datatype_map_callback'][$type])) {
2298  $parameter = array( 'type' => $type );
2299 
2300  return call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
2301  }
2302  }
2303 
2304  return $type;
2305  }
$type
+ Here is the call graph for this function:

◆ matchPattern()

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

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

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

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

◆ patternEscapeString()

ilDBPdoFieldDefinition::patternEscapeString ( )
Returns
string

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

Referenced by matchPattern(), and quote().

2258  {
2259  return '';
2260  }
+ 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
|mixed|string
Exceptions

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

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

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

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

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

References quoteLOB().

1951  {
1952  return $this->quoteLOB($value, $quote, $escape_wildcards);
1953  }
quoteLOB($value, $quote, $escape_wildcards)
+ 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 1962 of file class.ilDBPdoFieldDefinition.php.

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

◆ quoteCLOB()

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

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

References quoteLOB().

1939  {
1940  return $this->quoteLOB($value, $quote, $escape_wildcards);
1941  }
quoteLOB($value, $quote, $escape_wildcards)
+ Here is the call graph for this function:

◆ quoteDate()

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

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

References getDBInstance(), and quoteText().

1975  {
1976  if ($value === 'CURRENT_DATE') {
1977  $db = $this->getDBInstance();
1978 
1979  return 'CURRENT_DATE';
1980  }
1981 
1982  return $this->quoteText($value, $quote, $escape_wildcards);
1983  }
quoteText($value, $quote, $escape_wildcards)
+ 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 2059 of file class.ilDBPdoFieldDefinition.php.

Referenced by quoteFloat().

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

References quoteDecimal().

2039  {
2040  if (preg_match('/^(.*)e([-+])(\d+)$/i', $value, $matches)) {
2041  $decimal = $this->quoteDecimal($matches[1], $quote, $escape_wildcards);
2042  $sign = $matches[2];
2043  $exponent = str_pad($matches[3], 2, '0', STR_PAD_LEFT);
2044  $value = $decimal . 'E' . $sign . $exponent;
2045  } else {
2046  $value = $this->quoteDecimal($value, $quote, $escape_wildcards);
2047  }
2048 
2049  return $value;
2050  }
quoteDecimal($value, $quote, $escape_wildcards)
+ 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 1859 of file class.ilDBPdoFieldDefinition.php.

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

◆ quoteLOB()

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

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

References quoteText(), and readFile().

Referenced by quoteBLOB(), and quoteCLOB().

1925  {
1926  $value = $this->readFile($value);
1927 
1928  return $this->quoteText($value, $quote, $escape_wildcards);
1929  }
quoteText($value, $quote, $escape_wildcards)
+ 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
|string

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

References getDBInstance().

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

1872  {
1873  if (!$quote) {
1874  return $value;
1875  }
1876 
1877  $db = $this->getDBInstance();
1878 
1879  $value = $db->escape($value, $escape_wildcards);
1880 
1881  return "'" . $value . "'";
1882  }
+ 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
|string

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

References getDBInstance(), and quoteText().

2016  {
2017  throw new ilDatabaseException("deprecated");
2018  if ($value === 'CURRENT_TIME') {
2019  $db = $this->getDBInstance();
2020 
2021  if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
2022  return $db->function->now('time');
2023  }
2024 
2025  return 'CURRENT_TIME';
2026  }
2027 
2028  return $this->quoteText($value, $quote, $escape_wildcards);
2029  }
Class ilDatabaseException.
quoteText($value, $quote, $escape_wildcards)
+ Here is the call graph for this function:

◆ quoteTimestamp()

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

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

References getDBInstance(), and quoteText().

1993  {
1994  throw new ilDatabaseException("deprecated");
1995  if ($value === 'CURRENT_TIMESTAMP') {
1996  $db = $this->getDBInstance();
1997 
1998  if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
1999  return $db->function->now('timestamp');
2000  }
2001 
2002  return 'CURRENT_TIMESTAMP';
2003  }
2004 
2005  return $this->quoteText($value, $quote, $escape_wildcards);
2006  }
Class ilDatabaseException.
quoteText($value, $quote, $escape_wildcards)
+ Here is the call graph for this function:

◆ readFile()

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

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

References getDBInstance().

Referenced by quoteLOB().

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

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

◆ retrieveLOB()

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

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

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

◆ setAllowedAttributes()

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

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

References $allowed_attributes.

1093  {
1094  $this->allowed_attributes = $allowed_attributes;
1095  }

◆ setAvailableTypes()

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

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

References $available_types.

1075  {
1076  $this->available_types = $available_types;
1077  }

◆ setMaxLength()

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

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

References $max_length.

1111  {
1112  $this->max_length = $max_length;
1113  }

◆ setReservedMysql()

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

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

References $reserved_mysql.

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

◆ setReservedPostgres()

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

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

References $reserved_postgres.

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

◆ sortResultFieldTypes()

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

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

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

Referenced by convertResultRow().

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

◆ writeLOBToFile()

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

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

References $result, and getDBInstance().

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

◆ T_TEXT

const ilDBPdoFieldDefinition::T_TEXT = 'text'

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

◆ 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: