This class gives all kind of DB information using the MDB2 manager and reverse module.
More...
This class gives all kind of DB information using the MDB2 manager and reverse module.
- Author
- Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
- Version
- Id
- class.ilDBUpdate.php 18649 2009-01-21 09:59:23Z akill
Definition at line 13 of file class.ilDBAnalyzer.php.
◆ __construct()
ilDBAnalyzer::__construct |
( |
| ) |
|
Constructor.
Definition at line 19 of file class.ilDBAnalyzer.php.
References $ilDB.
23 $this->manager = $ilDB->db->loadModule(
'Manager');
24 $this->reverse = $ilDB->db->loadModule(
'Reverse');
26 $this->allowed_attributes = $ilDB->getAllowedAttributes();
◆ getAutoIncrementField()
ilDBAnalyzer::getAutoIncrementField |
( |
|
$a_table | ) |
|
Gets the auto increment field of a table.
This should be used on ILIAS 3.10.x "MySQL" tables only.
- Parameters
-
- Returns
- string name of autoincrement field
Definition at line 128 of file class.ilDBAnalyzer.php.
130 $fields = $this->manager->listTableFields($a_table);
133 foreach ($fields as $field)
135 $rdef = $this->reverse->getTableFieldDefinition($a_table, $field);
136 if ($rdef[0][
"autoincrement"])
◆ getBestDefinitionAlternative()
ilDBAnalyzer::getBestDefinitionAlternative |
( |
|
$a_def | ) |
|
◆ getConstraintsInformation()
ilDBAnalyzer::getConstraintsInformation |
( |
|
$a_table, |
|
|
|
$a_abstract_table = false |
|
) |
| |
Get information on constraints of a table.
Primary key is NOT included! Fulltext indices are included and marked.
- Parameters
-
- Returns
- array indices information array
Definition at line 245 of file class.ilDBAnalyzer.php.
247 $constraints = $this->manager->listTableConstraints($a_table);
250 foreach ($constraints as $c)
252 $info = $this->reverse->getTableConstraintDefinition($a_table, $c);
258 $i[
"type"] =
"unique";
259 foreach ($info[
"fields"] as $k => $f)
261 $i[
"fields"][$k] = array(
262 "position" => $f[
"position"],
263 "sorting" => $f[
"sorting"]);
◆ getFieldInformation()
ilDBAnalyzer::getFieldInformation |
( |
|
$a_table, |
|
|
|
$a_remove_not_allowed_attributes = false |
|
) |
| |
Get field information of a table.
- Parameters
-
- Returns
- array field information array
Definition at line 36 of file class.ilDBAnalyzer.php.
References getBestDefinitionAlternative().
Referenced by ilSetting\_getValueType().
39 $fields = $this->manager->listTableFields($a_table);
41 foreach ($fields as $field)
44 $rdef = $this->reverse->getTableFieldDefinition($a_table, $field);
47 if ($rdef[
"type"] != $rdef[
"mdb2type"])
49 echo
"ilDBAnalyzer::getFielInformation: Found type != mdb2type: $a_table, $field";
57 foreach ($rdef as $k => $rd)
61 $alt_types.= $rdef[$k][
"type"].$rdef[$k][
"length"].
" ";
66 "notnull" => $rdef[$best_alt][
"notnull"],
67 "nativetype" => $rdef[$best_alt][
"nativetype"],
68 "length" => $rdef[$best_alt][
"length"],
69 "unsigned" => $rdef[$best_alt][
"unsigned"],
70 "default" => $rdef[$best_alt][
"default"],
71 "fixed" => $rdef[$best_alt][
"fixed"],
72 "autoincrement" => $rdef[$best_alt][
"autoincrement"],
73 "type" => $rdef[$best_alt][
"type"],
74 "alt_types" => $alt_types,
77 if ($a_remove_not_allowed_attributes)
79 foreach ($inf[$field] as $k => $v)
81 if ($k !=
"type" && !in_array($k, $this->allowed_attributes[$inf[$field][
"type"]]))
83 unset($inf[$field][$k]);
getBestDefinitionAlternative($a_def)
◆ getIndicesInformation()
ilDBAnalyzer::getIndicesInformation |
( |
|
$a_table, |
|
|
|
$a_abstract_table = false |
|
) |
| |
Get information on indices of a table.
Primary key is NOT included! Fulltext indices are included and marked.
- Parameters
-
- Returns
- array indices information array
Definition at line 180 of file class.ilDBAnalyzer.php.
183 $indexes = $this->manager->listTableIndexes($a_table);
186 $mysql_info = array();
187 if ($this->il_db->getDBType() ==
"mysql")
189 $set = $this->il_db->query(
"SHOW INDEX FROM ".$a_table);
190 while ($rec = $this->il_db->fetchAssoc($set))
192 if (!empty ($rec[
"Key_name"]))
194 $mysql_info[$rec[
"Key_name"]] = $rec;
198 $mysql_info[$rec[
"key_name"]] = $rec;
204 foreach ($indexes as $c)
206 $info = $this->reverse->getTableIndexDefinition($a_table, $c);
209 if (!$info[
"primary"])
212 $i[
"fulltext"] =
false;
213 $suffix = ($a_abstract_table)
217 if ($mysql_info[$i[
"name"]][
"Index_type"] ==
"FULLTEXT" ||
218 $mysql_info[$i[
"name"].
"_idx"][
"Index_type"] ==
"FULLTEXT" ||
219 $mysql_info[$i[
"name"]][
"index_type"] ==
"FULLTEXT" ||
220 $mysql_info[$i[
"name"].
"_idx"][
"index_type"] ==
"FULLTEXT")
222 $i[
"fulltext"] =
true;
224 foreach ($info[
"fields"] as $k => $f)
226 $i[
"fields"][$k] = array(
227 "position" => $f[
"position"],
228 "sorting" => $f[
"sorting"]);
◆ getPrimaryKeyInformation()
ilDBAnalyzer::getPrimaryKeyInformation |
( |
|
$a_table | ) |
|
Get primary key of a table.
- Parameters
-
- Returns
- array primary key information array
Definition at line 150 of file class.ilDBAnalyzer.php.
Referenced by hasSequence().
152 $constraints = $this->manager->listTableConstraints($a_table);
154 foreach ($constraints as $c)
156 $info = $this->reverse->getTableConstraintDefinition($a_table, $c);
157 if ($info[
"primary"])
160 foreach ($info[
"fields"] as $k => $f)
162 $pk[
"fields"][$k] = array(
163 "position" => $f[
"position"],
164 "sorting" => $f[
"sorting"]);
◆ hasSequence()
ilDBAnalyzer::hasSequence |
( |
|
$a_table | ) |
|
Check whether sequence is defined for current table (only works on "abstraced" tables)
- Parameters
-
- Returns
- mixed false, if no sequence is defined, start number otherwise
Definition at line 278 of file class.ilDBAnalyzer.php.
References getPrimaryKeyInformation().
280 $seq = $this->manager->listSequences();
281 if (is_array($seq) && in_array($a_table, $seq))
285 if (is_array($pk[
"fields"]) && count($pk[
"fields"] == 1))
287 $seq_field = key($pk[
"fields"]);
291 die(
"ilDBAnalyzer::hasSequence: Error, sequence defined, but no one-field primary key given. Table: ".$a_table.
".");
294 $set = $this->il_db->query(
"SELECT MAX(`".$seq_field.
"`) ma FROM `".$a_table.
"`");
295 $rec = $this->il_db->fetchAssoc($set);
296 $next = $rec[
"ma"] + 1;
getPrimaryKeyInformation($a_table)
Get primary key of a table.
The documentation for this class was generated from the following file: