ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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)
 
 getReservedOracle ()
 
 setReservedOracle ($reserved_oracle)
 
 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
 
 $reserved_oracle
 
 $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 935 of file class.ilDBPdoFieldDefinition.php.

936  {
937  $this->db_instance = $ilDBInterface;
938  }

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 1309 of file class.ilDBPdoFieldDefinition.php.

References $type, and array.

Referenced by convertResult().

1310  {
1311  switch ($type) {
1312  case 'text':
1313  if ($rtrim) {
1314  $value = rtrim($value);
1315  }
1316 
1317  return $value;
1318  case 'integer':
1319  return intval($value);
1320  case 'boolean':
1321  return !empty($value);
1322  case 'decimal':
1323  return $value;
1324  case 'float':
1325  return doubleval($value);
1326  case 'date':
1327  return $value;
1328  case 'time':
1329  return $value;
1330  case 'timestamp':
1331  return $value;
1332  case 'clob':
1333  case 'blob':
1334  $this->lobs[] = array(
1335  'buffer' => null,
1336  'position' => 0,
1337  'lob_index' => null,
1338  'endOfLOB' => false,
1339  'resource' => $value,
1340  'value' => null,
1341  'loaded' => false,
1342  );
1343  end($this->lobs);
1344  $lob_index = key($this->lobs);
1345  $this->lobs[$lob_index]['lob_index'] = $lob_index;
1346 
1347  return fopen('MDB2LOB://' . $lob_index . '@' . $this->db_index, 'r+');
1348  }
1349 
1350  throw new ilDatabaseException('attempt to convert result value to an unknown type :' . $type);
1351  }
$type
Class ilDatabaseException.
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ checkColumnDefinition()

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

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

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

1128  {
1129  // check valid type
1130  if (!in_array($a_def["type"], $this->getAvailableTypes())) {
1131  switch ($a_def["type"]) {
1132  case "boolean":
1133  throw new ilDatabaseException("Invalid column type '" . $a_def["type"] . "'. Use integer(1) instead.");
1134  break;
1135 
1136  case "decimal":
1137  throw new ilDatabaseException("Invalid column type '" . $a_def["type"] . "'. Use float or integer instead.");
1138  break;
1139 
1140  default:
1141  throw new ilDatabaseException("Invalid column type '" . $a_def["type"] . "'. Allowed types are: "
1142  . implode(', ', $this->getAvailableTypes()));
1143  }
1144  }
1145 
1146  // check used attributes
1148  foreach ($a_def as $k => $v) {
1149  if ($k != "type" && !in_array($k, $allowed_attributes[$a_def["type"]])) {
1150  throw new ilDatabaseException("Attribute '" . $k . "' is not allowed for column type '" . $a_def["type"] . "'.");
1151  }
1152  }
1153 
1154  // type specific checks
1155  $max_length = $this->getMaxLength();
1156  switch ($a_def["type"]) {
1157  case self::T_TEXT:
1158  if ($a_def["length"] < 1 || $a_def["length"] > $max_length[self::T_TEXT]) {
1159  if (isset($a_def["length"])) {
1160  throw new ilDatabaseException("Invalid length '" . $a_def["length"] . "' for type text." . " Length must be >=1 and <= "
1161  . $max_length[self::T_TEXT] . ".");
1162  }
1163  }
1164  break;
1165 
1166  case self::T_INTEGER:
1167  if (!in_array($a_def["length"], $max_length[self::T_INTEGER])) {
1168  if (isset($a_def["length"])) {
1169  throw new ilDatabaseException("Invalid length '" . $a_def["length"] . "' for type integer." . " Length must be "
1170  . implode(', ', $max_length[self::T_INTEGER]) . " (bytes).");
1171  }
1172  }
1173  if ($a_def["unsigned"]) {
1174  throw new ilDatabaseException("Unsigned attribut must not be true for type integer.");
1175  }
1176  break;
1177  }
1178 
1179  return true;
1180  }
Class ilDatabaseException.
+ Here is the call graph for this function:

◆ checkColumnName()

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

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

References isReserved().

1077  {
1078  if (!preg_match("/^[a-z]+[_a-z0-9]*$/", $column_name)) {
1079  throw new ilDatabaseException("Invalid column name '" . $column_name
1080  . "'. Column name must only contain _a-z0-9 and must start with a-z.");
1081  }
1082 
1083  if ($this->isReserved($column_name)) {
1084  throw new ilDatabaseException("Invalid column name '" . $column_name . "' (Reserved Word).");
1085  }
1086 
1087  if (strtolower(substr($column_name, 0, 4)) == "sys_") {
1088  throw new ilDatabaseException("Invalid column name '" . $column_name . "'. Name must not start with 'sys_'.");
1089  }
1090 
1091  if (strlen($column_name) > 30) {
1092  throw new ilDatabaseException("Invalid column name '" . $column_name . "'. Maximum column identifer length is 30 bytes.");
1093  }
1094 
1095  return true;
1096  }
Class ilDatabaseException.
+ Here is the call graph for this function:

◆ checkIndexName()

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

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

References isReserved().

1105  {
1106  if (!preg_match("/^[a-z]+[_a-z0-9]*$/", $a_name)) {
1107  throw new ilDatabaseException("Invalid column name '" . $a_name . "'. Column name must only contain _a-z0-9 and must start with a-z.");
1108  }
1109 
1110  if ($this->isReserved($a_name)) {
1111  throw new ilDatabaseException("Invalid column name '" . $a_name . "' (Reserved Word).");
1112  }
1113 
1114  if (strlen($a_name) > 3) {
1115  throw new ilDatabaseException("Invalid index name '" . $a_name . "'. Maximum index identifer length is 3 bytes.");
1116  }
1117 
1118  return true;
1119  }
Class ilDatabaseException.
+ Here is the call graph for this function:

◆ checkResultTypes()

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

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

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

1287  {
1288  $types = is_array($types) ? $types : array( $types );
1289  foreach ($types as $key => $type) {
1290  if (!isset($this->valid_default_values[$type])) {
1291  $db = $this->getDBInstance();
1292  if (empty($db->options['datatype_map'][$type])) {
1293  throw new ilDatabaseException($type . ' for ' . $key . ' is not a supported column type');
1294  }
1295  }
1296  }
1297 
1298  return $types;
1299  }
$type
Class ilDatabaseException.
Create styles array
The data for the language used.
$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 976 of file class.ilDBPdoFieldDefinition.php.

References isReserved().

977  {
978  if (!preg_match(self::DEFINITION_TABLE_NAME, $table_name)) {
979  throw new ilDatabaseException('Table name must only contain _a-z0-9 and must start with a-z.');
980  }
981 
982  if ($this->isReserved($table_name)) {
983  throw new ilDatabaseException("Invalid table name '" . $table_name . "' (Reserved Word).");
984  }
985 
986  if (strtolower(substr($table_name, 0, 4)) == "sys_") {
987  throw new ilDatabaseException("Invalid table name '" . $table_name . "'. Name must not start with 'sys_'.");
988  }
989 
990  if (strlen($table_name) > 22) {
991  throw new ilDatabaseException("Invalid table name '" . $table_name . "'. Maximum table identifer length is 22 bytes.");
992  }
993 
994  return true;
995  }
Class ilDatabaseException.
+ Here is the call graph for this function:

◆ compareBLOBDefinition()

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

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

References $current, and compareTextDefinition().

1833  {
1834  return $this->compareTextDefinition($current, $previous);
1835  }
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 1876 of file class.ilDBPdoFieldDefinition.php.

References array.

1877  {
1878  return array();
1879  }
Create styles array
The data for the language used.

◆ compareCLOBDefinition()

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

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

References $current, and compareTextDefinition().

1822  {
1823  return $this->compareTextDefinition($current, $previous);
1824  }
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 1843 of file class.ilDBPdoFieldDefinition.php.

References array.

1844  {
1845  return array();
1846  }
Create styles array
The data for the language used.

◆ compareDecimalDefinition()

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

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

References array.

1899  {
1900  return array();
1901  }
Create styles array
The data for the language used.

◆ compareDefinition()

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

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

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

1728  {
1729  $type = !empty($current['type']) ? $current['type'] : null;
1730 
1731  if (!method_exists($this, "compare{$type}Definition")) {
1732  $db = $this->getDBInstance();
1733 
1734  if (!empty($db->options['datatype_map_callback'][$type])) {
1735  $parameter = array( 'current' => $current, 'previous' => $previous );
1736  $change = call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1737 
1738  return $change;
1739  }
1740 
1741  throw new ilDatabaseException('type "' . $current['type'] . '" is not yet supported');
1742  }
1743 
1744  if (empty($previous['type']) || $previous['type'] != $type) {
1745  return $current;
1746  }
1747 
1748  $change = $this->{"compare{$type}Definition"}($current, $previous);
1749 
1750  if ($previous['type'] != $type) {
1751  $change['type'] = true;
1752  }
1753 
1754  $previous_notnull = !empty($previous['notnull']) ? $previous['notnull'] : false;
1755  $notnull = !empty($current['notnull']) ? $current['notnull'] : false;
1756  if ($previous_notnull != $notnull) {
1757  $change['notnull'] = true;
1758  }
1759 
1760  $previous_default = array_key_exists('default', $previous) ? $previous['default'] : ($previous_notnull ? '' : null);
1761  $default = array_key_exists('default', $current) ? $current['default'] : ($notnull ? '' : null);
1762  if ($previous_default !== $default) {
1763  $change['default'] = true;
1764  }
1765 
1766  return $change;
1767  }
$type
Class ilDatabaseException.
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ compareFloatDefinition()

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

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

References array.

1888  {
1889  return array();
1890  }
Create styles array
The data for the language used.

◆ compareIntegerDefinition()

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

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

References $current, and array.

1776  {
1777  $change = array();
1778  $previous_unsigned = !empty($previous['unsigned']) ? $previous['unsigned'] : false;
1779  $unsigned = !empty($current['unsigned']) ? $current['unsigned'] : false;
1780  if ($previous_unsigned != $unsigned) {
1781  $change['unsigned'] = true;
1782  }
1783  $previous_autoincrement = !empty($previous['autoincrement']) ? $previous['autoincrement'] : false;
1784  $autoincrement = !empty($current['autoincrement']) ? $current['autoincrement'] : false;
1785  if ($previous_autoincrement != $autoincrement) {
1786  $change['autoincrement'] = true;
1787  }
1788 
1789  return $change;
1790  }
Create styles array
The data for the language used.

◆ compareTextDefinition()

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

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

References $current, and array.

Referenced by compareBLOBDefinition(), and compareCLOBDefinition().

1799  {
1800  $change = array();
1801  $previous_length = !empty($previous['length']) ? $previous['length'] : 0;
1802  $length = !empty($current['length']) ? $current['length'] : 0;
1803  if ($previous_length != $length) {
1804  $change['length'] = true;
1805  }
1806  $previous_fixed = !empty($previous['fixed']) ? $previous['fixed'] : 0;
1807  $fixed = !empty($current['fixed']) ? $current['fixed'] : 0;
1808  if ($previous_fixed != $fixed) {
1809  $change['fixed'] = true;
1810  }
1811 
1812  return $change;
1813  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ compareTimeDefinition()

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

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

References array.

1855  {
1856  return array();
1857  }
Create styles array
The data for the language used.

◆ compareTimestampDefinition()

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

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

References array.

1866  {
1867  return array();
1868  }
Create styles array
The data for the language used.

◆ convertResult()

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

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

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

Referenced by convertResultRow().

1362  {
1363  if (is_null($value)) {
1364  return null;
1365  }
1366  $db = $this->getDBInstance();
1367 
1368  if (!empty($db->options['datatype_map'][$type])) {
1369  $type = $db->options['datatype_map'][$type];
1370  if (!empty($db->options['datatype_map_callback'][$type])) {
1371  $parameter = array( 'type' => $type, 'value' => $value, 'rtrim' => $rtrim );
1372 
1373  return call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1374  }
1375  }
1376 
1377  return $this->baseConvertResult($value, $type, $rtrim);
1378  }
$type
baseConvertResult($value, $type, $rtrim=true)
Create styles array
The data for the language used.
+ 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 1387 of file class.ilDBPdoFieldDefinition.php.

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

1388  {
1389  $types = $this->sortResultFieldTypes(array_keys($row), $types);
1390  foreach ($row as $key => $value) {
1391  if (empty($types[$key])) {
1392  continue;
1393  }
1394  $value = $this->convertResult($row[$key], $types[$key], $rtrim);
1395 
1396  $row[$key] = $value;
1397  }
1398 
1399  return $row;
1400  }
$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 2284 of file class.ilDBPdoFieldDefinition.php.

References destroyLOBInternal().

2285  {
2286  $lob_data = stream_get_meta_data($lob);
2287  $lob_index = $lob_data['wrapper_data']->lob_index;
2288  fclose($lob);
2289  if (isset($this->lobs[$lob_index])) {
2290  $this->destroyLOBInternal($this->lobs[$lob_index]);
2291  unset($this->lobs[$lob_index]);
2292  }
2293 
2294  return true;
2295  }
+ Here is the call graph for this function:

◆ destroyLOBInternal()

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

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

Referenced by destroyLOB().

2303  {
2304  return true;
2305  }
+ Here is the caller graph for this function:

◆ endOfLOB()

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

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

2275  {
2276  return $lob['endOfLOB'];
2277  }

◆ getAllowedAttributes()

ilDBPdoFieldDefinition::getAllowedAttributes ( )
Returns
array

Definition at line 1215 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 1011 of file class.ilDBPdoFieldDefinition.php.

References getReservedMysql(), getReservedOracle(), and getReservedPostgres().

+ Here is the call graph for this function:

◆ getAvailableTypes()

ilDBPdoFieldDefinition::getAvailableTypes ( )
Returns
array

Definition at line 1197 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 1644 of file class.ilDBPdoFieldDefinition.php.

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

1645  {
1646  $db = $this->getDBInstance();
1647 
1648  $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
1649  $name = $db->quoteIdentifier($name, true);
1650 
1651  return $name . ' ' . $this->getTypeDeclaration($field) . $notnull;
1652  }
if($format !==null) $name
Definition: metadata.php:146
+ Here is the call graph for this function:

◆ getBooleanDeclaration()

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

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

References $name, and getInternalDeclaration().

1661  {
1662  return $this->getInternalDeclaration($name, $field);
1663  }
if($format !==null) $name
Definition: metadata.php:146
+ Here is the call graph for this function:

◆ getCharsetFieldDeclaration()

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

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

Referenced by getDeclarationOptions().

1578  {
1579  return '';
1580  }
+ Here is the caller graph for this function:

◆ getCLOBDeclaration()

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

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

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

1629  {
1630  $db = $this->getDBInstance();
1631 
1632  $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
1633  $name = $db->quoteIdentifier($name, true);
1634 
1635  return $name . ' ' . $this->getTypeDeclaration($field) . $notnull;
1636  }
if($format !==null) $name
Definition: metadata.php:146
+ Here is the call graph for this function:

◆ getCollationFieldDeclaration()

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

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

Referenced by getDeclarationOptions().

1588  {
1589  return '';
1590  }
+ Here is the caller graph for this function:

◆ getDateDeclaration()

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

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

References $name, and getInternalDeclaration().

1672  {
1673  return $this->getInternalDeclaration($name, $field);
1674  }
if($format !==null) $name
Definition: metadata.php:146
+ Here is the call graph for this function:

◆ getDBInstance()

◆ getDecimalDeclaration()

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

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

References $name, and getInternalDeclaration().

1716  {
1717  return $this->getInternalDeclaration($name, $field);
1718  }
if($format !==null) $name
Definition: metadata.php:146
+ Here is the call graph for this function:

◆ getDeclaration()

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

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

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

1453  {
1454  $db = $this->getDBInstance();
1455 
1456  if (!empty($db->options['datatype_map'][$type])) {
1457  $type = $db->options['datatype_map'][$type];
1458  if (!empty($db->options['datatype_map_callback'][$type])) {
1459  $parameter = array( 'type' => $type, 'name' => $name, 'field' => $field );
1460 
1461  return call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1462  }
1463  $field['type'] = $type;
1464  }
1465 
1466  if (!method_exists($this, "get{$type}Declaration")) {
1467  throw new ilDatabaseException('type not defined: ' . $type);
1468  }
1469 
1470  return $this->{"get{$type}Declaration"}($name, $field);
1471  }
$type
Class ilDatabaseException.
if($format !==null) $name
Definition: metadata.php:146
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ getDeclarationOptions()

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

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

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

1535  {
1536  $charset = empty($field['charset']) ? '' : ' ' . $this->getCharsetFieldDeclaration($field['charset']);
1537 
1538  $default = '';
1539  if (array_key_exists('default', $field)) {
1540  if ($field['default'] === '') {
1541  $db = $this->getDBInstance();
1542 
1543  if (empty($field['notnull'])) {
1544  $field['default'] = null;
1545  } else {
1547  $field['default'] = $valid_default_values[$field['type']];
1548  }
1549  if ($field['default'] === ''
1550  && ($db->options['portability'] & 32)
1551  ) {
1552  $field['default'] = ' ';
1553  }
1554  }
1555  $default = ' DEFAULT ' . $this->quote($field['default'], $field['type']);
1556  } elseif (empty($field['notnull'])) {
1557  $default = ' DEFAULT NULL';
1558  }
1559 
1560  $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
1561  // alex patch 28 Nov 2011 start
1562  if ($field['notnull'] === false) {
1563  $notnull = " NULL";
1564  }
1565  // alex patch 28 Nov 2011 end
1566 
1567  $collation = empty($field['collation']) ? '' : ' ' . $this->getCollationFieldDeclaration($field['collation']);
1568 
1569  return $charset . $default . $notnull . $collation;
1570  }
quote($value, $type=null, $quote=true, $escape_wildcards=false)
+ Here is the call graph for this function:

◆ getFloatDeclaration()

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

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

References $name, and getInternalDeclaration().

1705  {
1706  return $this->getInternalDeclaration($name, $field);
1707  }
if($format !==null) $name
Definition: metadata.php:146
+ Here is the call graph for this function:

◆ getIntegerDeclaration()

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

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

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

1600  {
1601  if (!empty($field['unsigned'])) {
1602  $db = $this->getDBInstance();
1603 
1604  $db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer";
1605  }
1606 
1607  return $this->getInternalDeclaration($name, $field);
1608  }
if($format !==null) $name
Definition: metadata.php:146
+ Here is the call graph for this function:

◆ getInternalDeclaration()

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

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

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

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

1519  {
1520  $db = $this->getDBInstance();
1521 
1522  $name = $db->quoteIdentifier($name, true);
1523  $declaration_options = $db->getFieldDefinition()->getDeclarationOptions($field);
1524 
1525  return $name . ' ' . $this->getTypeDeclaration($field) . $declaration_options;
1526  }
if($format !==null) $name
Definition: metadata.php:146
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMaxLength()

ilDBPdoFieldDefinition::getMaxLength ( )
Returns
array

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

References $max_length.

Referenced by checkColumnDefinition().

1234  {
1235  return $this->max_length;
1236  }
+ Here is the caller graph for this function:

◆ getQueryUtils()

ilDBPdoFieldDefinition::getQueryUtils ( )
protected
Returns

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

References $query_utils.

945  {
946  if (!$this->query_utils) {
947  $this->query_utils = new ilMySQLQueryUtils($this->db_instance);
948  }
949 
950  return $this->query_utils;
951  }
Class ilMySQLQueryUtils.

◆ getReservedMysql()

ilDBPdoFieldDefinition::getReservedMysql ( )
Returns
array

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

References $reserved_mysql.

Referenced by getAllReserved().

+ Here is the caller graph for this function:

◆ getReservedOracle()

ilDBPdoFieldDefinition::getReservedOracle ( )
Returns
array

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

References $reserved_oracle.

Referenced by getAllReserved().

+ Here is the caller graph for this function:

◆ getReservedPostgres()

ilDBPdoFieldDefinition::getReservedPostgres ( )
Returns
array

Definition at line 1038 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 1617 of file class.ilDBPdoFieldDefinition.php.

References $name, and getInternalDeclaration().

1618  {
1619  return $this->getInternalDeclaration($name, $field);
1620  }
if($format !==null) $name
Definition: metadata.php:146
+ Here is the call graph for this function:

◆ getTimeDeclaration()

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

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

References $name, and getInternalDeclaration().

1694  {
1695  return $this->getInternalDeclaration($name, $field);
1696  }
if($format !==null) $name
Definition: metadata.php:146
+ Here is the call graph for this function:

◆ getTimestampDeclaration()

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

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

References $name, and getInternalDeclaration().

1683  {
1684  return $this->getInternalDeclaration($name, $field);
1685  }
if($format !==null) $name
Definition: metadata.php:146
+ Here is the call graph for this function:

◆ getTypeDeclaration()

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

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

References getDBInstance().

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

1479  {
1480  $db = $this->getDBInstance();
1481 
1482  switch ($field['type']) {
1483  case 'text':
1484  $length = !empty($field['length']) ? $field['length'] : $db->options['default_text_field_length'];
1485  $fixed = !empty($field['fixed']) ? $field['fixed'] : false;
1486 
1487  return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(' . $db->options['default_text_field_length']
1488  . ')') : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
1489  case 'clob':
1490  return 'TEXT';
1491  case 'blob':
1492  return 'TEXT';
1493  case 'integer':
1494  return 'INT';
1495  case 'boolean':
1496  return 'INT';
1497  case 'date':
1498  return 'CHAR (' . strlen('YYYY-MM-DD') . ')';
1499  case 'time':
1500  return 'CHAR (' . strlen('HH:MM:SS') . ')';
1501  case 'timestamp':
1502  return 'CHAR (' . strlen('YYYY-MM-DD HH:MM:SS') . ')';
1503  case 'float':
1504  return 'TEXT';
1505  case 'decimal':
1506  return 'TEXT';
1507  }
1508 
1509  return '';
1510  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getValidTypes()

ilDBPdoFieldDefinition::getValidTypes ( )
Returns
array

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

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

Referenced by getDeclarationOptions().

1261  {
1262  $types = $this->valid_default_values;
1263  $db = $this->getDBInstance();
1264 
1265  if (!empty($db->options['datatype_map'])) {
1266  foreach ($db->options['datatype_map'] as $type => $mapped_type) {
1267  if (array_key_exists($mapped_type, $types)) {
1268  $types[$type] = $types[$mapped_type];
1269  } elseif (!empty($db->options['datatype_map_callback'][$type])) {
1270  $parameter = array( 'type' => $type, 'mapped_type' => $mapped_type );
1271  $default = call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1272  $types[$type] = $default;
1273  }
1274  }
1275  }
1276 
1277  return $types;
1278  }
$type
Create styles array
The data for the language used.
+ 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 2314 of file class.ilDBPdoFieldDefinition.php.

References $type, and quote().

2315  {
2316  if (!is_array($array) || empty($array)) {
2317  return 'NULL';
2318  }
2319  if ($type) {
2320  foreach ($array as $value) {
2321  $return[] = $this->quote($value, $type);
2322  }
2323  } else {
2324  $return = $array;
2325  }
2326 
2327  return implode(', ', $return);
2328  }
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 1188 of file class.ilDBPdoFieldDefinition.php.

References $type.

1189  {
1190  return in_array($attribute, $this->allowed_attributes[$type]);
1191  }
$type

◆ isReserved()

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

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

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

1003  {
1004  return false;
1005  }
+ Here is the caller graph for this function:

◆ mapNativeDatatype()

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

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

References array, getDBInstance(), and mapNativeDatatypeInternal().

2395  {
2396  $db = $this->getDBInstance();
2397  $db_type = strtok($field['type'], '(), ');
2398  if (!empty($db->options['nativetype_map_callback'][$db_type])) {
2399  return call_user_func_array($db->options['nativetype_map_callback'][$db_type], array( $db, $field ));
2400  }
2401 
2402  return $this->mapNativeDatatypeInternal($field);
2403  }
Create styles array
The data for the language used.
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 2418 of file class.ilDBPdoFieldDefinition.php.

References $type, array, and getDBInstance().

2419  {
2420  $db = $this->getDBInstance();
2421 
2422  if (!empty($db->options['datatype_map'][$type])) {
2423  $type = $db->options['datatype_map'][$type];
2424  if (!empty($db->options['datatype_map_callback'][$type])) {
2425  $parameter = array( 'type' => $type );
2426 
2427  return call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
2428  }
2429  }
2430 
2431  return $type;
2432  }
$type
Create styles array
The data for the language used.
+ 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 2338 of file class.ilDBPdoFieldDefinition.php.

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

2339  {
2340  $db = $this->getDBInstance();
2341 
2342  $match = '';
2343  if (!is_null($operator)) {
2344  $operator = strtoupper($operator);
2345  switch ($operator) {
2346  // case insensitive
2347  case 'ILIKE':
2348  if (is_null($field)) {
2349  throw new ilDatabaseException('case insensitive LIKE matching requires passing the field name');
2350  }
2351  $db->loadModule('Function', null, true);
2352  $match = $db->function->lower($field) . ' LIKE ';
2353  break;
2354  // case sensitive
2355  case 'LIKE':
2356  $match = is_null($field) ? 'LIKE ' : $field . ' LIKE ';
2357  break;
2358  default:
2359  throw new ilDatabaseException('not a supported operator type:' . $operator);
2360  }
2361  }
2362  $match .= "'";
2363  foreach ($pattern as $key => $value) {
2364  if ($key % 2) {
2365  $match .= $value;
2366  } else {
2367  if ($operator === 'ILIKE') {
2368  $value = strtolower($value);
2369  }
2370  $escaped = $db->escape($value);
2371  $match .= $db->escapePattern($escaped);
2372  }
2373  }
2374  $match .= "'";
2375  $match .= $this->patternEscapeString();
2376 
2377  return $match;
2378  }
Class ilDatabaseException.
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ patternEscapeString()

ilDBPdoFieldDefinition::patternEscapeString ( )
Returns
string

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

Referenced by matchPattern(), and quote().

2385  {
2386  return '';
2387  }
+ 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 1912 of file class.ilDBPdoFieldDefinition.php.

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

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

1913  {
1914  $db = $this->getDBInstance();
1915 
1916  return $db->quote($value, $type);
1917 
1918  if (is_null($value)
1919  || ($value === '' && $db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)
1920  ) {
1921  if (!$quote) {
1922  return null;
1923  }
1924 
1925  return 'NULL';
1926  }
1927 
1928  if (is_null($type)) {
1929  switch (gettype($value)) {
1930  case 'integer':
1931  $type = 'integer';
1932  break;
1933  case 'double':
1934  // todo: default to decimal as float is quite unusual
1935  // $type = 'float';
1936  $type = 'decimal';
1937  break;
1938  case 'boolean':
1939  $type = 'boolean';
1940  break;
1941  case 'array':
1942  $value = serialize($value);
1943  // no break
1944  case 'object':
1945  $type = 'text';
1946  break;
1947  default:
1948  if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/', $value)) {
1949  $type = 'timestamp';
1950  } elseif (preg_match('/^\d{2}:\d{2}$/', $value)) {
1951  $type = 'time';
1952  } elseif (preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) {
1953  $type = 'date';
1954  } else {
1955  $type = 'text';
1956  }
1957  break;
1958  }
1959  } elseif (!empty($db->options['datatype_map'][$type])) {
1960  $type = $db->options['datatype_map'][$type];
1961  if (!empty($db->options['datatype_map_callback'][$type])) {
1962  $parameter = array( 'type' => $type, 'value' => $value, 'quote' => $quote, 'escape_wildcards' => $escape_wildcards );
1963 
1964  return call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1965  }
1966  }
1967 
1968  if (!method_exists($this, "quote{$type}")) {
1969  throw new ilDatabaseException('type not defined: ' . $type);
1970  }
1971  $value = $this->{"quote{$type}"}($value, $quote, $escape_wildcards);
1972  if ($quote && $escape_wildcards && $db->string_quoting['escape_pattern']
1973  && $db->string_quoting['escape'] !== $db->string_quoting['escape_pattern']
1974  ) {
1975  $value .= $this->patternEscapeString();
1976  }
1977 
1978  return $value;
1979  }
$type
const MDB2_PORTABILITY_EMPTY_TO_NULL
Portability: convert empty values to null strings in data output by query*() and fetch*().
Definition: MDB2.php:203
Class ilDatabaseException.
Create styles array
The data for the language used.
+ 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 2079 of file class.ilDBPdoFieldDefinition.php.

References quoteLOB().

2080  {
2081  return $this->quoteLOB($value, $quote, $escape_wildcards);
2082  }
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 2091 of file class.ilDBPdoFieldDefinition.php.

2092  {
2093  return ($value ? 1 : 0);
2094  }

◆ quoteCLOB()

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

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

References quoteLOB().

2068  {
2069  return $this->quoteLOB($value, $quote, $escape_wildcards);
2070  }
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 2103 of file class.ilDBPdoFieldDefinition.php.

References getDBInstance(), and quoteText().

2104  {
2105  if ($value === 'CURRENT_DATE') {
2106  $db = $this->getDBInstance();
2107 
2108  return 'CURRENT_DATE';
2109  }
2110 
2111  return $this->quoteText($value, $quote, $escape_wildcards);
2112  }
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 2186 of file class.ilDBPdoFieldDefinition.php.

References string.

Referenced by quoteFloat().

2187  {
2188  $value = (string) $value;
2189  $value = preg_replace('/[^\d\.,\-+eE]/', '', $value);
2190  if (preg_match('/[^.0-9]/', $value)) {
2191  if (strpos($value, ',')) {
2192  // 1000,00
2193  if (!strpos($value, '.')) {
2194  // convert the last "," to a "."
2195  $value = strrev(str_replace(',', '.', strrev($value)));
2196  // 1.000,00
2197  } elseif (strpos($value, '.') && strpos($value, '.') < strpos($value, ',')) {
2198  $value = str_replace('.', '', $value);
2199  // convert the last "," to a "."
2200  $value = strrev(str_replace(',', '.', strrev($value)));
2201  // 1,000.00
2202  } else {
2203  $value = str_replace(',', '', $value);
2204  }
2205  }
2206  }
2207 
2208  return $value;
2209  }
Add rich text string
+ 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 2165 of file class.ilDBPdoFieldDefinition.php.

References quoteDecimal().

2166  {
2167  if (preg_match('/^(.*)e([-+])(\d+)$/i', $value, $matches)) {
2168  $decimal = $this->quoteDecimal($matches[1], $quote, $escape_wildcards);
2169  $sign = $matches[2];
2170  $exponent = str_pad($matches[3], 2, '0', STR_PAD_LEFT);
2171  $value = $decimal . 'E' . $sign . $exponent;
2172  } else {
2173  $value = $this->quoteDecimal($value, $quote, $escape_wildcards);
2174  }
2175 
2176  return $value;
2177  }
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 1988 of file class.ilDBPdoFieldDefinition.php.

1989  {
1990  return (int) $value;
1991  }

◆ quoteLOB()

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

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

References quoteText(), and readFile().

Referenced by quoteBLOB(), and quoteCLOB().

2054  {
2055  $value = $this->readFile($value);
2056 
2057  return $this->quoteText($value, $quote, $escape_wildcards);
2058  }
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 2000 of file class.ilDBPdoFieldDefinition.php.

References getDBInstance().

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

2001  {
2002  if (!$quote) {
2003  return $value;
2004  }
2005 
2006  $db = $this->getDBInstance();
2007 
2008  $value = $db->escape($value, $escape_wildcards);
2009 
2010  return "'" . $value . "'";
2011  }
+ 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 2143 of file class.ilDBPdoFieldDefinition.php.

References getDBInstance(), and quoteText().

2144  {
2145  if ($value === 'CURRENT_TIME') {
2146  $db = $this->getDBInstance();
2147 
2148  if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
2149  return $db->function->now('time');
2150  }
2151 
2152  return 'CURRENT_TIME';
2153  }
2154 
2155  return $this->quoteText($value, $quote, $escape_wildcards);
2156  }
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 2121 of file class.ilDBPdoFieldDefinition.php.

References getDBInstance(), and quoteText().

2122  {
2123  if ($value === 'CURRENT_TIMESTAMP') {
2124  $db = $this->getDBInstance();
2125 
2126  if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
2127  return $db->function->now('timestamp');
2128  }
2129 
2130  return 'CURRENT_TIMESTAMP';
2131  }
2132 
2133  return $this->quoteText($value, $quote, $escape_wildcards);
2134  }
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 2018 of file class.ilDBPdoFieldDefinition.php.

References getDBInstance().

Referenced by quoteLOB().

2019  {
2020  $close = false;
2021  if (preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) {
2022  $close = true;
2023  if ($match[1] == 'file://') {
2024  $value = $match[2];
2025  }
2026  // do not try to open urls
2027  #$value = @fopen($value, 'r');
2028  }
2029 
2030  if (is_resource($value)) {
2031  $db = $this->getDBInstance();
2032 
2033  $fp = $value;
2034  $value = '';
2035  while (!@feof($fp)) {
2036  $value .= @fread($fp, $db->options['lob_buffer_length']);
2037  }
2038  if ($close) {
2039  @fclose($fp);
2040  }
2041  }
2042 
2043  return $value;
2044  }
+ 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 2264 of file class.ilDBPdoFieldDefinition.php.

2265  {
2266  return substr($lob['value'], $lob['position'], $length);
2267  }

◆ retrieveLOB()

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

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

References MDB2_OK.

2249  {
2250  if (is_null($lob['value'])) {
2251  $lob['value'] = $lob['resource'];
2252  }
2253  $lob['loaded'] = true;
2254 
2255  return MDB2_OK;
2256  }
const MDB2_OK(!class_exists('PEAR'))
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these...
Definition: MDB2.php:72

◆ setAllowedAttributes()

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

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

References $allowed_attributes.

1225  {
1226  $this->allowed_attributes = $allowed_attributes;
1227  }

◆ setAvailableTypes()

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

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

References $available_types.

1207  {
1208  $this->available_types = $available_types;
1209  }

◆ setMaxLength()

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

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

References $max_length.

1243  {
1244  $this->max_length = $max_length;
1245  }

◆ setReservedMysql()

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

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

References $reserved_mysql.

1030  {
1031  $this->reserved_mysql = $reserved_mysql;
1032  }

◆ setReservedOracle()

ilDBPdoFieldDefinition::setReservedOracle (   $reserved_oracle)
Parameters
array$reserved_oracle

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

References $reserved_oracle.

1066  {
1067  $this->reserved_oracle = $reserved_oracle;
1068  }

◆ setReservedPostgres()

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

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

References $reserved_postgres.

1048  {
1049  $this->reserved_postgres = $reserved_postgres;
1050  }

◆ sortResultFieldTypes()

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

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

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

Referenced by convertResultRow().

1411  {
1412  $n_cols = count($columns);
1413  $n_types = count($types);
1414  if ($n_cols > $n_types) {
1415  for ($i = $n_cols - $n_types; $i >= 0; $i--) {
1416  $types[] = null;
1417  }
1418  }
1419  $sorted_types = array();
1420  foreach ($columns as $col) {
1421  $sorted_types[$col] = null;
1422  }
1423  foreach ($types as $name => $type) {
1424  if (array_key_exists($name, $sorted_types)) {
1425  $sorted_types[$name] = $type;
1426  unset($types[$name]);
1427  }
1428  }
1429  // if there are left types in the array, fill the null values of the
1430  // sorted array with them, in order.
1431  if (count($types)) {
1432  reset($types);
1433  foreach (array_keys($sorted_types) as $k) {
1434  if (is_null($sorted_types[$k])) {
1435  $sorted_types[$k] = current($types);
1436  next($types);
1437  }
1438  }
1439  }
1440 
1441  return $sorted_types;
1442  }
$type
if($format !==null) $name
Definition: metadata.php:146
Create styles array
The data for the language used.
$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 2218 of file class.ilDBPdoFieldDefinition.php.

References $file, $result, getDBInstance(), and MDB2_OK.

2219  {
2220  $db = $this->getDBInstance();
2221 
2222  if (preg_match('/^(\w+:\/\/)(.*)$/', $file, $match)) {
2223  if ($match[1] == 'file://') {
2224  $file = $match[2];
2225  }
2226  }
2227 
2228  $fp = @fopen($file, 'wb');
2229  while (!@feof($lob)) {
2230  $result = @fread($lob, $db->options['lob_buffer_length']);
2231  $read = strlen($result);
2232  if (@fwrite($fp, $result, $read) != $read) {
2233  @fclose($fp);
2234 
2235  throw new ilDatabaseException('could not write to the output file');
2236  }
2237  }
2238  @fclose($fp);
2239 
2240  return MDB2_OK;
2241  }
const MDB2_OK(!class_exists('PEAR'))
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these...
Definition: MDB2.php:72
$result
Class ilDatabaseException.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:

Field Documentation

◆ $allowed_attributes

ilDBPdoFieldDefinition::$allowed_attributes
Initial value:
"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:
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:
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:
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 927 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_oracle

ilDBPdoFieldDefinition::$reserved_oracle
protected

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

Referenced by getReservedOracle(), and setReservedOracle().

◆ $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:
'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 957 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: