46 $ilDBInterface =
$ilDB;
51 $this->il_db = $ilDBInterface;
52 $this->allowed_attributes = $ilDBInterface->getAllowedAttributes();
63 $fields = $this->manager->listTableFields($a_table);
65 foreach ($fields as $field) {
66 $rdef = $this->reverse->getTableFieldDefinition($a_table, $field);
68 if ($rdef[
"type"] != $rdef[
"mdb2type"]) {
69 throw new ilDatabaseException(
"ilDBAnalyzer::getFielInformation: Found type != mdb2type: $a_table, $field");
77 foreach ($rdef as $k => $rd) {
78 if ($k != $best_alt) {
79 $alt_types .= $rdef[$k][
"type"] . $rdef[$k][
"length"] .
" ";
84 "notnull" => $rdef[$best_alt][
"notnull"],
85 "nativetype" => $rdef[$best_alt][
"nativetype"],
86 "length" => $rdef[$best_alt][
"length"],
87 "unsigned" => $rdef[$best_alt][
"unsigned"],
88 "default" => $rdef[$best_alt][
"default"],
89 "fixed" => $rdef[$best_alt][
"fixed"],
90 "autoincrement" => $rdef[$best_alt][
"autoincrement"],
91 "type" => $rdef[$best_alt][
"type"],
92 "alt_types" => $alt_types,
95 if ($a_remove_not_allowed_attributes) {
96 foreach ($inf[$field] as $k => $v) {
97 if ($k !=
"type" && !in_array($k, $this->allowed_attributes[$inf[$field][
"type"]])) {
98 unset($inf[$field][$k]);
129 foreach ($a_def as $k => $rd) {
130 if ($car[$rd[
"type"]] > $cur_car) {
131 $cur_car = $car[$rd[
"type"]];
148 $fields = $this->manager->listTableFields($a_table);
151 foreach ($fields as $field) {
152 $rdef = $this->reverse->getTableFieldDefinition($a_table, $field);
153 if ($rdef[0][
"autoincrement"]) {
169 $constraints = $this->manager->listTableConstraints($a_table);
172 foreach ($constraints as $c) {
174 $info = $this->reverse->getTableConstraintDefinition($a_table, $c);
176 if (
$info[
"primary"]) {
178 foreach (
$info[
"fields"] as $k => $f) {
179 $pk[
"fields"][$k] =
array(
180 "position" => $f[
"position"],
181 "sorting" => $f[
"sorting"],
201 $indexes = $this->manager->listTableIndexes($a_table);
204 $mysql_info =
array();
206 $set = $this->il_db->query(
"SHOW INDEX FROM " . $a_table);
207 while ($rec = $this->il_db->fetchAssoc($set)) {
208 if (!empty ($rec[
"Key_name"])) {
209 $mysql_info[$rec[
"Key_name"]] = $rec;
211 $mysql_info[$rec[
"key_name"]] = $rec;
217 foreach ($indexes as $c) {
218 $info = $this->reverse->getTableIndexDefinition($a_table, $c);
221 if (!
$info[
"primary"]) {
223 $i[
"fulltext"] =
false;
224 $suffix = ($a_abstract_table) ?
"_idx" :
"";
226 if ($mysql_info[$i[
"name"]][
"Index_type"] ==
"FULLTEXT" 227 || $mysql_info[$i[
"name"] .
"_idx"][
"Index_type"] ==
"FULLTEXT" 228 || $mysql_info[$i[
"name"]][
"index_type"] ==
"FULLTEXT" 229 || $mysql_info[$i[
"name"] .
"_idx"][
"index_type"] ==
"FULLTEXT" 231 $i[
"fulltext"] =
true;
233 foreach (
$info[
"fields"] as $k => $f) {
234 $i[
"fields"][$k] =
array(
235 "position" => $f[
"position"],
236 "sorting" => $f[
"sorting"],
256 $constraints = $this->manager->listTableConstraints($a_table);
259 foreach ($constraints as $c) {
260 $info = $this->reverse->getTableConstraintDefinition($a_table, $c);
263 if (
$info[
"unique"]) {
265 $i[
"type"] =
"unique";
266 foreach (
$info[
"fields"] as $k => $f) {
267 $i[
"fields"][$k] =
array(
268 "position" => $f[
"position"],
269 "sorting" => $f[
"sorting"],
290 $seq = $this->manager->listSequences();
291 if (is_array($seq) && in_array($a_table, $seq)) {
294 if (is_array($pk[
"fields"]) && count($pk[
"fields"] == 1)) {
295 $seq_field = key($pk[
"fields"]);
297 throw new ilDatabaseException(
"ilDBAnalyzer::hasSequence: Error, sequence defined, but no one-field primary key given. Table: " 301 $set = $this->il_db->query(
"SELECT MAX(" .$this->il_db->quoteIdentifier($seq_field) .
") ma FROM " . $this->il_db->quoteIdentifier($a_table) .
"");
302 $rec = $this->il_db->fetchAssoc($set);
303 $next = $rec[
"ma"] + 1;
getBestDefinitionAlternative($a_def)
hasSequence($a_table)
Check whether sequence is defined for current table (only works on "abstraced" tables) ...
getConstraintsInformation($a_table, $a_abstract_table=false)
Get information on constraints of a table.
getAutoIncrementField($a_table)
Gets the auto increment field of a table.
getIndicesInformation($a_table, $a_abstract_table=false)
Get information on indices of a table.
Class ilDatabaseException.
getPrimaryKeyInformation($a_table)
Get primary key of a table.
Create styles array
The data for the language used.
getFieldInformation($a_table, $a_remove_not_allowed_attributes=false)
Get field information of a table.
__construct(ilDBInterface $ilDBInterface=null)
ilDBAnalyzer constructor.
This class gives all kind of DB information using the MDB2 manager and reverse module.