58 $this->testmode = $a_testmode;
92 $a_table_name = strtolower($a_table_name);
97 $auto_inc_field = $this->analyzer->getAutoIncrementField($a_table_name);
100 $pk = $this->analyzer->getPrimaryKeyInformation($a_table_name);
103 $indices = $this->analyzer->getIndicesInformation($a_table_name);
106 $constraints = $this->analyzer->getConstraintsInformation($a_table_name);
109 $fields = $this->analyzer->getFieldInformation($a_table_name);
130 $this->
alterTable($a_table_name, $fields, $a_set_text_ts_fields_notnull_false, $pk);
132 $a_table_name = strtolower($a_table_name) .
"_copy";
162 if ($auto_inc_field !=
"") {
184 if ($nr_rec != $nr_rec2) {
186 "ilMySQLAbstraction: Unexpected difference in table record number, table '" . $a_table_name .
"'." .
" Before: " . ((
int) $nr_rec) .
", After: " . ((
int) $nr_rec2) .
"."
205 $st =
$ilDB->prepare(
"SELECT count(*) AS cnt FROM `" . $a_table_name .
"`");
222 "REPLACE INTO abstraction_progress (table_name, step)" .
" VALUES (?,?)",
250 $fields = $this->analyzer->getFieldInformation($a_table);
252 foreach ($fields as $field => $def) {
253 if ($def[
"type"] ==
"text"
254 && ($def[
"length"] >= 1 && $def[
"length"] <= 4000)
256 $upfields[] = $field;
259 foreach ($upfields as $uf) {
260 $ilDB->query(
"UPDATE `" . $a_table .
"` SET `" . $uf .
"` = null WHERE `" . $uf .
"` = ''");
281 $fields = $this->analyzer->getFieldInformation($a_table);
283 foreach ($fields as $field => $def) {
284 if ($def[
"type"] ==
"timestamp") {
285 $upfields[] = $field;
288 foreach ($upfields as $uf) {
289 $ilDB->query(
"UPDATE `" . $a_table .
"` SET `" . $uf .
"` = null WHERE `" . $uf .
"` = '0000-00-00 00:00:00'");
294 foreach ($fields as $field => $def) {
295 if ($def[
"type"] ==
"date") {
296 $upfields[] = $field;
299 foreach ($upfields as $uf) {
300 $ilDB->query(
"UPDATE `" . $a_table .
"` SET `" . $uf .
"` = null WHERE `" . $uf .
"` = '0000-00-00'");
315 if ($a_table_name != strtolower($a_table_name)) {
318 mysql_query(
"ALTER TABLE `" . $a_table_name .
"` RENAME `" . strtolower($a_table_name) .
"xxx" .
"`");
319 mysql_query(
"ALTER TABLE `" . strtolower($a_table_name) .
"xxx" .
"` RENAME `" . strtolower($a_table_name) .
"`");
334 $result = mysql_query(
"SHOW COLUMNS FROM `" . $a_table_name .
"`");
335 while ($row = mysql_fetch_assoc(
$result)) {
336 if ($row[
"Field"] != strtolower($row[
"Field"])) {
337 $ilDB->renameTableColumn($a_table_name, $row[
"Field"], strtolower($row[
"Field"]));
351 if ($a_auto_inc_field !=
"") {
365 if ($a_pk[
"name"] !=
"") {
366 $this->
ilDBInterface->dropPrimaryKey($a_table, $a_pk[
"name"]);
379 if (is_array($a_indices)) {
380 foreach ($a_indices as
$index) {
395 if (is_array($a_constraints)) {
396 foreach ($a_constraints as
$c) {
397 if (
$c[
"type"] ==
"unique") {
414 public function alterTable($a_table, $a_fields, $a_set_text_ts_fields_notnull_false =
true, $pk =
"")
417 foreach ($a_fields as $field =>
$d) {
418 $def = $this->reverse->getTableFieldDefinition($a_table, $field);
420 $best_alt = $this->analyzer->getBestDefinitionAlternative($def);
421 $def = $def[$best_alt];
424 if (strtolower($def[
"nativetype"]) ==
"timestamp"
425 && strtolower($def[
"default"]) ==
"current_timestamp"
427 unset($def[
"default"]);
430 if (strtolower($def[
"type"]) ==
"float") {
431 unset($def[
"length"]);
435 foreach ($def as $k => $v) {
453 if ($def[
"type"] ==
"decimal") {
454 $l_arr = explode(
",", $def[
"length"]);
455 $def[
"length"] = $l_arr[0];
459 if ($def[
"type"] ==
"float") {
460 unset($def[
"length"]);
464 if ($a_set_text_ts_fields_notnull_false
465 && ($def[
"type"] ==
"text"
466 || $def[
"type"] ==
"timestamp"
467 || $def[
"type"] ==
"date")
468 && (!is_array($pk) || !isset($field, $pk[
"fields"][$field]))
470 $def[
"notnull"] =
false;
474 if ($def[
"type"] ==
"integer") {
475 $def[
"unsigned"] =
false;
479 if ($def[
"type"] ==
"blob" || $def[
"type"] ==
"clob") {
480 $def[
"notnull"] =
false;
484 if (($def[
"type"] ==
"timestamp" && $def[
"default"] ==
"0000-00-00 00:00:00")
485 || ($def[
"type"] ==
"date" && $def[
"default"] ==
"0000-00-00")
487 unset($def[
"default"]);
491 foreach ($def as $k => $v) {
494 $def[
"definition"] =
$a;
496 $n_fields[$field] = $def;
500 "change" => $n_fields,
504 $r = $this->manager->alterTable($a_table, $changes,
false);
506 $r = $this->manager->createTable(strtolower($a_table) .
"_copy", $n_fields);
519 if (is_array($a_pk[
"fields"])) {
521 foreach ($a_pk[
"fields"] as
$f => $pos) {
522 $fields[] = strtolower(
$f);
537 if (is_array($a_indices)) {
540 foreach ($a_indices as
$index) {
541 if (strlen(
$index[
"name"]) > 3) {
547 foreach ($a_indices as
$index) {
548 if (is_array(
$index[
"fields"])) {
550 $index[
"name"] =
"i" . $cnt;
553 foreach (
$index[
"fields"] as
$f => $pos) {
554 $fields[] = strtolower(
$f);
572 if (is_array($a_constraints)) {
575 foreach ($a_constraints as
$c) {
576 if (strlen(
$c[
"name"]) > 3) {
582 foreach ($a_constraints as
$c) {
583 if (is_array(
$c[
"fields"])) {
585 $c[
"name"] =
"c" . $cnt;
588 foreach (
$c[
"fields"] as
$f => $pos) {
589 $fields[] = strtolower(
$f);
591 $this->
ilDBInterface->addUniqueConstraint($a_table, $fields, strtolower(
$c[
"name"]));
609 $indices = $this->analyzer->getIndicesInformation($a_table);
610 foreach ($indices as
$index) {
611 if (strlen(
$index[
"name"]) > 3) {
617 foreach ($indices as
$index) {
633 if ($a_auto_inc_field !=
"") {
634 $set = $this->
ilDBInterface->
query(
"SELECT MAX(`" . strtolower($a_auto_inc_field) .
"`) ma FROM `" . $a_table .
"`");
636 $next = $rec[
"ma"] + 1;
652 $fields = $this->analyzer->getFieldInformation($a_table);
653 foreach ($fields as
$name => $def) {
654 if ($def[
"type"] ==
"clob" && $def[
"notnull"] ==
true) {
678 $fields = $this->analyzer->getFieldInformation($a_table);
679 foreach ($fields as
$name => $def) {
680 if ($def[
"type"] ==
"timestamp"
681 && ($def[
"notnull"] ==
true || $def[
"default"] ==
"0000-00-00 00:00:00")
684 "type" =>
"timestamp",
687 if ($def[
"default"] ==
"0000-00-00 00:00:00") {
688 $nd[
"default"] =
null;
692 if ($def[
"type"] ==
"date"
693 && ($def[
"notnull"] ==
true || $def[
"default"] ==
"0000-00-00")
699 if ($def[
"default"] ==
"0000-00-00") {
700 $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)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
foreach($_POST as $key=> $value) $res