48 if (@is_file(
'../Services/Database/classes/class.ilDBAnalyzer.php')) {
49 include_once
'../Services/Database/classes/class.ilDBAnalyzer.php';
51 include_once
'./Services/Database/classes/class.ilDBAnalyzer.php';
63 $this->testmode = $a_testmode;
97 $a_table_name = strtolower($a_table_name);
102 $auto_inc_field = $this->analyzer->getAutoIncrementField($a_table_name);
105 $pk = $this->analyzer->getPrimaryKeyInformation($a_table_name);
108 $indices = $this->analyzer->getIndicesInformation($a_table_name);
111 $constraints = $this->analyzer->getConstraintsInformation($a_table_name);
114 $fields = $this->analyzer->getFieldInformation($a_table_name);
135 $this->
alterTable($a_table_name, $fields, $a_set_text_ts_fields_notnull_false, $pk);
137 $a_table_name = strtolower($a_table_name) .
"_copy";
167 if ($auto_inc_field !=
"") {
189 if ($nr_rec != $nr_rec2) {
191 "ilMySQLAbstraction: Unexpected difference in table record number, table '" . $a_table_name .
"'." .
" Before: " . ((
int) $nr_rec) .
", After: " . ((
int) $nr_rec2) .
"."
210 $st =
$ilDB->prepare(
"SELECT count(*) AS cnt FROM `" . $a_table_name .
"`");
227 "REPLACE INTO abstraction_progress (table_name, step)" .
" VALUES (?,?)",
255 $fields = $this->analyzer->getFieldInformation($a_table);
257 foreach ($fields as $field =>
$def) {
258 if (
$def[
"type"] ==
"text"
259 && (
$def[
"length"] >= 1 &&
$def[
"length"] <= 4000)
261 $upfields[] = $field;
264 foreach ($upfields as $uf) {
265 $ilDB->query(
"UPDATE `" . $a_table .
"` SET `" . $uf .
"` = null WHERE `" . $uf .
"` = ''");
286 $fields = $this->analyzer->getFieldInformation($a_table);
288 foreach ($fields as $field =>
$def) {
289 if (
$def[
"type"] ==
"timestamp") {
290 $upfields[] = $field;
293 foreach ($upfields as $uf) {
294 $ilDB->query(
"UPDATE `" . $a_table .
"` SET `" . $uf .
"` = null WHERE `" . $uf .
"` = '0000-00-00 00:00:00'");
299 foreach ($fields as $field =>
$def) {
300 if (
$def[
"type"] ==
"date") {
301 $upfields[] = $field;
304 foreach ($upfields as $uf) {
305 $ilDB->query(
"UPDATE `" . $a_table .
"` SET `" . $uf .
"` = null WHERE `" . $uf .
"` = '0000-00-00'");
320 if ($a_table_name != strtolower($a_table_name)) {
323 mysql_query(
"ALTER TABLE `" . $a_table_name .
"` RENAME `" . strtolower($a_table_name) .
"xxx" .
"`");
324 mysql_query(
"ALTER TABLE `" . strtolower($a_table_name) .
"xxx" .
"` RENAME `" . strtolower($a_table_name) .
"`");
339 $result = mysql_query(
"SHOW COLUMNS FROM `" . $a_table_name .
"`");
341 if (
$row[
"Field"] != strtolower(
$row[
"Field"])) {
342 $ilDB->renameTableColumn($a_table_name,
$row[
"Field"], strtolower(
$row[
"Field"]));
356 if ($a_auto_inc_field !=
"") {
370 if ($a_pk[
"name"] !=
"") {
371 $this->
ilDBInterface->dropPrimaryKey($a_table, $a_pk[
"name"]);
384 if (is_array($a_indices)) {
385 foreach ($a_indices as
$index) {
400 if (is_array($a_constraints)) {
401 foreach ($a_constraints as
$c) {
402 if (
$c[
"type"] ==
"unique") {
419 public function alterTable($a_table, $a_fields, $a_set_text_ts_fields_notnull_false =
true, $pk =
"")
422 foreach ($a_fields as $field =>
$d) {
423 $def = $this->reverse->getTableFieldDefinition($a_table, $field);
425 $best_alt = $this->analyzer->getBestDefinitionAlternative(
$def);
429 if (strtolower(
$def[
"nativetype"]) ==
"timestamp"
430 && strtolower(
$def[
"default"]) ==
"current_timestamp"
432 unset(
$def[
"default"]);
435 if (strtolower(
$def[
"type"]) ==
"float") {
436 unset(
$def[
"length"]);
440 foreach (
$def as $k => $v) {
458 if (
$def[
"type"] ==
"decimal") {
459 $l_arr = explode(
",",
$def[
"length"]);
460 $def[
"length"] = $l_arr[0];
464 if (
$def[
"type"] ==
"float") {
465 unset(
$def[
"length"]);
469 if ($a_set_text_ts_fields_notnull_false
470 && (
$def[
"type"] ==
"text"
471 ||
$def[
"type"] ==
"timestamp"
472 ||
$def[
"type"] ==
"date")
473 && (!is_array($pk) || !isset($field, $pk[
"fields"][$field]))
475 $def[
"notnull"] =
false;
479 if (
$def[
"type"] ==
"integer") {
480 $def[
"unsigned"] =
false;
484 if (
$def[
"type"] ==
"blob" ||
$def[
"type"] ==
"clob") {
485 $def[
"notnull"] =
false;
489 if ((
$def[
"type"] ==
"timestamp" &&
$def[
"default"] ==
"0000-00-00 00:00:00")
490 || (
$def[
"type"] ==
"date" &&
$def[
"default"] ==
"0000-00-00")
492 unset(
$def[
"default"]);
496 foreach (
$def as $k => $v) {
499 $def[
"definition"] = $a;
501 $n_fields[$field] =
$def;
505 "change" => $n_fields,
509 $r = $this->manager->alterTable($a_table, $changes,
false);
511 $r = $this->manager->createTable(strtolower($a_table) .
"_copy", $n_fields);
524 if (is_array($a_pk[
"fields"])) {
526 foreach ($a_pk[
"fields"] as
$f => $pos) {
527 $fields[] = strtolower(
$f);
542 if (is_array($a_indices)) {
545 foreach ($a_indices as
$index) {
546 if (strlen(
$index[
"name"]) > 3) {
552 foreach ($a_indices as
$index) {
553 if (is_array(
$index[
"fields"])) {
555 $index[
"name"] =
"i" . $cnt;
558 foreach (
$index[
"fields"] as
$f => $pos) {
559 $fields[] = strtolower(
$f);
577 if (is_array($a_constraints)) {
580 foreach ($a_constraints as
$c) {
581 if (strlen(
$c[
"name"]) > 3) {
587 foreach ($a_constraints as
$c) {
588 if (is_array(
$c[
"fields"])) {
590 $c[
"name"] =
"c" . $cnt;
593 foreach (
$c[
"fields"] as
$f => $pos) {
594 $fields[] = strtolower(
$f);
596 $this->
ilDBInterface->addUniqueConstraint($a_table, $fields, strtolower(
$c[
"name"]));
614 $indices = $this->analyzer->getIndicesInformation($a_table);
615 foreach ($indices as
$index) {
616 if (strlen(
$index[
"name"]) > 3) {
622 foreach ($indices as
$index) {
638 if ($a_auto_inc_field !=
"") {
639 $set = $this->
ilDBInterface->
query(
"SELECT MAX(`" . strtolower($a_auto_inc_field) .
"`) ma FROM `" . $a_table .
"`");
641 $next = $rec[
"ma"] + 1;
657 $fields = $this->analyzer->getFieldInformation($a_table);
659 if (
$def[
"type"] ==
"clob" &&
$def[
"notnull"] ==
true) {
683 $fields = $this->analyzer->getFieldInformation($a_table);
685 if (
$def[
"type"] ==
"timestamp"
686 && (
$def[
"notnull"] ==
true ||
$def[
"default"] ==
"0000-00-00 00:00:00")
689 "type" =>
"timestamp",
692 if (
$def[
"default"] ==
"0000-00-00 00:00:00") {
693 $nd[
"default"] =
null;
697 if (
$def[
"type"] ==
"date"
698 && (
$def[
"notnull"] ==
true ||
$def[
"default"] ==
"0000-00-00")
704 if (
$def[
"default"] ==
"0000-00-00") {
705 $nd[
"default"] =
null;
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.
Class ilDatabaseException.
This class includes methods that help to abstract ILIAS 3.10.x MySQL tables for the use with MDB2 abs...
lowerCaseColumnNames($a_table_name)
lower case column names
fixClobNotNull($a_table)
This is only used on tables that have already been abstracted but missed the "full treatment".
addPrimaryKey($a_table, $a_pk)
__construct()
Constructor.
performAbstraction($a_table_name, $a_set_text_ts_fields_notnull_false=true)
Converts an existing (MySQL) ILIAS table in an abstract table.
fixIndexNames($a_table)
This is only used on tables that have already been abstracted but missed the "full treatment".
countRecords($a_table_name)
Check number of records before and after.
replaceEmptyDatesWithNull($a_table)
Replace empty dates with null.
removeConstraints($a_table, $a_constraints)
Remove Constraints.
removeIndices($a_table, $a_indices)
Remove Indices.
alterTable($a_table, $a_fields, $a_set_text_ts_fields_notnull_false=true, $pk="")
replaceEmptyStringsWithNull($a_table)
Replace empty strings with null values.
fixDatetimeValues($a_table)
This is only used on tables that have already been abstracted but missed the "full treatment".
lowerCaseTableName($a_table_name)
Lower case table and field names.
removePrimaryKey($a_table, $a_pk)
Remove primary key from table.
addConstraints($a_table, $a_constraints)
Add constraints.
addIndices($a_table, $a_indices)
Add indices.
storeStep($a_table, $a_step)
Store performed step.
removeAutoIncrement($a_table_name, $a_auto_inc_field)
Remove auto_increment attribute of a field.
addAutoIncrementSequence($a_table, $a_auto_inc_field)
Add autoincrement sequence.
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
execute($stmt, $data=array())
fetchAssoc($query_result)
addPrimaryKey($table_name, $primary_keys)
query($query)
Run a (read-only) Query on the database.
modifyTableColumn($table, $column, $attributes)
createSequence($table_name, $start=1)
prepareManip($a_query, $a_types=null)
dropIndex($a_table, $a_name="i1")
addIndex($table_name, $fields, $index_name='', $fulltext=false)
foreach($_POST as $key=> $value) $res