23 $this->manager = $ilDB->db->loadModule(
'Manager');
24 $this->reverse = $ilDB->db->loadModule(
'Reverse');
26 $this->allowed_attributes = $ilDB->getAllowedAttributes();
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]);
109 foreach ($a_def as $k => $rd)
111 if ($car[$rd[
"type"]] > $cur_car)
113 $cur_car = $car[$rd[
"type"]];
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"])
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"]);
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"]);
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"]);
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;