49            $ilDBInterface = 
$ilDB;
 
   54        $this->il_db = $ilDBInterface;
 
   55        $this->allowed_attributes = $ilDBInterface->getAllowedAttributes();
 
   67        $fields = $this->manager->listTableFields($a_table);
 
   69        foreach ($fields as $field) {
 
   70            $rdef = $this->reverse->getTableFieldDefinition($a_table, $field);
 
   72            if ($rdef[
"type"] != $rdef[
"mdb2type"]) {
 
   73                throw new ilDatabaseException(
"ilDBAnalyzer::getFielInformation: Found type != mdb2type: $a_table, $field");
 
   81            foreach ($rdef as $k => $rd) {
 
   82                if ($k != $best_alt) {
 
   83                    $alt_types .= $rdef[$k][
"type"] . $rdef[$k][
"length"] . 
" ";
 
   88                "notnull" => $rdef[$best_alt][
"notnull"],
 
   89                "nativetype" => $rdef[$best_alt][
"nativetype"],
 
   90                "length" => $rdef[$best_alt][
"length"],
 
   91                "unsigned" => $rdef[$best_alt][
"unsigned"],
 
   92                "default" => $rdef[$best_alt][
"default"],
 
   93                "fixed" => $rdef[$best_alt][
"fixed"],
 
   94                "autoincrement" => $rdef[$best_alt][
"autoincrement"],
 
   95                "type" => $rdef[$best_alt][
"type"],
 
   96                "alt_types" => $alt_types,
 
   99            if ($a_remove_not_allowed_attributes) {
 
  100                foreach ($inf[$field] as $k => $v) {
 
  101                    if ($k != 
"type" && !in_array($k, $this->allowed_attributes[$inf[$field][
"type"]])) {
 
  102                        unset($inf[$field][$k]);
 
  134        foreach ($a_def as $k => $rd) {
 
  135            if ($car[$rd[
"type"]] > $cur_car) {
 
  136                $cur_car = $car[$rd[
"type"]];
 
  154        $fields = $this->manager->listTableFields($a_table);
 
  157        foreach ($fields as $field) {
 
  158            $rdef = $this->reverse->getTableFieldDefinition($a_table, $field);
 
  159            if ($rdef[0][
"autoincrement"]) {
 
  176        $constraints = $this->manager->listTableConstraints($a_table);
 
  179        foreach ($constraints as 
$c) {
 
  180            $info = $this->reverse->getTableConstraintDefinition($a_table, 
$c);
 
  182            if (
$info[
"primary"]) {
 
  184                foreach (
$info[
"fields"] as $k => 
$f) {
 
  185                    $pk[
"fields"][$k] = array(
 
  186                        "position" => 
$f[
"position"],
 
  187                        "sorting" => 
$f[
"sorting"],
 
  208        $indexes = $this->manager->listTableIndexes($a_table);
 
  211        $mysql_info = array();
 
  213        $set = $this->il_db->query(
"SHOW INDEX FROM " . $a_table);
 
  214        while ($rec = $this->il_db->fetchAssoc($set)) {
 
  215            if (!empty($rec[
"Key_name"])) {
 
  216                $mysql_info[$rec[
"Key_name"]] = $rec;
 
  218                $mysql_info[$rec[
"key_name"]] = $rec;
 
  224        foreach ($indexes as 
$c) {
 
  225            $info = $this->reverse->getTableIndexDefinition($a_table, 
$c);
 
  228            if (!
$info[
"primary"]) {
 
  230                $i[
"fulltext"] = 
false;
 
  231                $suffix = ($a_abstract_table) ? 
"_idx" : 
"";
 
  233                if ($mysql_info[
$i[
"name"]][
"Index_type"] == 
"FULLTEXT" 
  234                    || $mysql_info[
$i[
"name"] . 
"_idx"][
"Index_type"] == 
"FULLTEXT" 
  235                    || $mysql_info[
$i[
"name"]][
"index_type"] == 
"FULLTEXT" 
  236                    || $mysql_info[
$i[
"name"] . 
"_idx"][
"index_type"] == 
"FULLTEXT" 
  238                    $i[
"fulltext"] = 
true;
 
  240                foreach (
$info[
"fields"] as $k => 
$f) {
 
  241                    $i[
"fields"][$k] = array(
 
  242                        "position" => 
$f[
"position"],
 
  243                        "sorting" => 
$f[
"sorting"],
 
  264        $constraints = $this->manager->listTableConstraints($a_table);
 
  267        foreach ($constraints as 
$c) {
 
  268            $info = $this->reverse->getTableConstraintDefinition($a_table, 
$c);
 
  271            if (
$info[
"unique"]) {
 
  273                $i[
"type"] = 
"unique";
 
  274                foreach (
$info[
"fields"] as $k => 
$f) {
 
  275                    $i[
"fields"][$k] = array(
 
  276                        "position" => 
$f[
"position"],
 
  277                        "sorting" => 
$f[
"sorting"],
 
  299        $seq = $this->manager->listSequences();
 
  300        if (is_array($seq) && in_array($a_table, $seq)) {
 
  303            if (is_array($pk[
"fields"]) && count($pk[
"fields"] == 1)) {
 
  304                $seq_field = key($pk[
"fields"]);
 
  306                throw new ilDatabaseException(
"ilDBAnalyzer::hasSequence: Error, sequence defined, but no one-field primary key given. Table: " 
  310            $set = $this->il_db->query(
"SELECT MAX(" . $this->il_db->quoteIdentifier($seq_field) . 
") ma FROM " . $this->il_db->quoteIdentifier($a_table) . 
"");
 
  311            $rec = $this->il_db->fetchAssoc($set);
 
  312            $next = $rec[
"ma"] + 1;
 
An exception for terminatinating execution or to throw for unit testing.
This class gives all kind of DB information using the database manager and reverse module.
getFieldInformation($a_table, $a_remove_not_allowed_attributes=false)
Get field information of a table.
getPrimaryKeyInformation($a_table)
Get primary key of a table.
getBestDefinitionAlternative($a_def)
getConstraintsInformation($a_table, $a_abstract_table=false)
Get information on constraints of a table.
hasSequence($a_table)
Check whether sequence is defined for current table (only works on "abstraced" tables)
__construct(ilDBInterface $ilDBInterface=null)
ilDBAnalyzer constructor.
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.