43 $ilDB = $DIC->database();
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) .
"." 208 $ilDB = $DIC->database();
210 $st =
$ilDB->prepare(
"SELECT count(*) AS cnt FROM `" . $a_table_name .
"`");
227 "REPLACE INTO abstraction_progress (table_name, step)" .
" VALUES (?,?)",
253 $ilDB = $DIC->database();
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 .
"` = ''");
280 $ilDB = $DIC->database();
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'");
318 $ilDB = $DIC->database();
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) .
"`");
337 $ilDB = $DIC->database();
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 !=
"") {
357 $this->
ilDBInterface->modifyTableColumn($a_table_name, $a_auto_inc_field, array());
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) {
386 $this->
ilDBInterface->query(
"ALTER TABLE `" . $a_table .
"` DROP INDEX `" . $index[
"name"] .
"`");
400 if (is_array($a_constraints)) {
401 foreach ($a_constraints as
$c) {
402 if ($c[
"type"] ==
"unique") {
403 $this->
ilDBInterface->query(
"ALTER TABLE `" . $a_table .
"` DROP INDEX `" . $c[
"name"] .
"`");
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);
561 $this->
ilDBInterface->addIndex($a_table, $fields, strtolower($index[
"name"]), $index[
"fulltext"]);
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;
lowerCaseColumnNames($a_table_name)
lower case column names
replaceEmptyStringsWithNull($a_table)
Replace empty strings with null values.
This class includes methods that help to abstract ILIAS 3.10.x MySQL tables for the use with MDB2 abs...
fixClobNotNull($a_table)
This is only used on tables that have already been abstracted but missed the "full treatment"...
Class ilDatabaseException.
removeAutoIncrement($a_table_name, $a_auto_inc_field)
Remove auto_increment attribute of a field.
countRecords($a_table_name)
Check number of records before and after.
foreach($_POST as $key=> $value) $res
addAutoIncrementSequence($a_table, $a_auto_inc_field)
Add autoincrement sequence.
fixIndexNames($a_table)
This is only used on tables that have already been abstracted but missed the "full treatment"...
replaceEmptyDatesWithNull($a_table)
Replace empty dates with null.
__construct()
Constructor.
storeStep($a_table, $a_step)
Store performed step.
alterTable($a_table, $a_fields, $a_set_text_ts_fields_notnull_false=true, $pk="")
lowerCaseTableName($a_table_name)
Lower case table and field names.
performAbstraction($a_table_name, $a_set_text_ts_fields_notnull_false=true)
Converts an existing (MySQL) ILIAS table in an abstract table.
fixDatetimeValues($a_table)
This is only used on tables that have already been abstracted but missed the "full treatment"...
addIndices($a_table, $a_indices)
Add indices.
addPrimaryKey($a_table, $a_pk)
removeIndices($a_table, $a_indices)
Remove Indices.
This class gives all kind of DB information using the database manager and reverse module...
removeConstraints($a_table, $a_constraints)
Remove Constraints.
removePrimaryKey($a_table, $a_pk)
Remove primary key from table.
addConstraints($a_table, $a_constraints)
Add constraints.
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d