8include_once (
"MDB2.php");
 
   55                        "text" => array(
"length", 
"notnull", 
"default", 
"fixed"),
 
   56                        "integer" => array(
"length", 
"notnull", 
"default", 
"unsigned"),
 
   57                        "float" => array(
"notnull", 
"default"),
 
   58                        "date" => array(
"notnull", 
"default"),
 
   59                        "time" => array(
"notnull", 
"default"),
 
   60                        "timestamp" => array(
"notnull", 
"default"),
 
   61                        "clob" => array(
"notnull", 
"default"),
 
   62                        "blob" => array(
"notnull", 
"default")
 
   85                $this->db_user = $a_user;
 
  105                $this->db_port = $a_port;
 
  115                return $this->db_port;
 
  125                $this->db_host = $a_host;
 
  145                $this->db_password = $a_password;
 
  155                return $this->db_password;
 
  165                $this->db_name = $a_name;
 
  211                $this->db->setOption(
'result_buffering',$a_status);
 
  220                global $ilClientIniFile;
 
  223                if (is_object($tmpClientIniFile))
 
  224                        $clientIniFile = $tmpClientIniFile;
 
  226                        $clientIniFile = $ilClientIniFile;      
 
  228                if (is_object($clientIniFile ))
 
  241        function connect($a_return_false_for_error = 
false)
 
  248                if ($this->
getDSN() == 
"")
 
  283                        array(
"use_transactions" => 
true));
 
  291                $this->db->disconnect();
 
  334                        array(
"use_transactions" => 
true));
 
  346                        $this->db->setOption(
"portability", $this->db->getOption(
"portability") - $cur);
 
  349                        $this->db->setOption(
"portability", $this->db->getOption(
"portability") - $cur);
 
  396                $this->use_slave = $a_val;
 
  413                                $a_level = $this->error_class->FATAL;
 
  428                                        $stack = $e->getTraceAsString();
 
  434                                        $a_res->getMessage().
"<br />".$a_res->getUserInfo().
"<br />".$stack, $a_level);                                                 
 
  489                        $a_level = $this->error_class->FATAL;
 
  504                        $this->db->loadModule(
'Extended');
 
  529                if ($a_collation != 
"")
 
  531                        $sql = 
"CREATE DATABASE ".$a_name.
 
  532                                " CHARACTER SET ".$a_charset.
 
  533                                " COLLATE ".$a_collation;
 
  537                        $sql = 
"CREATE DATABASE ".$a_name.
 
  538                                " CHARACTER SET ".$a_charset;
 
  541                return $this->
query($sql, 
false);
 
  552        function createTable($a_name, $a_definition_array, $a_drop_table = 
false,
 
  553                $a_ignore_erros = 
false)
 
  558                        $this->
raisePearError(
"ilDB Error: createTable(".$a_name.
")<br />".
 
  565                        $this->
raisePearError(
"ilDB Error: createTable(".$a_name.
")<br />".
 
  576                $manager = $this->db->loadModule(
'Manager');
 
  577                $r = $manager->createTable($a_name, $a_definition_array, 
$options);
 
  579                return $this->
handleError($r, 
"createTable(".$a_name.
")");
 
  598        function dropTable($a_name, $a_error_if_not_existing = 
true)
 
  600                if (!$a_error_if_not_existing)
 
  603                        if (!in_array($a_name, $tables))
 
  609                $manager = $this->db->loadModule(
'Manager');
 
  614                        $constraints = $manager->listTableConstraints($a_name);
 
  615                        $this->
handleError($constraints, 
"dropTable(".$a_name.
"), listTableConstraints");
 
  616                        foreach ($constraints as $c)
 
  618                                if (
substr($c, 0, 4) != 
"sys_")
 
  620                                        $r = $manager->dropConstraint($a_name, $c);
 
  621                                        $this->
handleError($r, 
"dropTable(".$a_name.
"), dropConstraint");
 
  626                        $indexes = $manager->listTableIndexes($a_name);
 
  627                        $this->
handleError($indexes, 
"dropTable(".$a_name.
"), listTableIndexes");
 
  628                        foreach ($indexes as $i)
 
  630                                $r = $manager->dropIndex($a_name, $i);
 
  631                                $this->
handleError($r, 
"dropTable(".$a_name.
"), dropIndex");
 
  636                $seqs = $manager->listSequences();
 
  637                if (in_array($a_name, $seqs))
 
  639                        $r = $manager->dropSequence($a_name);
 
  640                        $this->
handleError($r, 
"dropTable(".$a_name.
"), dropSequence");
 
  644                $r = $manager->dropTable($a_name);
 
  646                return $this->
handleError($r, 
"dropTable(".$a_name.
")");
 
  656                if ($a_options == 
"")
 
  658                        $a_options = array();
 
  661                $manager = $this->db->loadModule(
'Manager');
 
  662                $r = $manager->alterTable($a_name, $a_changes, 
false);
 
  664                return $this->
handleError($r, 
"alterTable(".$a_name.
")");
 
  678                $manager = $this->db->loadModule(
'Manager');
 
  682                        $this->
raisePearError(
"ilDB Error: addTableColumn(".$a_table.
", ".$a_column.
")<br />".
 
  687                        $this->
raisePearError(
"ilDB Error: addTableColumn(".$a_table.
", ".$a_column.
")<br />".
 
  693                                $a_column => $a_attributes
 
  697                $r = $manager->alterTable($a_table, $changes, 
false);
 
  699                return $this->
handleError($r, 
"addTableColumn(".$a_table.
", ".$a_column.
")");
 
  712                $manager = $this->db->loadModule(
'Manager');
 
  720                $r = $manager->alterTable($a_table, $changes, 
false);
 
  722                return $this->
handleError($r, 
"dropTableColumn(".$a_table.
", ".$a_column.
")");
 
  735                $manager = $this->db->loadModule(
'Manager');
 
  736                $reverse = $this->db->loadModule(
'Reverse');
 
  737                $def = $reverse->getTableFieldDefinition($a_table, $a_column);
 
  739                $this->
handleError($def, 
"modifyTableColumn(".$a_table.
")");
 
  741                if (is_file(
"./Services/Database/classes/class.ilDBAnalyzer.php"))
 
  743                        include_once(
"./Services/Database/classes/class.ilDBAnalyzer.php");
 
  747                        include_once(
"../Services/Database/classes/class.ilDBAnalyzer.php");
 
  750                $best_alt = $analyzer->getBestDefinitionAlternative($def);
 
  751                $def = $def[$best_alt];
 
  752                unset($def[
"nativetype"]);
 
  753                unset($def[
"mdb2type"]);
 
  756                $type = ($a_attributes[
"type"] != 
"")
 
  757                        ? $a_attributes[
"type"]
 
  759                foreach ($def as $k => $v)
 
  761                        if ($k != 
"type" && !in_array($k, $this->allowed_attributes[$type]))
 
  767                foreach ($a_attributes as $k => $v)
 
  769                        $check_array[$k] = $v;
 
  773                        $this->
raisePearError(
"ilDB Error: modifyTableColumn(".$a_table.
", ".$a_column.
")<br />".
 
  778                if ($this->getDbType() == 
"oracle")
 
  780                        if ($def[
"notnull"] == 
true && ($a_attributes[
"notnull"] == 
true 
  781                                || !isset($a_attributes[
"notnull"])))
 
  783                                unset($def[
"notnull"]);
 
  784                                unset($a_attributes[
"notnull"]);
 
  786                        if ($def[
"notnull"] == 
false && ($a_attributes[
"notnull"] == 
false 
  787                                || !isset($a_attributes[
"notnull"])))
 
  789                                unset($def[
"notnull"]);
 
  790                                unset($a_attributes[
"notnull"]);
 
  793                foreach ($a_attributes as $a => $v)
 
  798                $a_attributes[
"definition"] = $def;
 
  802                                $a_column => $a_attributes
 
  806                $r = $manager->alterTable($a_table, $changes, 
false);
 
  808                return $this->
handleError($r, 
"modifyTableColumn(".$a_table.
")");
 
  824                        $this->
raisePearError(
"ilDB Error: renameTableColumn(".$a_table.
",".$a_column.
",".$a_new_column.
")<br />".
 
  828                $manager = $this->db->loadModule(
'Manager');
 
  829                $reverse = $this->db->loadModule(
'Reverse');
 
  830                $def = $reverse->getTableFieldDefinition($a_table, $a_column);
 
  832                $this->
handleError($def, 
"renameTableColumn(".$a_table.
",".$a_column.
",".$a_new_column.
")");
 
  834                if (is_file(
"./Services/Database/classes/class.ilDBAnalyzer.php"))
 
  836                        include_once(
"./Services/Database/classes/class.ilDBAnalyzer.php");
 
  840                        include_once(
"../Services/Database/classes/class.ilDBAnalyzer.php");
 
  844                $best_alt = $analyzer->getBestDefinitionAlternative($def);
 
  845                $def = $def[$best_alt];
 
  846                unset($def[
"nativetype"]);
 
  847                unset($def[
"mdb2type"]);
 
  849                $f[
"definition"] = $def;
 
  850                $f[
"name"] = $a_new_column;
 
  858                $r = $manager->alterTable($a_table, $changes, 
false);
 
  860                return $this->
handleError($r, 
"renameTableColumn(".$a_table.
",".$a_column.
",".$a_new_column.
")");
 
  874                        $this->
raisePearError(
"ilDB Error: renameTable(".$a_name.
",".$a_new_name.
")<br />".
 
  878                $manager = $this->db->loadModule(
'Manager');
 
  879                $r = $manager->alterTable($a_name, array(
"name" => $a_new_name), 
false);
 
  881                $query = 
"UPDATE abstraction_progress ".
 
  882                        "SET table_name = ".$this->db->quote($a_new_name,
'text').
" ".
 
  883                        "WHERE table_name = ".$this->db->quote($a_name,
'text');
 
  886                return $this->
handleError($r, 
"renameTable(".$a_name.
",".$a_new_name.
")");
 
  898                $manager = $this->db->loadModule(
'Manager');
 
  901                foreach ($a_fields as $f)
 
  903                        $fields[$f] = array();
 
  905                $definition = array (
 
  909                $r = $manager->createConstraint($a_table,
 
  912                return $this->
handleError($r, 
"addPrimaryKey(".$a_table.
")");
 
  931                $manager = $this->db->loadModule(
'Manager');
 
  933                $r = $manager->dropConstraint($a_table,
 
  936                return $this->
handleError($r, 
"dropPrimaryKey(".$a_table.
")");
 
  946        function addIndex($a_table, $a_fields, $a_name = 
"in", $a_fulltext = 
false)
 
  948                $manager = $this->db->loadModule(
'Manager');
 
  953                        $this->
raisePearError(
"ilDB Error: addIndex(".$a_table.
",".$a_name.
")<br />".
 
  958                foreach ($a_fields as $f)
 
  960                        $fields[$f] = array();
 
  962                $definition = array (
 
  968                        $r = $manager->createIndex($a_table, $this->
constraintName($a_table, $a_name), $definition);
 
  978                return $this->
handleError($r, 
"addIndex(".$a_table.
")");
 
 1005                $manager = $this->db->loadModule(
'Manager');
 
 1006                $reverse = $this->db->loadModule(
'Reverse');
 
 1009                        foreach($manager->listTableIndexes($a_table) as $idx_name)
 
 1011                                $def = $reverse->getTableIndexDefinition($a_table,$idx_name);
 
 1012                                $idx_fields = array_keys((array) $def[
'fields']);
 
 1014                                if($idx_fields === $a_fields)
 
 1031                $manager = $this->db->loadModule(
'Manager');
 
 1032                $reverse = $this->db->loadModule(
'Reverse');
 
 1035                        foreach($manager->listTableIndexes($a_table) as $idx_name)
 
 1037                                $def = $reverse->getTableIndexDefinition($a_table,$idx_name);
 
 1038                                $idx_fields = array_keys((array) $def[
'fields']);
 
 1040                                if($idx_fields === $a_fields)
 
 1042                                        return $this->
dropIndex($a_table, $idx_name);
 
 1059                $manager = $this->db->loadModule(
'Manager');
 
 1063                        $r = $manager->dropIndex($a_table, $this->
constraintName($a_table, $a_name));
 
 1067                        $this->dropFulltextIndex($a_table, $a_name);
 
 1070                return $this->
handleError($r, 
"dropIndex(".$a_table.
")");
 
 1082                $manager = $this->db->loadModule(
'Manager');
 
 1087                        $this->
raisePearError(
"ilDB Error: addUniqueConstraint(".$a_table.
",".$a_name.
")<br />".
 
 1092                foreach ($a_fields as $f)
 
 1094                        $fields[$f] = array();
 
 1096                $definition = array (
 
 1101                $r = $manager->createConstraint($a_table, $this->
constraintName($a_table, $a_name), $definition);
 
 1103                return $this->
handleError($r, 
"addUniqueConstraint(".$a_table.
")");
 
 1111                $manager = $this->db->loadModule(
'Manager');
 
 1113                $r = $manager->createSequence($a_table_name, $a_start);
 
 1115                return $this->
handleError($r, 
"createSequence(".$a_table_name.
")");
 
 1124                $manager = $this->db->loadModule(
'Manager');
 
 1126                $r = $manager->dropSequence($a_table_name);
 
 1128                return $this->
handleError($r, 
"dropSequence(".$a_table_name.
")");
 
 1138                if (!preg_match (
"/^[a-z]+[_a-z0-9]*$/", $a_name))
 
 1140                        $this->error_str = 
"Table name must only contain _a-z0-9 and must start with a-z.";
 
 1146                        $this->error_str = 
"Invalid table name '".$a_name.
"' (Reserved Word).";
 
 1150                if (strtolower(
substr($a_name, 0, 4)) == 
"sys_")
 
 1152                        $this->error_str = 
"Invalid table name '".$a_name.
"'. Name must not start with 'sys_'.";
 
 1156                if (strlen($a_name) > 22)
 
 1158                        $this->error_str = 
"Invalid table name '".$a_name.
"'. Maximum table identifer lenght is 22 bytes.";
 
 1172                foreach ($a_cols as $col => $def)
 
 1209                if (!in_array($a_def[
"type"], array(
"text", 
"integer", 
"float", 
"date", 
"time", 
"timestamp", 
"clob", 
"blob")))
 
 1211                        switch ($a_def[
"type"])
 
 1214                                        $this->error_str = 
"Invalid column type '".$a_def[
"type"].
"'. Use integer(1) instead.";
 
 1218                                        $this->error_str = 
"Invalid column type '".$a_def[
"type"].
"'. Use float or integer instead.";
 
 1222                                        $this->error_str = 
"Invalid column type '".$a_def[
"type"].
"'. Allowed types are: ".
 
 1223                                                "text, integer, float, date, time, timestamp, clob and blob.";
 
 1230                foreach ($a_def as $k => $v)
 
 1234                                $this->error_str = 
"Attribute '".$k.
"' is not allowed for column type '".$a_def[
"type"].
"'.";
 
 1240                switch ($a_def[
"type"])
 
 1243                                if ($a_def[
"length"] < 1 || $a_def[
"length"] > 4000)
 
 1245                                        if (!$a_modify_mode || isset($a_def[
"length"]))
 
 1247                                                $this->error_str = 
"Invalid length '".$a_def[
"length"].
"' for type text.".
 
 1248                                                        " Length must be >=1 and <= 4000.";
 
 1255                                if (!in_array($a_def[
"length"], array(1, 2, 3, 4, 8)))
 
 1257                                        if (!$a_modify_mode || isset($a_def[
"length"]))
 
 1259                                                $this->error_str = 
"Invalid length '".$a_def[
"length"].
"' for type integer.".
 
 1260                                                        " Length must be 1, 2, 3, 4 or 8 (bytes).";
 
 1264                                if ($a_def[
"unsigned"])
 
 1266                                        $this->error_str = 
"Unsigned attribut must not be true for type integer.";
 
 1282                if (!preg_match (
"/^[a-z]+[_a-z0-9]*$/", $a_name))
 
 1284                        $this->error_str = 
"Invalid column name '".$a_name.
"'. Column name must only contain _a-z0-9 and must start with a-z.";
 
 1290                        $this->error_str = 
"Invalid column name '".$a_name.
"' (Reserved Word).";
 
 1294                if (strtolower(
substr($a_name, 0, 4)) == 
"sys_")
 
 1296                        $this->error_str = 
"Invalid column name '".$a_name.
"'. Name must not start with 'sys_'.";
 
 1300                if (strlen($a_name) > 30)
 
 1302                        $this->error_str = 
"Invalid column name '".$a_name.
"'. Maximum column identifer lenght is 30 bytes.";
 
 1316                if (!preg_match (
"/^[a-z]+[_a-z0-9]*$/", $a_name))
 
 1318                        $this->error_str = 
"Invalid column name '".$a_name.
"'. Column name must only contain _a-z0-9 and must start with a-z.";
 
 1324                        $this->error_str = 
"Invalid column name '".$a_name.
"' (Reserved Word).";
 
 1328                if (strlen($a_name) > 3)
 
 1330                        $this->error_str = 
"Invalid index name '".$a_name.
"'. Maximum index identifer lenght is 3 bytes.";
 
 1349                return $a_constraint;
 
 1358                include_once(
"./Services/Database/classes/class.ilDBMySQL.php");
 
 1360                if (in_array(strtoupper($a_word), $mysql_reserved_words))
 
 1364                include_once(
"./Services/Database/classes/class.ilDBOracle.php");
 
 1366                if (in_array(strtoupper($a_word), $oracle_reserved_words))
 
 1370                include_once(
"./Services/Database/classes/class.ilDBPostgreSQL.php");
 
 1372                if (in_array(strtoupper($a_word), $postgres_reserved_words))
 
 1393        function query($sql, $a_handle_error = 
true)
 
 1401                $r = $this->db->query($sql);
 
 1407                if ($a_handle_error)
 
 1422        function queryF($a_query, $a_types, $a_values)
 
 1424                if (!is_array($a_types) || !is_array($a_values) ||
 
 1425                        count($a_types) != count($a_values))
 
 1427                        $this->
raisePearError(
"ilDB::queryF: Types and values must be arrays of same size. ($a_query)");
 
 1429                $quoted_values = array();
 
 1430                foreach($a_types as $k => 
$t)
 
 1432                        $quoted_values[] = $this->
quote($a_values[$k], 
$t);
 
 1434                $query = vsprintf($a_query, $quoted_values);
 
 1448                if (!is_array($a_types) || !is_array($a_values) ||
 
 1449                        count($a_types) != count($a_values))
 
 1451                        $this->
raisePearError(
"ilDB::manipulateF: types and values must be arrays of same size. ($a_query)");
 
 1453                $quoted_values = array();
 
 1454                foreach($a_types as $k => 
$t)
 
 1456                        $quoted_values[] = $this->
quote($a_values[$k], 
$t);
 
 1458                $query = vsprintf($a_query, $quoted_values);
 
 1468                $pos1 = strpos(strtolower($sql), 
"from ");
 
 1472                        $tablef = 
substr($sql, $pos1+5);
 
 1473                        $pos2 = strpos(strtolower($tablef), 
" ");
 
 1476                                $table =
substr($tablef, 0, $pos2);
 
 1483                if (trim($table) != 
"")
 
 1485                        if (!is_array($this->ttt) || !in_array($table, $this->ttt))
 
 1488                                $this->ttt[] = $table;
 
 1493                        echo 
"<br><b>".$sql.
"</b>";
 
 1502                $this->db->setLimit($a_limit, $a_offset);
 
 1513                $r = $this->db->nextId($a_table_name, 
false);
 
 1515                return $this->
handleError($r, 
"nextId(".$a_table_name.
")");
 
 1536                $r = $this->db->exec($sql);
 
 1542                return $this->
handleError($r, 
"manipulate(".$sql.
")");
 
 1553        function prepare($a_query, $a_types = 
null, $a_result_types = 
null)
 
 1555                $res = $this->db->prepare($a_query, $a_types, $a_result_types);
 
 1585                $res = $a_stmt->execute($a_data);
 
 1601                $res = $this->db->extended->executeMultiple($a_stmt,$a_data);
 
 1603                return $this->
handleError(
$res, 
"executeMultiple(".$a_stmt->query.
")");
 
 1615                $field_values = array();
 
 1616                $placeholders = array();
 
 1621                foreach ($a_columns as $k => $col)
 
 1624                        $placeholders[] = 
"%s";
 
 1625                        $placeholders2[] = 
":$k";
 
 1629                        if ($col[0] == 
'integer' && !is_null($col[1]))
 
 1631                                $col[1] = (int) $col[1];
 
 1634                        $values[] = $col[1];
 
 1635                        $field_values[$k] = $col[1];
 
 1636                        if ($col[0] == 
"blob" || $col[0] == 
"clob")
 
 1644                        $st = $this->db->prepare(
"INSERT INTO ".$a_table.
" (".implode($fields,
",").
") VALUES (".
 
 1647                        $this->
handleError($st, 
"insert / prepare/execute(".$a_table.
")");
 
 1649                        $r = $st->execute($field_values);
 
 1653                        $this->
handleError($r, 
"insert / prepare/execute(".$a_table.
")");
 
 1658                        $q = 
"INSERT INTO ".$a_table.
" (".implode($fields,
",").
") VALUES (".
 
 1659                                implode($placeholders,
",").
")";
 
 1673        function update($a_table, $a_columns, $a_where)
 
 1676                $field_values = array();
 
 1677                $placeholders = array();
 
 1682                foreach ($a_columns as $k => $col)
 
 1685                        $placeholders[] = 
"%s";
 
 1686                        $placeholders2[] = 
":$k";
 
 1690                        if ($col[0] == 
'integer' && !is_null($col[1]))
 
 1692                                $col[1] = (int) $col[1];
 
 1695                        $values[] = $col[1];
 
 1696                        $field_values[$k] = $col[1];
 
 1697                        if ($col[0] == 
"blob" || $col[0] == 
"clob")
 
 1706                        $q = 
"UPDATE ".$a_table.
" SET ";
 
 1708                        foreach ($fields as $k => $field)
 
 1710                                $q.= $lim.$field.
" = ".$placeholders2[$k];
 
 1715                        foreach ($a_where as $k => $col)
 
 1717                                $q.= $lim.$k.
" = ".$this->
quote($col[1], $col[0]);
 
 1721                        $r = $st->execute($field_values);
 
 1724                        $this->
handleError($r, 
"update / prepare/execute(".$a_table.
")");
 
 1729                        foreach ($a_where as $k => $col)
 
 1732                                $values[] = $col[1];
 
 1733                                $field_values[$k] = $col;
 
 1735                        $q = 
"UPDATE ".$a_table.
" SET ";
 
 1737                        foreach ($fields as $k => $field)
 
 1739                                $q.= $lim.$field.
" = ".$placeholders[$k];
 
 1744                        foreach ($a_where as $k => $col)
 
 1746                                $q.= $lim.$k.
" = %s";
 
 1762        function replace($a_table, $a_pk_columns, $a_other_columns)
 
 1765                $a_columns = array_merge($a_pk_columns, $a_other_columns);
 
 1767                $field_values = array();
 
 1768                $placeholders = array();
 
 1773                foreach ($a_columns as $k => $col)
 
 1776                        $placeholders[] = 
"%s";
 
 1777                        $placeholders2[] = 
":$k";
 
 1781                        if ($col[0] == 
'integer' && !is_null($col[1]))
 
 1783                                $col[1] = (int) $col[1];
 
 1786                        $values[] = $col[1];
 
 1787                        $field_values[$k] = $col[1];
 
 1788                        if ($col[0] == 
"blob" || $col[0] == 
"clob")
 
 1796                        $st = $this->db->prepare(
"REPLACE INTO ".$a_table.
" (".implode($fields,
",").
") VALUES (".
 
 1798                        $this->
handleError($st, 
"insert / prepare/execute(".$a_table.
")");
 
 1799                        $r = $st->execute($field_values);
 
 1801                        $this->
handleError($r, 
"insert / prepare/execute(".$a_table.
")");
 
 1806                        $q = 
"REPLACE INTO ".$a_table.
" (".implode($fields,
",").
") VALUES (".
 
 1807                                implode($placeholders,
",").
")";
 
 1828                return $a_st->free();
 
 1848                return $a_set->numRows();
 
 1866        function in($a_field, $a_values, $negate = 
false, $a_type = 
"")
 
 1868                if (count($a_values) == 0)
 
 1872                        return $negate ? 
' 1=1 ' : 
' 1=2 ';
 
 1877                        $str = $a_field.(($negate) ? 
" NOT" : 
"").
" IN (?".str_repeat(
",?", count($a_values) - 1).
")";
 
 1881                        $str = $a_field.(($negate) ? 
" NOT" : 
"").
" IN (";
 
 1883                        foreach ($a_values as $v)
 
 1885                                $str.= $sep.$this->quote($v, $a_type);
 
 1899                if (!is_array($a_arr))
 
 1905                        $type_arr = array_fill(0, $a_cnt, $a_type);
 
 1909                        $type_arr = array();
 
 1911                return array_merge($a_arr, $type_arr);
 
 1933        public function concat($a_values,$a_allow_null = 
true)
 
 1935                if(!count($a_values))
 
 1940                $concat = 
' CONCAT(';
 
 1942                foreach($a_values as $field_info)
 
 1944                        $val = $field_info[0];
 
 1953                                $concat .= 
'COALESCE(';
 
 1975        function substr($a_exp, $a_pos = 1, $a_len = -1)
 
 1980                        $lenstr = 
", ".$a_len;
 
 1982                return " SUBSTR(".$a_exp.
", ".$a_pos.$lenstr.
") ";
 
 1993                return " UPPER(".$a_exp.
") ";
 
 2004                return " LOWER(".$a_exp.
") ";
 
 2014        public function locate($a_needle,$a_string,$a_start_pos = 1)
 
 2016                $locate = 
' LOCATE( ';
 
 2017                $locate .= $a_needle;
 
 2019                $locate .= $a_string;
 
 2021                $locate .= $a_start_pos;
 
 2032        function like($a_col, $a_type, $a_value = 
"?", $case_insensitive = 
true)
 
 2034                if (!in_array($a_type, array(
"text", 
"clob", 
"blob")))
 
 2036                        $this->
raisePearError(
"Like: Invalid column type '".$a_type.
"'.", $this->error_class->FATAL);
 
 2038                if ($a_value == 
"?")
 
 2040                        if ($case_insensitive)
 
 2042                                return "UPPER(".$a_col.
") LIKE(UPPER(?))";
 
 2046                                return $a_col .
" LIKE(?)";
 
 2051                        if ($case_insensitive)
 
 2054                                return " UPPER(".$a_col.
") LIKE(UPPER(".$this->
quote($a_value, 
'text').
"))";
 
 2059                                return " ".$a_col.
" LIKE(".$this->
quote($a_value, 
'text').
")";
 
 2068        function equals($a_col, $a_value, $a_type, $a_empty_or_null = 
false)
 
 2070                if (!$a_empty_or_null || $a_value != 
"")
 
 2072                        return $a_col.
" = ".$this->
quote($a_value, $a_type);
 
 2076                        return "(".$a_col.
" = '' OR $a_col IS NULL)";
 
 2083        function equalsNot($a_col, $a_value, $a_type, $a_empty_or_null = 
false)
 
 2085                if (!$a_empty_or_null)
 
 2087                        return $a_col.
" <> ".$this->
quote($a_value, $a_type);
 
 2091                        return "(".$a_col.
" <> ".$this->
quote($a_value, $a_type). 
" OR ".
 
 2096                        return "(".$a_col.
" <> '' AND $a_col IS NOT NULL)";
 
 2108                return "FROM_UNIXTIME(".$a_expr.
")";
 
 2116                return "UNIX_TIMESTAMP()";
 
 2142                if (is_array($tables))
 
 2144                        if (in_array($a_table, $tables))
 
 2162                $column_visibility = 
false;
 
 2163                $manager = $this->db->loadModule(
'Manager');
 
 2164                $r = $manager->listTableFields($a_table);
 
 2168                        foreach($r as $field)
 
 2170                                if ($field == $a_column_name)
 
 2172                                        $column_visibility = 
true;
 
 2177                return $column_visibility;
 
 2189                if (is_file(
"./Services/Database/classes/class.ilDBAnalyzer.php"))
 
 2191                        include_once(
"./Services/Database/classes/class.ilDBAnalyzer.php");
 
 2195                        include_once(
"../Services/Database/classes/class.ilDBAnalyzer.php");
 
 2198                $cons = $analyzer->getConstraintsInformation($a_table);
 
 2199                foreach ($cons as $c)
 
 2201                        if ($c[
"type"] == 
"unique" && count($a_fields) == count($c[
"fields"]))
 
 2204                                foreach ($a_fields as $f)
 
 2206                                        if (!isset($c[
"fields"][$f]))
 
 2228                $manager = $this->db->loadModule(
'Manager');
 
 2229                $r = $manager->listTables();
 
 2249                if (is_array($sequences))
 
 2251                        if (in_array($a_sequence, $sequences))
 
 2266                $manager = $this->db->loadModule(
'Manager');
 
 2267                $r = $manager->listSequences();
 
 2285        function quote($a_query, $a_type = 
null)
 
 2287                if ($a_query == 
"" && is_null($a_type))
 
 2293                if($a_type == 
'integer' && !is_null($a_query))
 
 2295                        return (
int) $a_query;
 
 2298                if ($a_type == 
"blob" || $a_type == 
"clob")
 
 2300                        $this->
raisePearError(
"ilDB::quote: Quoting not allowed on type '".$a_type.
"'. Please use ilDB->insert and ilDB->update to write clobs.", $this->error_class->FATAL);
 
 2303                return $this->db->quote($a_query, $a_type);
 
 2315                return $this->db->quoteIdentifier($a_identifier);
 
 2330                if (!$this->db->supports(
'transactions'))
 
 2332                        $this->
raisePearError(
"ilDB::beginTransaction: Transactions are not supported.", $this->error_class->FATAL);
 
 2334                $res = $this->db->beginTransaction();
 
 2344                $res = $this->db->commit();
 
 2354                $res = $this->db->rollback();
 
 2389                $res = $this->db->autoExecute($a_tablename,$a_fields,$a_mode,$a_where);
 
 2405                $res = $this->db->lastInsertId();
 
 2425                $set = $this->db->query($sql);
 
 2448                $set = $this->
query($sql);
 
 2449                $r = $set->fetchRow($mode);
 
 2464                $this->sub_type = (string)$a_value;
 
const MDB2_AUTOQUERY_UPDATE
const MDB2_AUTOQUERY_SELECT
const MDB2_AUTOQUERY_INSERT
Used by autoPrepare()
const MDB2_AUTOQUERY_DELETE
const MDB2_PORTABILITY_ALL
Portability: turn on all portability features.
const MDB2_PORTABILITY_FIX_CASE
Portability: convert names of tables and fields to case defined in the "field_case" option when using...
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare()
const MDB2_PORTABILITY_EMPTY_TO_NULL
Portability: convert empty values to null strings in data output by query*() and fetch*().
const MDB2_FETCHMODE_OBJECT
Column data as object properties.
const MDB2_FETCHMODE_ASSOC
Column data indexed by column names.
const PEAR_ERROR_CALLBACK
isError($data, $code=null)
Tell whether a value is a MDB2 error.
& connect($dsn, $options=false)
Create a new MDB2 connection object and connect to the specified database.
setErrorHandling($mode=null, $options=null)
Sets how errors generated by this object should be handled.
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object's de...
const DB_FETCHMODE_OBJECT
readVariable($a_group, $a_var_name)
reads a single variable from a group @access public
This class gives all kind of DB information using the MDB2 manager and reverse module.
static getReservedWords()
Get reserved words.
static getReservedWords()
Get reserved words.
static getReservedWords()
Get reserved words.
replace($a_table, $a_pk_columns, $a_other_columns)
Replace into method.
lockTables($a_tables)
Abstraction of lock table.
listTables()
Get all tables.
tableColumnExists($a_table, $a_column_name)
Checks for the existence of a table column.
equals($a_col, $a_value, $a_type, $a_empty_or_null=false)
Use this only on text fields.
initFromIniFile($tmpClientIniFile=null)
Init db parameters from ini file.
executeMultiple($a_stmt, $a_data)
Execute a query statement prepared by either prepare() or prepareManip() with multiple data arrays.
manipulate($sql)
Data manipulation.
fetchObject($a_set)
Fetch row as object from result set.
setSubType($a_value)
Set sub type.
checkTableColumns($a_cols)
Check table columns definition.
createTable($a_name, $a_definition_array, $a_drop_table=false, $a_ignore_erros=false)
Create a new table in the database.
connectHost()
Sets up a host connection only (no specific database used).
createSequence($a_table_name, $a_start=1)
Create a sequence for a table.
enableResultBuffering($a_status)
En/disable result buffering.
addTableColumn($a_table, $a_column, $a_attributes)
Add table column Use this only on aleady "abstracted" tables.
getDBPort()
Get database port.
update($a_table, $a_columns, $a_where)
Convenient method for standard update statements, example field array:
getPrimaryKeyIdentifier()
Primary key identifier.
getLastInsertId()
Get last insert id.
rollback()
Rollback a transaction.
dropSequence($a_table_name)
Drop a sequence for a table.
connect($a_return_false_for_error=false)
Open the connection.
renameTable($a_name, $a_new_name)
Rename a table.
dropPrimaryKey($a_table)
Drop a primary key from a table.
quoteIdentifier($a_identifier)
Quote table and field names.
tableExists($a_table)
Check, whether a given table exists.
getRow($sql, $mode=DB_FETCHMODE_OBJECT)
getRow.
queryF($a_query, $a_types, $a_values)
Formatted query (for SELECTS).
in($a_field, $a_values, $negate=false, $a_type="")
Get abstract in-clause for given array.
static isReservedWord($a_word)
Checks whether a word is a reserved word in one of the supported databases.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
nextId($a_table_name)
Get next ID for an index.
modifyTableColumn($a_table, $a_column, $a_attributes)
Modify a table column Use this only on aleady "abstracted" tables.
getDBUser()
Get database user.
uniqueConstraintExists($a_table, $a_fields)
Checks if a unique constraint exists based on the fields of the unique constraint (not the name)
unixTimestamp()
Unix timestamp.
getDBName()
Get database name.
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
concat($a_values, $a_allow_null=true)
Abstraction of SQL function CONCAT.
doConnect()
Standard way to connect to db.
addTypesToArray($a_arr, $a_type, $a_cnt)
Adds a type x times to an array.
manipulateF($a_query, $a_types, $a_values)
Formatted manupulate (for DELETE, UPDATE, INSERT).
free($a_st)
Free a statement / result set.
checkIndexName($a_name)
Check whether an index name is valid.
setDBUser($a_user)
Set database user.
supportsSlave()
Supports slave.
getDBVersion()
Get DB version.
checkTableName($a_name)
Check whether a table name is valid.
static getReservedWords()
Get reserved words.
createDatabase($a_name, $a_charset="utf8", $a_collation="")
Create database.
renameTableColumn($a_table, $a_column, $a_new_column)
Rename a table column Use this only on aleady "abstracted" tables.
like($a_col, $a_type, $a_value="?", $case_insensitive=true)
Like.
numRows($a_set)
Fetch row as associative array from result set.
equalsNot($a_col, $a_value, $a_type, $a_empty_or_null=false)
Use this only on text fields.
setLimit($a_limit, $a_offset=0)
Set limit and offset for a query.
checkColumnDefinition($a_def, $a_modify_mode=false)
Check whether a column definition is valid.
query($sql, $a_handle_error=true)
Query.
insert($a_table, $a_columns)
Convenient method for standard insert statements, example field array:
isFulltextIndex($a_table, $a_name)
Is index a fulltext index?
setDBPort($a_port)
Set database port.
optimizeTable($a_table)
Optimize Table.
initHostConnection()
Initialize the host connection (no specific database)
getCreateTableOptions()
Get options for the create table statement.
addUniqueConstraint($a_table, $a_fields, $a_name="con")
Add a unique constraint to a table.
logStatement($sql)
Helper function, should usually not be called.
dropTable($a_name, $a_error_if_not_existing=true)
Drop a table.
static isDbError($a_res)
Check error.
alterTable($a_name, $a_changes)
Alter a table in the database This method is DEPRECATED, see http://www.ilias.de/docu/goto....
commit()
Commit a transaction.
checkColumnName($a_name)
Check whether a column name is valid.
setDBName($a_name)
Set database name.
checkColumn($a_col, $a_def)
Check column definition.
getSubType()
Get sub type.
dropIndex($a_table, $a_name="in")
Drop an index from a table.
beginTransaction()
Begin Transaction.
raisePearError($a_message, $a_level="")
Raise an error.
addIndex($a_table, $a_fields, $a_name="in", $a_fulltext=false)
Add an index to a table.
prepare($a_query, $a_types=null, $a_result_types=null)
Prepare a query (SELECT) statement to be used with execute.
setDBHost($a_host)
Set database host.
addPrimaryKey($a_table, $a_fields)
Add a primary key to a table.
execute($a_stmt, $a_data=null)
Execute a query statement prepared by either prepare() or prepareManip()
fetchAssoc($a_set)
Fetch row as associative array from result set.
getDBPassword()
Get database password.
substr($a_exp, $a_pos=1, $a_len=-1)
Substring.
indexExistsByFields($a_table, $a_fields)
Check if index exists.
sequenceExists($a_sequence)
Check, whether a given sequence exists.
fromUnixtime($a_expr, $a_to_text=true)
fromUnixtime (makes timestamp out of unix timestamp)
dropIndexByFields($a_table, $a_fields)
Drop index by field(s)
addFulltextIndex($a_table, $a_fields, $a_name="in")
Add fulltext index.
useSlave($a_val=true)
Use slave.
getHostDSN()
Should return a valid value, if host connections are possible (connectHost) to create a new database ...
unlockTables()
Unlock tables locked by previous lock table calls.
getDBHost()
Get database host.
autoExecute($a_tablename, $a_fields, $a_mode=MDB2_AUTOQUERY_INSERT, $a_where=false)
Wrapper for Pear autoExecute.
listSequences()
Get all sequences.
dropTableColumn($a_table, $a_column)
Drop table column Use this only on aleady "abstracted" tables.
locate($a_needle, $a_string, $a_start_pos=1)
Create locate string.
initConnection()
Initialize the database connection.
setDBPassword($a_password)
Set database password.
prepareManip($a_query, $a_types=null)
Prepare a data manipulation statement to be used with execute.
quote($a_query, $a_type=null)
Wrapper for quote method.
loadMDB2Extensions()
load additional mdb2 extensions and set their constants
Error Handling & global info handling uses PEAR error class.
if(!is_array($argv)) $options