48 $ilDBInterface =
$ilDB;
53 $this->il_db = $ilDBInterface;
54 $this->allowed_attributes = $ilDBInterface->getAllowedAttributes();
66 $fields = $this->manager->listTableFields($a_table);
68 foreach ($fields as $field) {
69 $rdef = $this->reverse->getTableFieldDefinition($a_table, $field);
71 if ($rdef[
"type"] != $rdef[
"mdb2type"]) {
72 throw new ilDatabaseException(
"ilDBAnalyzer::getFielInformation: Found type != mdb2type: $a_table, $field");
80 foreach ($rdef as $k => $rd) {
81 if ($k != $best_alt) {
82 $alt_types .= $rdef[$k][
"type"] . $rdef[$k][
"length"] .
" ";
87 "notnull" => $rdef[$best_alt][
"notnull"],
88 "nativetype" => $rdef[$best_alt][
"nativetype"],
89 "length" => $rdef[$best_alt][
"length"],
90 "unsigned" => $rdef[$best_alt][
"unsigned"],
91 "default" => $rdef[$best_alt][
"default"],
92 "fixed" => $rdef[$best_alt][
"fixed"],
93 "autoincrement" => $rdef[$best_alt][
"autoincrement"],
94 "type" => $rdef[$best_alt][
"type"],
95 "alt_types" => $alt_types,
98 if ($a_remove_not_allowed_attributes) {
99 foreach ($inf[$field] as $k => $v) {
100 if ($k !=
"type" && !in_array($k, $this->allowed_attributes[$inf[$field][
"type"]])) {
101 unset($inf[$field][$k]);
133 foreach ($a_def as $k => $rd) {
134 if ($car[$rd[
"type"]] > $cur_car) {
135 $cur_car = $car[$rd[
"type"]];
153 $fields = $this->manager->listTableFields($a_table);
156 foreach ($fields as $field) {
157 $rdef = $this->reverse->getTableFieldDefinition($a_table, $field);
158 if ($rdef[0][
"autoincrement"]) {
175 $constraints = $this->manager->listTableConstraints($a_table);
178 foreach ($constraints as $c) {
179 $info = $this->reverse->getTableConstraintDefinition($a_table, $c);
181 if (
$info[
"primary"]) {
183 foreach (
$info[
"fields"] as $k => $f) {
184 $pk[
"fields"][$k] =
array(
185 "position" => $f[
"position"],
186 "sorting" => $f[
"sorting"],
207 $indexes = $this->manager->listTableIndexes($a_table);
210 $mysql_info =
array();
212 $set = $this->il_db->query(
"SHOW INDEX FROM " . $a_table);
213 while ($rec = $this->il_db->fetchAssoc($set)) {
214 if (!empty($rec[
"Key_name"])) {
215 $mysql_info[$rec[
"Key_name"]] = $rec;
217 $mysql_info[$rec[
"key_name"]] = $rec;
223 foreach ($indexes as $c) {
224 $info = $this->reverse->getTableIndexDefinition($a_table, $c);
227 if (!
$info[
"primary"]) {
229 $i[
"fulltext"] =
false;
230 $suffix = ($a_abstract_table) ?
"_idx" :
"";
232 if ($mysql_info[
$i[
"name"]][
"Index_type"] ==
"FULLTEXT" 233 || $mysql_info[
$i[
"name"] .
"_idx"][
"Index_type"] ==
"FULLTEXT" 234 || $mysql_info[
$i[
"name"]][
"index_type"] ==
"FULLTEXT" 235 || $mysql_info[
$i[
"name"] .
"_idx"][
"index_type"] ==
"FULLTEXT" 237 $i[
"fulltext"] =
true;
239 foreach (
$info[
"fields"] as $k => $f) {
241 "position" => $f[
"position"],
242 "sorting" => $f[
"sorting"],
263 $constraints = $this->manager->listTableConstraints($a_table);
266 foreach ($constraints as $c) {
267 $info = $this->reverse->getTableConstraintDefinition($a_table, $c);
270 if (
$info[
"unique"]) {
272 $i[
"type"] =
"unique";
273 foreach (
$info[
"fields"] as $k => $f) {
275 "position" => $f[
"position"],
276 "sorting" => $f[
"sorting"],
298 $seq = $this->manager->listSequences();
299 if (is_array($seq) && in_array($a_table, $seq)) {
302 if (is_array($pk[
"fields"]) && count($pk[
"fields"] == 1)) {
303 $seq_field = key($pk[
"fields"]);
305 throw new ilDatabaseException(
"ilDBAnalyzer::hasSequence: Error, sequence defined, but no one-field primary key given. Table: " 309 $set = $this->il_db->query(
"SELECT MAX(" . $this->il_db->quoteIdentifier($seq_field) .
") ma FROM " . $this->il_db->quoteIdentifier($a_table) .
"");
310 $rec = $this->il_db->fetchAssoc($set);
311 $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.