ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
ilDBPdoMySQLFieldDefinition Class Reference

Class ilDBPdoMySQLFieldDefinition. More...

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

Public Member Functions

 getTypeDeclaration ($field)
 
- Public Member Functions inherited from ilDBPdoFieldDefinition
 __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)
 

Protected Member Functions

 getIntegerDeclaration ($name, $field)
 
 mapNativeDatatypeInternal ($field)
 
- Protected Member Functions inherited from ilDBPdoFieldDefinition
 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)
 

Additional Inherited Members

- Data Fields inherited from ilDBPdoFieldDefinition
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 Attributes inherited from ilDBPdoFieldDefinition
 $db_instance
 
 $max_length
 
 $available_types
 
 $reserved_mysql
 
 $reserved_postgres
 
 $reserved_oracle
 
 $query_utils
 
 $valid_default_values
 
- Static Protected Attributes inherited from ilDBPdoFieldDefinition
static $instance
 

Detailed Description

Member Function Documentation

◆ getIntegerDeclaration()

ilDBPdoMySQLFieldDefinition::getIntegerDeclaration (   $name,
  $field 
)
protected
Parameters
$name
$field
Returns
|string
Exceptions

Definition at line 97 of file class.ilDBPdoMySQLFieldDefinition.php.

References ilDBPdoFieldDefinition\getDBInstance(), getTypeDeclaration(), and ilDBPdoFieldDefinition\quote().

97  {
98  $db = $this->getDBInstance();
99 
100  $default = $autoinc = '';
101  if (!empty($field['autoincrement'])) {
102  $autoinc = ' AUTO_INCREMENT PRIMARY KEY';
103  } elseif (array_key_exists('default', $field)) {
104  if ($field['default'] === '') {
105  $field['default'] = empty($field['notnull']) ? null : 0;
106  }
107  $default = ' DEFAULT ' . $this->quote($field['default'], 'integer');
108  } elseif (empty($field['notnull'])) {
109  $default = ' DEFAULT NULL';
110  }
111 
112  $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
113  $unsigned = empty($field['unsigned']) ? '' : ' UNSIGNED';
114  $name = $db->quoteIdentifier($name, true);
115 
116  return $name . ' ' . $this->getTypeDeclaration($field) . $unsigned . $default . $notnull . $autoinc;
117  }
quote($value, $type=null, $quote=true, $escape_wildcards=false)
+ Here is the call graph for this function:

◆ getTypeDeclaration()

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

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

References ilDBPdoFieldDefinition\getDBInstance().

Referenced by getIntegerDeclaration().

15  {
16  $db = $this->getDBInstance();
17 
18  switch ($field['type']) {
19  case 'text':
20  if (empty($field['length']) && array_key_exists('default', $field)) {
21  $field['length'] = $db->varchar_max_length;
22  }
23  $length = !empty($field['length']) ? $field['length'] : false;
24  $fixed = !empty($field['fixed']) ? $field['fixed'] : false;
25 
26  return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)') : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
27  case 'clob':
28  if (!empty($field['length'])) {
29  $length = $field['length'];
30  if ($length <= 255) {
31  return 'TINYTEXT';
32  } elseif ($length <= 65532) {
33  return 'TEXT';
34  } elseif ($length <= 16777215) {
35  return 'MEDIUMTEXT';
36  }
37  }
38 
39  return 'LONGTEXT';
40  case 'blob':
41  if (!empty($field['length'])) {
42  $length = $field['length'];
43  if ($length <= 255) {
44  return 'TINYBLOB';
45  } elseif ($length <= 65532) {
46  return 'BLOB';
47  } elseif ($length <= 16777215) {
48  return 'MEDIUMBLOB';
49  }
50  }
51 
52  return 'LONGBLOB';
53  case 'integer':
54  if (!empty($field['length'])) {
55  $length = $field['length'];
56  if ($length <= 1) {
57  return 'TINYINT';
58  } elseif ($length == 2) {
59  return 'SMALLINT';
60  } elseif ($length == 3) {
61  return 'MEDIUMINT';
62  } elseif ($length == 4) {
63  return 'INT';
64  } elseif ($length > 4) {
65  return 'BIGINT';
66  }
67  }
68 
69  return 'INT';
70  case 'boolean':
71  return 'TINYINT(1)';
72  case 'date':
73  return 'DATE';
74  case 'time':
75  return 'TIME';
76  case 'timestamp':
77  return 'DATETIME';
78  case 'float':
79  return 'DOUBLE';
80  case 'decimal':
81  $length = !empty($field['length']) ? $field['length'] : 18;
82  $scale = !empty($field['scale']) ? $field['scale'] : $db->options['decimal_places'];
83 
84  return 'DECIMAL(' . $length . ',' . $scale . ')';
85  }
86 
87  return '';
88  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapNativeDatatypeInternal()

ilDBPdoMySQLFieldDefinition::mapNativeDatatypeInternal (   $field)
protected
Parameters
$field
Returns
array
Exceptions

Definition at line 125 of file class.ilDBPdoMySQLFieldDefinition.php.

References array.

125  {
126  $db_type = strtolower($field['type']);
127  $db_type = strtok($db_type, '(), ');
128  if ($db_type == 'national') {
129  $db_type = strtok('(), ');
130  }
131  if (!empty($field['length'])) {
132  $length = strtok($field['length'], ', ');
133  $decimal = strtok(', ');
134  } else {
135  $length = strtok('(), ');
136  $decimal = strtok('(), ');
137  }
138  $type = array();
139  $unsigned = $fixed = null;
140  switch ($db_type) {
141  case 'tinyint':
142  $type[] = 'integer';
143  $type[] = 'boolean';
144  if (preg_match('/^(is|has)/', $field['name'])) {
145  $type = array_reverse($type);
146  }
147  $unsigned = preg_match('/ unsigned/i', $field['type']);
148  $length = 1;
149  break;
150  case 'smallint':
151  $type[] = 'integer';
152  $unsigned = preg_match('/ unsigned/i', $field['type']);
153  $length = 2;
154  break;
155  case 'mediumint':
156  $type[] = 'integer';
157  $unsigned = preg_match('/ unsigned/i', $field['type']);
158  $length = 3;
159  break;
160  case 'int':
161  case 'integer':
162  $type[] = 'integer';
163  $unsigned = preg_match('/ unsigned/i', $field['type']);
164  $length = 4;
165  break;
166  case 'bigint':
167  $type[] = 'integer';
168  $unsigned = preg_match('/ unsigned/i', $field['type']);
169  $length = 8;
170  break;
171  case 'tinytext':
172  case 'mediumtext':
173  case 'longtext':
174  case 'text':
175  case 'text':
176  case 'varchar':
177  $fixed = false;
178  case 'string':
179  case 'char':
180  $type[] = 'text';
181  if ($length == '1') {
182  $type[] = 'boolean';
183  if (preg_match('/^(is|has)/', $field['name'])) {
184  $type = array_reverse($type);
185  }
186  } elseif (strstr($db_type, 'text')) {
187  $type[] = 'clob';
188  if ($decimal == 'binary') {
189  $type[] = 'blob';
190  }
191  }
192  if ($fixed !== false) {
193  $fixed = true;
194  }
195  break;
196  case 'enum':
197  $type[] = 'text';
198  preg_match_all('/\'.+\'/U', $field['type'], $matches);
199  $length = 0;
200  $fixed = false;
201  if (is_array($matches)) {
202  foreach ($matches[0] as $value) {
203  $length = max($length, strlen($value) - 2);
204  }
205  if ($length == '1' && count($matches[0]) == 2) {
206  $type[] = 'boolean';
207  if (preg_match('/^(is|has)/', $field['name'])) {
208  $type = array_reverse($type);
209  }
210  }
211  }
212  $type[] = 'integer';
213  case 'set':
214  $fixed = false;
215  $type[] = 'text';
216  $type[] = 'integer';
217  break;
218  case 'date':
219  $type[] = 'date';
220  $length = null;
221  break;
222  case 'datetime':
223  case 'timestamp':
224  $type[] = 'timestamp';
225  $length = null;
226  break;
227  case 'time':
228  $type[] = 'time';
229  $length = null;
230  break;
231  case 'float':
232  case 'double':
233  case 'real':
234  $type[] = 'float';
235  $unsigned = preg_match('/ unsigned/i', $field['type']);
236  break;
237  case 'unknown':
238  case 'decimal':
239  case 'numeric':
240  $type[] = 'decimal';
241  $unsigned = preg_match('/ unsigned/i', $field['type']);
242  if ($decimal !== false) {
243  $length = $length . ',' . $decimal;
244  }
245  break;
246  case 'tinyblob':
247  case 'mediumblob':
248  case 'longblob':
249  case 'blob':
250  $type[] = 'blob';
251  $length = null;
252  break;
253  case 'binary':
254  case 'varbinary':
255  $type[] = 'blob';
256  break;
257  case 'year':
258  $type[] = 'integer';
259  $type[] = 'date';
260  $length = null;
261  break;
262  default:
263  throw new ilDatabaseException('unknown database attribute type: ' . $db_type);
264  }
265 
266  if ((int)$length <= 0) {
267  $length = null;
268  }
269 
270  return array( $type, $length, $unsigned, $fixed );
271  }
Class ilDatabaseException.
Create styles array
The data for the language used.

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