ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 533 of file class.ilDBPdoFieldDefinition.php.

533  {
534  $this->db_instance = $ilDBInterface;
535  }

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

References array.

Referenced by convertResult().

883  {
884  switch ($type) {
885  case 'text':
886  if ($rtrim) {
887  $value = rtrim($value);
888  }
889 
890  return $value;
891  case 'integer':
892  return intval($value);
893  case 'boolean':
894  return !empty($value);
895  case 'decimal':
896  return $value;
897  case 'float':
898  return doubleval($value);
899  case 'date':
900  return $value;
901  case 'time':
902  return $value;
903  case 'timestamp':
904  return $value;
905  case 'clob':
906  case 'blob':
907  $this->lobs[] = array(
908  'buffer' => null,
909  'position' => 0,
910  'lob_index' => null,
911  'endOfLOB' => false,
912  'resource' => $value,
913  'value' => null,
914  'loaded' => false,
915  );
916  end($this->lobs);
917  $lob_index = key($this->lobs);
918  $this->lobs[$lob_index]['lob_index'] = $lob_index;
919 
920  return fopen('MDB2LOB://' . $lob_index . '@' . $this->db_index, 'r+');
921  }
922 
923  throw new ilDatabaseException('attempt to convert result value to an unknown type :' . $type);
924  }
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 712 of file class.ilDBPdoFieldDefinition.php.

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

712  {
713  // check valid type
714  if (!in_array($a_def["type"], $this->getAvailableTypes())) {
715  switch ($a_def["type"]) {
716  case "boolean":
717  throw new ilDatabaseException("Invalid column type '" . $a_def["type"] . "'. Use integer(1) instead.");
718  break;
719 
720  case "decimal":
721  throw new ilDatabaseException("Invalid column type '" . $a_def["type"] . "'. Use float or integer instead.");
722  break;
723 
724  default:
725  throw new ilDatabaseException("Invalid column type '" . $a_def["type"] . "'. Allowed types are: "
726  . implode(', ', $this->getAvailableTypes()));
727  }
728  }
729 
730  // check used attributes
732  foreach ($a_def as $k => $v) {
733  if ($k != "type" && !in_array($k, $allowed_attributes[$a_def["type"]])) {
734  throw new ilDatabaseException("Attribute '" . $k . "' is not allowed for column type '" . $a_def["type"] . "'.");
735  }
736  }
737 
738  // type specific checks
739  $max_length = $this->getMaxLength();
740  switch ($a_def["type"]) {
741  case self::T_TEXT:
742  if ($a_def["length"] < 1 || $a_def["length"] > $max_length[self::T_TEXT]) {
743  if (isset($a_def["length"])) {
744  throw new ilDatabaseException("Invalid length '" . $a_def["length"] . "' for type text." . " Length must be >=1 and <= "
745  . $max_length[self::T_TEXT] . ".");
746  }
747  }
748  break;
749 
750  case self::T_INTEGER:
751  if (!in_array($a_def["length"], $max_length[self::T_INTEGER])) {
752  if (isset($a_def["length"])) {
753  throw new ilDatabaseException("Invalid length '" . $a_def["length"] . "' for type integer." . " Length must be "
754  . implode(', ', $max_length[self::T_INTEGER]) . " (bytes).");
755  }
756  }
757  if ($a_def["unsigned"]) {
758  throw new ilDatabaseException("Unsigned attribut must not be true for type integer.");
759  }
760  break;
761  }
762 
763  return true;
764  }
Class ilDatabaseException.
+ Here is the call graph for this function:

◆ checkColumnName()

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

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

References isReserved().

663  {
664  if (!preg_match("/^[a-z]+[_a-z0-9]*$/", $column_name)) {
665  throw new ilDatabaseException("Invalid column name '" . $column_name
666  . "'. Column name must only contain _a-z0-9 and must start with a-z.");
667  }
668 
669  if ($this->isReserved($column_name)) {
670  throw new ilDatabaseException("Invalid column name '" . $column_name . "' (Reserved Word).");
671  }
672 
673  if (strtolower(substr($column_name, 0, 4)) == "sys_") {
674  throw new ilDatabaseException("Invalid column name '" . $column_name . "'. Name must not start with 'sys_'.");
675  }
676 
677  if (strlen($column_name) > 30) {
678  throw new ilDatabaseException("Invalid column name '" . $column_name . "'. Maximum column identifer length is 30 bytes.");
679  }
680 
681  return true;
682  }
Class ilDatabaseException.
+ Here is the call graph for this function:

◆ checkIndexName()

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

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

References isReserved().

690  {
691  if (!preg_match("/^[a-z]+[_a-z0-9]*$/", $a_name)) {
692  throw new ilDatabaseException("Invalid column name '" . $a_name . "'. Column name must only contain _a-z0-9 and must start with a-z.");
693  }
694 
695  if ($this->isReserved($a_name)) {
696  throw new ilDatabaseException("Invalid column name '" . $a_name . "' (Reserved Word).");
697  }
698 
699  if (strlen($a_name) > 3) {
700  throw new ilDatabaseException("Invalid index name '" . $a_name . "'. Maximum index identifer length is 3 bytes.");
701  }
702 
703  return true;
704  }
Class ilDatabaseException.
+ Here is the call graph for this function:

◆ checkResultTypes()

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

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

References array, and getDBInstance().

861  {
862  $types = is_array($types) ? $types : array( $types );
863  foreach ($types as $key => $type) {
864  if (!isset($this->valid_default_values[$type])) {
865  $db = $this->getDBInstance();
866  if (empty($db->options['datatype_map'][$type])) {
867  throw new ilDatabaseException($type . ' for ' . $key . ' is not a supported column type');
868  }
869  }
870  }
871 
872  return $types;
873  }
Class ilDatabaseException.
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ checkTableName()

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

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

References isReserved().

572  {
573  if (!preg_match(self::DEFINITION_TABLE_NAME, $table_name)) {
574  throw new ilDatabaseException('Table name must only contain _a-z0-9 and must start with a-z.');
575  }
576 
577  if ($this->isReserved($table_name)) {
578  throw new ilDatabaseException("Invalid table name '" . $table_name . "' (Reserved Word).");
579  }
580 
581  if (strtolower(substr($table_name, 0, 4)) == "sys_") {
582  throw new ilDatabaseException("Invalid table name '" . $table_name . "'. Name must not start with 'sys_'.");
583  }
584 
585  if (strlen($table_name) > 22) {
586  throw new ilDatabaseException("Invalid table name '" . $table_name . "'. Maximum table identifer length is 22 bytes.");
587  }
588 
589  return true;
590  }
Class ilDatabaseException.
+ Here is the call graph for this function:

◆ compareBLOBDefinition()

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

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

References compareTextDefinition().

1382  {
1383  return $this->compareTextDefinition($current, $previous);
1384  }
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 1422 of file class.ilDBPdoFieldDefinition.php.

References array.

1422  {
1423  return array();
1424  }
Create styles array
The data for the language used.

◆ compareCLOBDefinition()

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

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

References compareTextDefinition().

1372  {
1373  return $this->compareTextDefinition($current, $previous);
1374  }
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 1392 of file class.ilDBPdoFieldDefinition.php.

References array.

1392  {
1393  return array();
1394  }
Create styles array
The data for the language used.

◆ compareDecimalDefinition()

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

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

References array.

1442  {
1443  return array();
1444  }
Create styles array
The data for the language used.

◆ compareDefinition()

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

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

References array, and getDBInstance().

1281  {
1282  $type = !empty($current['type']) ? $current['type'] : null;
1283 
1284  if (!method_exists($this, "compare{$type}Definition")) {
1285  $db = $this->getDBInstance();
1286 
1287  if (!empty($db->options['datatype_map_callback'][$type])) {
1288  $parameter = array( 'current' => $current, 'previous' => $previous );
1289  $change = call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1290 
1291  return $change;
1292  }
1293 
1294  throw new ilDatabaseException('type "' . $current['type'] . '" is not yet supported');
1295  }
1296 
1297  if (empty($previous['type']) || $previous['type'] != $type) {
1298  return $current;
1299  }
1300 
1301  $change = $this->{"compare{$type}Definition"}($current, $previous);
1302 
1303  if ($previous['type'] != $type) {
1304  $change['type'] = true;
1305  }
1306 
1307  $previous_notnull = !empty($previous['notnull']) ? $previous['notnull'] : false;
1308  $notnull = !empty($current['notnull']) ? $current['notnull'] : false;
1309  if ($previous_notnull != $notnull) {
1310  $change['notnull'] = true;
1311  }
1312 
1313  $previous_default = array_key_exists('default', $previous) ? $previous['default'] : ($previous_notnull ? '' : null);
1314  $default = array_key_exists('default', $current) ? $current['default'] : ($notnull ? '' : null);
1315  if ($previous_default !== $default) {
1316  $change['default'] = true;
1317  }
1318 
1319  return $change;
1320  }
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 1432 of file class.ilDBPdoFieldDefinition.php.

References array.

1432  {
1433  return array();
1434  }
Create styles array
The data for the language used.

◆ compareIntegerDefinition()

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

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

References array.

1328  {
1329  $change = array();
1330  $previous_unsigned = !empty($previous['unsigned']) ? $previous['unsigned'] : false;
1331  $unsigned = !empty($current['unsigned']) ? $current['unsigned'] : false;
1332  if ($previous_unsigned != $unsigned) {
1333  $change['unsigned'] = true;
1334  }
1335  $previous_autoincrement = !empty($previous['autoincrement']) ? $previous['autoincrement'] : false;
1336  $autoincrement = !empty($current['autoincrement']) ? $current['autoincrement'] : false;
1337  if ($previous_autoincrement != $autoincrement) {
1338  $change['autoincrement'] = true;
1339  }
1340 
1341  return $change;
1342  }
Create styles array
The data for the language used.

◆ compareTextDefinition()

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

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

References array.

Referenced by compareBLOBDefinition(), and compareCLOBDefinition().

1350  {
1351  $change = array();
1352  $previous_length = !empty($previous['length']) ? $previous['length'] : 0;
1353  $length = !empty($current['length']) ? $current['length'] : 0;
1354  if ($previous_length != $length) {
1355  $change['length'] = true;
1356  }
1357  $previous_fixed = !empty($previous['fixed']) ? $previous['fixed'] : 0;
1358  $fixed = !empty($current['fixed']) ? $current['fixed'] : 0;
1359  if ($previous_fixed != $fixed) {
1360  $change['fixed'] = true;
1361  }
1362 
1363  return $change;
1364  }
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 1402 of file class.ilDBPdoFieldDefinition.php.

References array.

1402  {
1403  return array();
1404  }
Create styles array
The data for the language used.

◆ compareTimestampDefinition()

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

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

References array.

1412  {
1413  return array();
1414  }
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 934 of file class.ilDBPdoFieldDefinition.php.

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

Referenced by convertResultRow().

934  {
935  if (is_null($value)) {
936  return null;
937  }
938  $db = $this->getDBInstance();
939 
940  if (!empty($db->options['datatype_map'][$type])) {
941  $type = $db->options['datatype_map'][$type];
942  if (!empty($db->options['datatype_map_callback'][$type])) {
943  $parameter = array( 'type' => $type, 'value' => $value, 'rtrim' => $rtrim );
944 
945  return call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
946  }
947  }
948 
949  return $this->baseConvertResult($value, $type, $rtrim);
950  }
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 959 of file class.ilDBPdoFieldDefinition.php.

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

959  {
960  $types = $this->sortResultFieldTypes(array_keys($row), $types);
961  foreach ($row as $key => $value) {
962  if (empty($types[$key])) {
963  continue;
964  }
965  $value = $this->convertResult($row[$key], $types[$key], $rtrim);
966 
967  $row[$key] = $value;
968  }
969 
970  return $row;
971  }
convertResult($value, $type, $rtrim=true)
+ Here is the call graph for this function:

◆ destroyLOB()

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

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

References destroyLOBInternal().

1809  {
1810  $lob_data = stream_get_meta_data($lob);
1811  $lob_index = $lob_data['wrapper_data']->lob_index;
1812  fclose($lob);
1813  if (isset($this->lobs[$lob_index])) {
1814  $this->destroyLOBInternal($this->lobs[$lob_index]);
1815  unset($this->lobs[$lob_index]);
1816  }
1817 
1818  return true;
1819  }
+ Here is the call graph for this function:

◆ destroyLOBInternal()

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

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

Referenced by destroyLOB().

1826  {
1827  return true;
1828  }
+ Here is the caller graph for this function:

◆ endOfLOB()

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

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

1800  {
1801  return $lob['endOfLOB'];
1802  }

◆ getAllowedAttributes()

ilDBPdoFieldDefinition::getAllowedAttributes ( )
Returns
array

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

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

Referenced by isReserved().

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

◆ getAvailableTypes()

ilDBPdoFieldDefinition::getAvailableTypes ( )
Returns
array

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

References getDBInstance(), and getTypeDeclaration().

1205  {
1206  $db = $this->getDBInstance();
1207 
1208  $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
1209  $name = $db->quoteIdentifier($name, true);
1210 
1211  return $name . ' ' . $this->getTypeDeclaration($field) . $notnull;
1212  }
+ Here is the call graph for this function:

◆ getBooleanDeclaration()

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

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

References getInternalDeclaration().

1220  {
1221  return $this->getInternalDeclaration($name, $field);
1222  }
+ Here is the call graph for this function:

◆ getCharsetFieldDeclaration()

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

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

Referenced by getDeclarationOptions().

1143  {
1144  return '';
1145  }
+ Here is the caller graph for this function:

◆ getCLOBDeclaration()

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

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

References getDBInstance(), and getTypeDeclaration().

1190  {
1191  $db = $this->getDBInstance();
1192 
1193  $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
1194  $name = $db->quoteIdentifier($name, true);
1195 
1196  return $name . ' ' . $this->getTypeDeclaration($field) . $notnull;
1197  }
+ Here is the call graph for this function:

◆ getCollationFieldDeclaration()

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

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

Referenced by getDeclarationOptions().

1152  {
1153  return '';
1154  }
+ Here is the caller graph for this function:

◆ getDateDeclaration()

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

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

References getInternalDeclaration().

1230  {
1231  return $this->getInternalDeclaration($name, $field);
1232  }
+ Here is the call graph for this function:

◆ getDBInstance()

◆ getDecimalDeclaration()

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

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

References getInternalDeclaration().

1270  {
1271  return $this->getInternalDeclaration($name, $field);
1272  }
+ Here is the call graph for this function:

◆ getDeclaration()

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

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

References array, and getDBInstance().

1022  {
1023  $db = $this->getDBInstance();
1024 
1025  if (!empty($db->options['datatype_map'][$type])) {
1026  $type = $db->options['datatype_map'][$type];
1027  if (!empty($db->options['datatype_map_callback'][$type])) {
1028  $parameter = array( 'type' => $type, 'name' => $name, 'field' => $field );
1029 
1030  return call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1031  }
1032  $field['type'] = $type;
1033  }
1034 
1035  if (!method_exists($this, "get{$type}Declaration")) {
1036  throw new ilDatabaseException('type not defined: ' . $type);
1037  }
1038 
1039  return $this->{"get{$type}Declaration"}($name, $field);
1040  }
Class ilDatabaseException.
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 1101 of file class.ilDBPdoFieldDefinition.php.

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

1101  {
1102  $charset = empty($field['charset']) ? '' : ' ' . $this->getCharsetFieldDeclaration($field['charset']);
1103 
1104  $default = '';
1105  if (array_key_exists('default', $field)) {
1106  if ($field['default'] === '') {
1107  $db = $this->getDBInstance();
1108 
1109  if (empty($field['notnull'])) {
1110  $field['default'] = null;
1111  } else {
1113  $field['default'] = $valid_default_values[$field['type']];
1114  }
1115  if ($field['default'] === ''
1116  && ($db->options['portability'] & 32)
1117  ) {
1118  $field['default'] = ' ';
1119  }
1120  }
1121  $default = ' DEFAULT ' . $this->quote($field['default'], $field['type']);
1122  } elseif (empty($field['notnull'])) {
1123  $default = ' DEFAULT NULL';
1124  }
1125 
1126  $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
1127  // alex patch 28 Nov 2011 start
1128  if ($field['notnull'] === false) {
1129  $notnull = " NULL";
1130  }
1131  // alex patch 28 Nov 2011 end
1132 
1133  $collation = empty($field['collation']) ? '' : ' ' . $this->getCollationFieldDeclaration($field['collation']);
1134 
1135  return $charset . $default . $notnull . $collation;
1136  }
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 1260 of file class.ilDBPdoFieldDefinition.php.

References getInternalDeclaration().

1260  {
1261  return $this->getInternalDeclaration($name, $field);
1262  }
+ Here is the call graph for this function:

◆ getIntegerDeclaration()

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

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

References getDBInstance(), and getInternalDeclaration().

1163  {
1164  if (!empty($field['unsigned'])) {
1165  $db = $this->getDBInstance();
1166 
1167  $db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer";
1168  }
1169 
1170  return $this->getInternalDeclaration($name, $field);
1171  }
+ Here is the call graph for this function:

◆ getInternalDeclaration()

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

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

References getDBInstance(), and getTypeDeclaration().

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

1086  {
1087  $db = $this->getDBInstance();
1088 
1089  $name = $db->quoteIdentifier($name, true);
1090  $declaration_options = $db->getFieldDefinition()->getDeclarationOptions($field);
1091 
1092  return $name . ' ' . $this->getTypeDeclaration($field) . $declaration_options;
1093  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMaxLength()

ilDBPdoFieldDefinition::getMaxLength ( )
Returns
array

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

References $max_length.

Referenced by checkColumnDefinition().

+ Here is the caller graph for this function:

◆ getQueryUtils()

ilDBPdoFieldDefinition::getQueryUtils ( )
protected
Returns

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

References $query_utils.

541  {
542  if (!$this->query_utils) {
543  $this->query_utils = new ilMySQLQueryUtils($this->db_instance);
544  }
545 
546  return $this->query_utils;
547  }
Class ilMySQLQueryUtils.

◆ getReservedMysql()

ilDBPdoFieldDefinition::getReservedMysql ( )
Returns
array

Definition at line 613 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 645 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 629 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 1180 of file class.ilDBPdoFieldDefinition.php.

References getInternalDeclaration().

1180  {
1181  return $this->getInternalDeclaration($name, $field);
1182  }
+ Here is the call graph for this function:

◆ getTimeDeclaration()

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

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

References getInternalDeclaration().

1250  {
1251  return $this->getInternalDeclaration($name, $field);
1252  }
+ Here is the call graph for this function:

◆ getTimestampDeclaration()

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

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

References getInternalDeclaration().

1240  {
1241  return $this->getInternalDeclaration($name, $field);
1242  }
+ Here is the call graph for this function:

◆ getTypeDeclaration()

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

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

References getDBInstance().

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

1047  {
1048  $db = $this->getDBInstance();
1049 
1050  switch ($field['type']) {
1051  case 'text':
1052  $length = !empty($field['length']) ? $field['length'] : $db->options['default_text_field_length'];
1053  $fixed = !empty($field['fixed']) ? $field['fixed'] : false;
1054 
1055  return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(' . $db->options['default_text_field_length']
1056  . ')') : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
1057  case 'clob':
1058  return 'TEXT';
1059  case 'blob':
1060  return 'TEXT';
1061  case 'integer':
1062  return 'INT';
1063  case 'boolean':
1064  return 'INT';
1065  case 'date':
1066  return 'CHAR (' . strlen('YYYY-MM-DD') . ')';
1067  case 'time':
1068  return 'CHAR (' . strlen('HH:MM:SS') . ')';
1069  case 'timestamp':
1070  return 'CHAR (' . strlen('YYYY-MM-DD HH:MM:SS') . ')';
1071  case 'float':
1072  return 'TEXT';
1073  case 'decimal':
1074  return 'TEXT';
1075  }
1076 
1077  return '';
1078  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getValidTypes()

ilDBPdoFieldDefinition::getValidTypes ( )
Returns
array

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

References $valid_default_values, array, and getDBInstance().

Referenced by getDeclarationOptions().

836  {
838  $db = $this->getDBInstance();
839 
840  if (!empty($db->options['datatype_map'])) {
841  foreach ($db->options['datatype_map'] as $type => $mapped_type) {
842  if (array_key_exists($mapped_type, $types)) {
843  $types[$type] = $types[$mapped_type];
844  } elseif (!empty($db->options['datatype_map_callback'][$type])) {
845  $parameter = array( 'type' => $type, 'mapped_type' => $mapped_type );
846  $default = call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
847  $types[$type] = $default;
848  }
849  }
850  }
851 
852  return $types;
853  }
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 1837 of file class.ilDBPdoFieldDefinition.php.

References quote().

1837  {
1838  if (!is_array($array) || empty($array)) {
1839  return 'NULL';
1840  }
1841  if ($type) {
1842  foreach ($array as $value) {
1843  $return[] = $this->quote($value, $type);
1844  }
1845  } else {
1846  $return = $array;
1847  }
1848 
1849  return implode(', ', $return);
1850  }
quote($value, $type=null, $quote=true, $escape_wildcards=false)
+ Here is the call graph for this function:

◆ isAllowedAttribute()

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

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

772  {
773  return in_array($attribute, $this->allowed_attributes[$type]);
774  }

◆ isReserved()

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

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

References getAllReserved().

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

597  {
598  return in_array(strtoupper($table_name), $this->getAllReserved());
599  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapNativeDatatype()

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

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

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

1914  {
1915  $db = $this->getDBInstance();
1916  $db_type = strtok($field['type'], '(), ');
1917  if (!empty($db->options['nativetype_map_callback'][$db_type])) {
1918  return call_user_func_array($db->options['nativetype_map_callback'][$db_type], array( $db, $field ));
1919  }
1920 
1921  return $this->mapNativeDatatypeInternal($field);
1922  }
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 1937 of file class.ilDBPdoFieldDefinition.php.

References array, and getDBInstance().

1937  {
1938  $db = $this->getDBInstance();
1939 
1940  if (!empty($db->options['datatype_map'][$type])) {
1941  $type = $db->options['datatype_map'][$type];
1942  if (!empty($db->options['datatype_map_callback'][$type])) {
1943  $parameter = array( 'type' => $type );
1944 
1945  return call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1946  }
1947  }
1948 
1949  return $type;
1950  }
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 1860 of file class.ilDBPdoFieldDefinition.php.

References getDBInstance(), and patternEscapeString().

1860  {
1861  $db = $this->getDBInstance();
1862 
1863  $match = '';
1864  if (!is_null($operator)) {
1865  $operator = strtoupper($operator);
1866  switch ($operator) {
1867  // case insensitive
1868  case 'ILIKE':
1869  if (is_null($field)) {
1870  throw new ilDatabaseException('case insensitive LIKE matching requires passing the field name');
1871  }
1872  $db->loadModule('Function', null, true);
1873  $match = $db->function->lower($field) . ' LIKE ';
1874  break;
1875  // case sensitive
1876  case 'LIKE':
1877  $match = is_null($field) ? 'LIKE ' : $field . ' LIKE ';
1878  break;
1879  default:
1880  throw new ilDatabaseException('not a supported operator type:' . $operator);
1881  }
1882  }
1883  $match .= "'";
1884  foreach ($pattern as $key => $value) {
1885  if ($key % 2) {
1886  $match .= $value;
1887  } else {
1888  if ($operator === 'ILIKE') {
1889  $value = strtolower($value);
1890  }
1891  $escaped = $db->escape($value);
1892  $match .= $db->escapePattern($escaped);
1893  }
1894  }
1895  $match .= "'";
1896  $match .= $this->patternEscapeString();
1897 
1898  return $match;
1899  }
Class ilDatabaseException.
+ Here is the call graph for this function:

◆ patternEscapeString()

ilDBPdoFieldDefinition::patternEscapeString ( )
Returns
string

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

Referenced by matchPattern(), and quote().

1905  {
1906  return '';
1907  }
+ 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 1455 of file class.ilDBPdoFieldDefinition.php.

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

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

1455  {
1456  $db = $this->getDBInstance();
1457 
1458  return $db->quote($value, $type);
1459 
1460  if (is_null($value)
1461  || ($value === '' && $db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)
1462  ) {
1463  if (!$quote) {
1464  return null;
1465  }
1466 
1467  return 'NULL';
1468  }
1469 
1470  if (is_null($type)) {
1471  switch (gettype($value)) {
1472  case 'integer':
1473  $type = 'integer';
1474  break;
1475  case 'double':
1476  // todo: default to decimal as float is quite unusual
1477  // $type = 'float';
1478  $type = 'decimal';
1479  break;
1480  case 'boolean':
1481  $type = 'boolean';
1482  break;
1483  case 'array':
1484  $value = serialize($value);
1485  case 'object':
1486  $type = 'text';
1487  break;
1488  default:
1489  if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/', $value)) {
1490  $type = 'timestamp';
1491  } elseif (preg_match('/^\d{2}:\d{2}$/', $value)) {
1492  $type = 'time';
1493  } elseif (preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) {
1494  $type = 'date';
1495  } else {
1496  $type = 'text';
1497  }
1498  break;
1499  }
1500  } elseif (!empty($db->options['datatype_map'][$type])) {
1501  $type = $db->options['datatype_map'][$type];
1502  if (!empty($db->options['datatype_map_callback'][$type])) {
1503  $parameter = array( 'type' => $type, 'value' => $value, 'quote' => $quote, 'escape_wildcards' => $escape_wildcards );
1504 
1505  return call_user_func_array($db->options['datatype_map_callback'][$type], array( &$db, __FUNCTION__, $parameter ));
1506  }
1507  }
1508 
1509  if (!method_exists($this, "quote{$type}")) {
1510  throw new ilDatabaseException('type not defined: ' . $type);
1511  }
1512  $value = $this->{"quote{$type}"}($value, $quote, $escape_wildcards);
1513  if ($quote && $escape_wildcards && $db->string_quoting['escape_pattern']
1514  && $db->string_quoting['escape'] !== $db->string_quoting['escape_pattern']
1515  ) {
1516  $value .= $this->patternEscapeString();
1517  }
1518 
1519  return $value;
1520  }
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 1615 of file class.ilDBPdoFieldDefinition.php.

References quoteLOB().

1615  {
1616  return $this->quoteLOB($value, $quote, $escape_wildcards);
1617  }
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 1626 of file class.ilDBPdoFieldDefinition.php.

1626  {
1627  return ($value ? 1 : 0);
1628  }

◆ quoteCLOB()

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

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

References quoteLOB().

1604  {
1605  return $this->quoteLOB($value, $quote, $escape_wildcards);
1606  }
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 1637 of file class.ilDBPdoFieldDefinition.php.

References getDBInstance(), and quoteText().

1637  {
1638  if ($value === 'CURRENT_DATE') {
1639  $db = $this->getDBInstance();
1640 
1641  return 'CURRENT_DATE';
1642  }
1643 
1644  return $this->quoteText($value, $quote, $escape_wildcards);
1645  }
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 1716 of file class.ilDBPdoFieldDefinition.php.

References string.

Referenced by quoteFloat().

1716  {
1717  $value = (string)$value;
1718  $value = preg_replace('/[^\d\.,\-+eE]/', '', $value);
1719  if (preg_match('/[^.0-9]/', $value)) {
1720  if (strpos($value, ',')) {
1721  // 1000,00
1722  if (!strpos($value, '.')) {
1723  // convert the last "," to a "."
1724  $value = strrev(str_replace(',', '.', strrev($value)));
1725  // 1.000,00
1726  } elseif (strpos($value, '.') && strpos($value, '.') < strpos($value, ',')) {
1727  $value = str_replace('.', '', $value);
1728  // convert the last "," to a "."
1729  $value = strrev(str_replace(',', '.', strrev($value)));
1730  // 1,000.00
1731  } else {
1732  $value = str_replace(',', '', $value);
1733  }
1734  }
1735  }
1736 
1737  return $value;
1738  }
Add rich text string
The name of the decorator.
+ 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 1696 of file class.ilDBPdoFieldDefinition.php.

References quoteDecimal().

1696  {
1697  if (preg_match('/^(.*)e([-+])(\d+)$/i', $value, $matches)) {
1698  $decimal = $this->quoteDecimal($matches[1], $quote, $escape_wildcards);
1699  $sign = $matches[2];
1700  $exponent = str_pad($matches[3], 2, '0', STR_PAD_LEFT);
1701  $value = $decimal . 'E' . $sign . $exponent;
1702  } else {
1703  $value = $this->quoteDecimal($value, $quote, $escape_wildcards);
1704  }
1705 
1706  return $value;
1707  }
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 1529 of file class.ilDBPdoFieldDefinition.php.

1529  {
1530  return (int)$value;
1531  }

◆ quoteLOB()

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

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

References quoteText(), and readFile().

Referenced by quoteBLOB(), and quoteCLOB().

1591  {
1592  $value = $this->readFile($value);
1593 
1594  return $this->quoteText($value, $quote, $escape_wildcards);
1595  }
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 1540 of file class.ilDBPdoFieldDefinition.php.

References getDBInstance().

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

1540  {
1541  if (!$quote) {
1542  return $value;
1543  }
1544 
1545  $db = $this->getDBInstance();
1546 
1547  $value = $db->escape($value, $escape_wildcards);
1548 
1549  return "'" . $value . "'";
1550  }
+ 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 1675 of file class.ilDBPdoFieldDefinition.php.

References getDBInstance(), and quoteText().

1675  {
1676  if ($value === 'CURRENT_TIME') {
1677  $db = $this->getDBInstance();
1678 
1679  if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
1680  return $db->function->now('time');
1681  }
1682 
1683  return 'CURRENT_TIME';
1684  }
1685 
1686  return $this->quoteText($value, $quote, $escape_wildcards);
1687  }
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 1654 of file class.ilDBPdoFieldDefinition.php.

References getDBInstance(), and quoteText().

1654  {
1655  if ($value === 'CURRENT_TIMESTAMP') {
1656  $db = $this->getDBInstance();
1657 
1658  if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
1659  return $db->function->now('timestamp');
1660  }
1661 
1662  return 'CURRENT_TIMESTAMP';
1663  }
1664 
1665  return $this->quoteText($value, $quote, $escape_wildcards);
1666  }
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 1557 of file class.ilDBPdoFieldDefinition.php.

References getDBInstance().

Referenced by quoteLOB().

1557  {
1558  $close = false;
1559  if (preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) {
1560  $close = true;
1561  if ($match[1] == 'file://') {
1562  $value = $match[2];
1563  }
1564  // do not try to open urls
1565  #$value = @fopen($value, 'r');
1566  }
1567 
1568  if (is_resource($value)) {
1569  $db = $this->getDBInstance();
1570 
1571  $fp = $value;
1572  $value = '';
1573  while (!@feof($fp)) {
1574  $value .= @fread($fp, $db->options['lob_buffer_length']);
1575  }
1576  if ($close) {
1577  @fclose($fp);
1578  }
1579  }
1580 
1581  return $value;
1582  }
+ 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 1791 of file class.ilDBPdoFieldDefinition.php.

1791  {
1792  return substr($lob['value'], $lob['position'], $length);
1793  }

◆ retrieveLOB()

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

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

References MDB2_OK.

1776  {
1777  if (is_null($lob['value'])) {
1778  $lob['value'] = $lob['resource'];
1779  }
1780  $lob['loaded'] = true;
1781 
1782  return MDB2_OK;
1783  }
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 804 of file class.ilDBPdoFieldDefinition.php.

References $allowed_attributes.

804  {
805  $this->allowed_attributes = $allowed_attributes;
806  }

◆ setAvailableTypes()

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

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

References $available_types.

788  {
789  $this->available_types = $available_types;
790  }

◆ setMaxLength()

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

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

References $max_length.

820  {
821  $this->max_length = $max_length;
822  }

◆ setReservedMysql()

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

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

References $reserved_mysql.

621  {
622  $this->reserved_mysql = $reserved_mysql;
623  }

◆ setReservedOracle()

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

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

References $reserved_oracle.

653  {
654  $this->reserved_oracle = $reserved_oracle;
655  }

◆ setReservedPostgres()

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

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

References $reserved_postgres.

637  {
638  $this->reserved_postgres = $reserved_postgres;
639  }

◆ sortResultFieldTypes()

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

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

References $columns, and array.

Referenced by convertResultRow().

981  {
982  $n_cols = count($columns);
983  $n_types = count($types);
984  if ($n_cols > $n_types) {
985  for ($i = $n_cols - $n_types; $i >= 0; $i --) {
986  $types[] = null;
987  }
988  }
989  $sorted_types = array();
990  foreach ($columns as $col) {
991  $sorted_types[$col] = null;
992  }
993  foreach ($types as $name => $type) {
994  if (array_key_exists($name, $sorted_types)) {
995  $sorted_types[$name] = $type;
996  unset($types[$name]);
997  }
998  }
999  // if there are left types in the array, fill the null values of the
1000  // sorted array with them, in order.
1001  if (count($types)) {
1002  reset($types);
1003  foreach (array_keys($sorted_types) as $k) {
1004  if (is_null($sorted_types[$k])) {
1005  $sorted_types[$k] = current($types);
1006  next($types);
1007  }
1008  }
1009  }
1010 
1011  return $sorted_types;
1012  }
Create styles array
The data for the language used.
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 1747 of file class.ilDBPdoFieldDefinition.php.

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

1747  {
1748  $db = $this->getDBInstance();
1749 
1750  if (preg_match('/^(\w+:\/\/)(.*)$/', $file, $match)) {
1751  if ($match[1] == 'file://') {
1752  $file = $match[2];
1753  }
1754  }
1755 
1756  $fp = @fopen($file, 'wb');
1757  while (!@feof($lob)) {
1758  $result = @fread($lob, $db->options['lob_buffer_length']);
1759  $read = strlen($result);
1760  if (@fwrite($fp, $result, $read) != $read) {
1761  @fclose($fp);
1762 
1763  throw new ilDatabaseException('could not write to the output file');
1764  }
1765  }
1766  @fclose($fp);
1767 
1768  return MDB2_OK;
1769  }
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 525 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 411 of file class.ilDBPdoFieldDefinition.php.

Referenced by getReservedOracle(), and setReservedOracle().

◆ $reserved_postgres

ilDBPdoFieldDefinition::$reserved_postgres
protected

Definition at line 311 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 553 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: