ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilMySQLAbstraction Class Reference

This class includes methods that help to abstract ILIAS 3.10.x MySQL tables for the use with MDB2 abstraction layer and full compliance mode support. More...

+ Collaboration diagram for ilMySQLAbstraction:

Public Member Functions

 __construct ()
 Constructor. More...
 
 setTestMode ($a_testmode)
 
 getTestMode ()
 
 performAbstraction ($a_table_name, $a_set_text_ts_fields_notnull_false=true)
 Converts an existing (MySQL) ILIAS table in an abstract table. More...
 
 countRecords ($a_table_name)
 Check number of records before and after. More...
 
 storeStep ($a_table, $a_step)
 Store performed step. More...
 
 replaceEmptyStringsWithNull ($a_table)
 Replace empty strings with null values. More...
 
 replaceEmptyDatesWithNull ($a_table)
 Replace empty dates with null. More...
 
 lowerCaseTableName ($a_table_name)
 Lower case table and field names. More...
 
 lowerCaseColumnNames ($a_table_name)
 lower case column names More...
 
 removeAutoIncrement ($a_table_name, $a_auto_inc_field)
 Remove auto_increment attribute of a field. More...
 
 removePrimaryKey ($a_table, $a_pk)
 Remove primary key from table. More...
 
 removeIndices ($a_table, $a_indices)
 Remove Indices. More...
 
 removeConstraints ($a_table, $a_constraints)
 Remove Constraints. More...
 
 alterTable ($a_table, $a_fields, $a_set_text_ts_fields_notnull_false=true, $pk="")
 
 addPrimaryKey ($a_table, $a_pk)
 
 addIndices ($a_table, $a_indices)
 Add indices. More...
 
 addConstraints ($a_table, $a_constraints)
 Add constraints. More...
 
 fixIndexNames ($a_table)
 This is only used on tables that have already been abstracted but missed the "full treatment". More...
 
 addAutoIncrementSequence ($a_table, $a_auto_inc_field)
 Add autoincrement sequence. More...
 
 fixClobNotNull ($a_table)
 This is only used on tables that have already been abstracted but missed the "full treatment". More...
 
 fixDatetimeValues ($a_table)
 This is only used on tables that have already been abstracted but missed the "full treatment". More...
 

Data Fields

 $analyzer
 

Protected Attributes

 $ilDBInterface
 
 $manager
 
 $reverse
 
 $testmode
 

Detailed Description

This class includes methods that help to abstract ILIAS 3.10.x MySQL tables for the use with MDB2 abstraction layer and full compliance mode support.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
Id
class.ilDBUpdate.php 18649 2009-01-21 09:59:23Z akill

Definition at line 12 of file class.ilMySQLAbstraction.php.

Constructor & Destructor Documentation

◆ __construct()

ilMySQLAbstraction::__construct ( )

Constructor.

Definition at line 40 of file class.ilMySQLAbstraction.php.

References $DIC, $ilDB, ilDBConstants\MODULE_MANAGER, ilDBConstants\MODULE_REVERSE, and setTestMode().

41  {
42  global $DIC;
43  $ilDB = $DIC->database();
44 
45  $this->ilDBInterface = $ilDB;
46  $this->manager = $ilDB->loadModule(ilDBConstants::MODULE_MANAGER);
47  $this->reverse = $ilDB->loadModule(ilDBConstants::MODULE_REVERSE);
48  if (@is_file('../Services/Database/classes/class.ilDBAnalyzer.php')) {
49  include_once '../Services/Database/classes/class.ilDBAnalyzer.php';
50  } else {
51  include_once './Services/Database/classes/class.ilDBAnalyzer.php';
52  }
53  $this->analyzer = new ilDBAnalyzer();
54  $this->setTestMode(false);
55  }
global $DIC
Definition: saml.php:7
global $ilDB
This class gives all kind of DB information using the database manager and reverse module...
+ Here is the call graph for this function:

Member Function Documentation

◆ addAutoIncrementSequence()

ilMySQLAbstraction::addAutoIncrementSequence (   $a_table,
  $a_auto_inc_field 
)

Add autoincrement sequence.

Parameters
stringtable name
stringautoincrement field

Definition at line 636 of file class.ilMySQLAbstraction.php.

Referenced by performAbstraction().

637  {
638  if ($a_auto_inc_field != "") {
639  $set = $this->ilDBInterface->query("SELECT MAX(`" . strtolower($a_auto_inc_field) . "`) ma FROM `" . $a_table . "`");
640  $rec = $this->ilDBInterface->fetchAssoc($set);
641  $next = $rec["ma"] + 1;
642  $this->ilDBInterface->createSequence($a_table, $next);
643  }
644  }
+ Here is the caller graph for this function:

◆ addConstraints()

ilMySQLAbstraction::addConstraints (   $a_table,
  $a_constraints 
)

Add constraints.

Parameters
stringtable name
arrayconstraints information

Definition at line 575 of file class.ilMySQLAbstraction.php.

References $c, and $f.

Referenced by performAbstraction().

576  {
577  if (is_array($a_constraints)) {
578  $all_valid = true;
579 
580  foreach ($a_constraints as $c) {
581  if (strlen($c["name"]) > 3) {
582  $all_valid = false;
583  }
584  }
585 
586  $cnt = 1;
587  foreach ($a_constraints as $c) {
588  if (is_array($c["fields"])) {
589  if (!$all_valid) {
590  $c["name"] = "c" . $cnt;
591  }
592  $fields = array();
593  foreach ($c["fields"] as $f => $pos) {
594  $fields[] = strtolower($f);
595  }
596  $this->ilDBInterface->addUniqueConstraint($a_table, $fields, strtolower($c["name"]));
597  $cnt++;
598  }
599  }
600  }
601  }
+ Here is the caller graph for this function:

◆ addIndices()

ilMySQLAbstraction::addIndices (   $a_table,
  $a_indices 
)

Add indices.

Parameters
stringtable name
arrayindices information

Definition at line 540 of file class.ilMySQLAbstraction.php.

References $f, and $index.

Referenced by fixIndexNames(), and performAbstraction().

541  {
542  if (is_array($a_indices)) {
543  $all_valid = true;
544 
545  foreach ($a_indices as $index) {
546  if (strlen($index["name"]) > 3) {
547  $all_valid = false;
548  }
549  }
550 
551  $cnt = 1;
552  foreach ($a_indices as $index) {
553  if (is_array($index["fields"])) {
554  if (!$all_valid) {
555  $index["name"] = "i" . $cnt;
556  }
557  $fields = array();
558  foreach ($index["fields"] as $f => $pos) {
559  $fields[] = strtolower($f);
560  }
561  $this->ilDBInterface->addIndex($a_table, $fields, strtolower($index["name"]), $index["fulltext"]);
562  $cnt++;
563  }
564  }
565  }
566  }
$index
Definition: metadata.php:60
+ Here is the caller graph for this function:

◆ addPrimaryKey()

ilMySQLAbstraction::addPrimaryKey (   $a_table,
  $a_pk 
)
Parameters
$a_table
$a_pk

Definition at line 522 of file class.ilMySQLAbstraction.php.

References $f.

Referenced by performAbstraction().

523  {
524  if (is_array($a_pk["fields"])) {
525  $fields = array();
526  foreach ($a_pk["fields"] as $f => $pos) {
527  $fields[] = strtolower($f);
528  }
529  $this->ilDBInterface->addPrimaryKey($a_table, $fields);
530  }
531  }
+ Here is the caller graph for this function:

◆ alterTable()

ilMySQLAbstraction::alterTable (   $a_table,
  $a_fields,
  $a_set_text_ts_fields_notnull_false = true,
  $pk = "" 
)
Parameters
$a_table
$a_fields
bool$a_set_text_ts_fields_notnull_false
string$pk
Returns
mixed
Exceptions

Definition at line 419 of file class.ilMySQLAbstraction.php.

References $d, $def, $r, and getTestMode().

Referenced by performAbstraction().

420  {
421  $n_fields = array();
422  foreach ($a_fields as $field => $d) {
423  $def = $this->reverse->getTableFieldDefinition($a_table, $field);
424  $this->ilDBInterface->handleError($def);
425  $best_alt = $this->analyzer->getBestDefinitionAlternative($def);
426  $def = $def[$best_alt];
427 
428  // remove "current_timestamp" default for timestamps (not supported)
429  if (strtolower($def["nativetype"]) == "timestamp"
430  && strtolower($def["default"]) == "current_timestamp"
431  ) {
432  unset($def["default"]);
433  }
434 
435  if (strtolower($def["type"]) == "float") {
436  unset($def["length"]);
437  }
438 
439  // remove all invalid attributes
440  foreach ($def as $k => $v) {
441  if (!in_array(
442  $k,
443  array(
444  "type",
445  "default",
446  "notnull",
447  "length",
448  "unsigned",
449  "fixed",
450  )
451  )
452  ) {
453  unset($def[$k]);
454  }
455  }
456 
457  // determine length for decimal type
458  if ($def["type"] == "decimal") {
459  $l_arr = explode(",", $def["length"]);
460  $def["length"] = $l_arr[0];
461  }
462 
463  // remove length values for float
464  if ($def["type"] == "float") {
465  unset($def["length"]);
466  }
467 
468  // set notnull to false for text/timestamp/date fields
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]))
474  ) {
475  $def["notnull"] = false;
476  }
477 
478  // set unsigned to false for integers
479  if ($def["type"] == "integer") {
480  $def["unsigned"] = false;
481  }
482 
483  // set notnull to false for blob and clob
484  if ($def["type"] == "blob" || $def["type"] == "clob") {
485  $def["notnull"] = false;
486  }
487 
488  // remove "0000-00-00..." default values
489  if (($def["type"] == "timestamp" && $def["default"] == "0000-00-00 00:00:00")
490  || ($def["type"] == "date" && $def["default"] == "0000-00-00")
491  ) {
492  unset($def["default"]);
493  }
494 
495  $a = array();
496  foreach ($def as $k => $v) {
497  $a[$k] = $v;
498  }
499  $def["definition"] = $a;
500 
501  $n_fields[$field] = $def;
502  }
503 
504  $changes = array(
505  "change" => $n_fields,
506  );
507 
508  if (!$this->getTestMode()) {
509  $r = $this->manager->alterTable($a_table, $changes, false);
510  } else {
511  $r = $this->manager->createTable(strtolower($a_table) . "_copy", $n_fields);
512  }
513 
514  return true;
515  }
$r
Definition: example_031.php:79
$def
Definition: croninfo.php:21
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ countRecords()

ilMySQLAbstraction::countRecords (   $a_table_name)

Check number of records before and after.

Parameters
string$a_table_name
Returns
int

Definition at line 205 of file class.ilMySQLAbstraction.php.

References $DIC, $ilDB, and $res.

Referenced by performAbstraction().

206  {
207  global $DIC;
208  $ilDB = $DIC->database();
209 
210  $st = $ilDB->prepare("SELECT count(*) AS cnt FROM `" . $a_table_name . "`");
211  $res = $ilDB->execute($st);
212  $rec = $ilDB->fetchAssoc($res);
213 
214  return $rec["cnt"];
215  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
+ Here is the caller graph for this function:

◆ fixClobNotNull()

ilMySQLAbstraction::fixClobNotNull (   $a_table)

This is only used on tables that have already been abstracted but missed the "full treatment".

Definition at line 651 of file class.ilMySQLAbstraction.php.

References $def, and $name.

652  {
653  if (!$this->ilDBInterface->tableExists($a_table)) {
654  return;
655  }
656  $all_valid = true;
657  $fields = $this->analyzer->getFieldInformation($a_table);
658  foreach ($fields as $name => $def) {
659  if ($def["type"] == "clob" && $def["notnull"] == true) {
660  $this->ilDBInterface->modifyTableColumn(
661  $a_table,
662  $name,
663  array(
664  "type" => "clob",
665  "notnull" => false,
666  )
667  );
668  }
669  }
670  }
$def
Definition: croninfo.php:21

◆ fixDatetimeValues()

ilMySQLAbstraction::fixDatetimeValues (   $a_table)

This is only used on tables that have already been abstracted but missed the "full treatment".

Definition at line 677 of file class.ilMySQLAbstraction.php.

References $def, $name, and $nd.

678  {
679  if (!$this->ilDBInterface->tableExists($a_table)) {
680  return;
681  }
682  $all_valid = true;
683  $fields = $this->analyzer->getFieldInformation($a_table);
684  foreach ($fields as $name => $def) {
685  if ($def["type"] == "timestamp"
686  && ($def["notnull"] == true || $def["default"] == "0000-00-00 00:00:00")
687  ) {
688  $nd = array(
689  "type" => "timestamp",
690  "notnull" => false,
691  );
692  if ($def["default"] == "0000-00-00 00:00:00") {
693  $nd["default"] = null;
694  }
695  $this->ilDBInterface->modifyTableColumn($a_table, $name, $nd);
696  }
697  if ($def["type"] == "date"
698  && ($def["notnull"] == true || $def["default"] == "0000-00-00")
699  ) {
700  $nd = array(
701  "type" => "date",
702  "notnull" => false,
703  );
704  if ($def["default"] == "0000-00-00") {
705  $nd["default"] = null;
706  }
707  $this->ilDBInterface->modifyTableColumn($a_table, $name, $nd);
708  }
709  }
710  }
$nd
Definition: error.php:10
$def
Definition: croninfo.php:21

◆ fixIndexNames()

ilMySQLAbstraction::fixIndexNames (   $a_table)

This is only used on tables that have already been abstracted but missed the "full treatment".

Definition at line 608 of file class.ilMySQLAbstraction.php.

References $index, and addIndices().

609  {
610  if (!$this->ilDBInterface->tableExists($a_table)) {
611  return;
612  }
613  $all_valid = true;
614  $indices = $this->analyzer->getIndicesInformation($a_table);
615  foreach ($indices as $index) {
616  if (strlen($index["name"]) > 3) {
617  $all_valid = false;
618  }
619  }
620 
621  if (!$all_valid) {
622  foreach ($indices as $index) {
623  $this->ilDBInterface->dropIndex($a_table, $index["name"]);
624  }
625  $this->addIndices($a_table, $indices);
626  }
627  }
$index
Definition: metadata.php:60
addIndices($a_table, $a_indices)
Add indices.
+ Here is the call graph for this function:

◆ getTestMode()

ilMySQLAbstraction::getTestMode ( )
Returns
bool

Definition at line 70 of file class.ilMySQLAbstraction.php.

References $testmode.

Referenced by alterTable(), and performAbstraction().

71  {
72  return $this->testmode;
73  }
+ Here is the caller graph for this function:

◆ lowerCaseColumnNames()

ilMySQLAbstraction::lowerCaseColumnNames (   $a_table_name)

lower case column names

Parameters
string$a_table_name

Definition at line 334 of file class.ilMySQLAbstraction.php.

References $DIC, $ilDB, $result, and $row.

Referenced by performAbstraction().

335  {
336  global $DIC;
337  $ilDB = $DIC->database();
338 
339  $result = mysql_query("SHOW COLUMNS FROM `" . $a_table_name . "`");
340  while ($row = mysql_fetch_assoc($result)) {
341  if ($row["Field"] != strtolower($row["Field"])) {
342  $ilDB->renameTableColumn($a_table_name, $row["Field"], strtolower($row["Field"]));
343  }
344  }
345  }
$result
global $DIC
Definition: saml.php:7
$row
global $ilDB
+ Here is the caller graph for this function:

◆ lowerCaseTableName()

ilMySQLAbstraction::lowerCaseTableName (   $a_table_name)

Lower case table and field names.

Parameters
string$a_table_name

Definition at line 315 of file class.ilMySQLAbstraction.php.

References $DIC, and $ilDB.

Referenced by performAbstraction().

316  {
317  global $DIC;
318  $ilDB = $DIC->database();
319 
320  if ($a_table_name != strtolower($a_table_name)) {
321  // this may look strange, but it does not work directly
322  // (seems that mysql does not see no difference whether upper or lowercase characters are used
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) . "`");
325  }
326  }
global $DIC
Definition: saml.php:7
global $ilDB
+ Here is the caller graph for this function:

◆ performAbstraction()

ilMySQLAbstraction::performAbstraction (   $a_table_name,
  $a_set_text_ts_fields_notnull_false = true 
)

Converts an existing (MySQL) ILIAS table in an abstract table.

This means the table conforms to the MDB2 field types, uses sequences instead of auto_increment.

Parameters
string$a_table_namestring
bool$a_set_text_ts_fields_notnull_false
Exceptions
ilDatabaseException

Definition at line 87 of file class.ilMySQLAbstraction.php.

References addAutoIncrementSequence(), addConstraints(), addIndices(), addPrimaryKey(), alterTable(), countRecords(), getTestMode(), lowerCaseColumnNames(), lowerCaseTableName(), removeAutoIncrement(), removeConstraints(), removeIndices(), removePrimaryKey(), replaceEmptyDatesWithNull(), replaceEmptyStringsWithNull(), and storeStep().

88  {
89  // to do: log this procedure
90 
91  // count number of records at the beginning
92  $nr_rec = $this->countRecords($a_table_name);
93 
94  // convert table name to lowercase
95  if (!$this->getTestMode()) {
96  $this->lowerCaseTableName($a_table_name);
97  $a_table_name = strtolower($a_table_name);
98  $this->storeStep($a_table_name, 10);
99  }
100 
101  // get auto increment information
102  $auto_inc_field = $this->analyzer->getAutoIncrementField($a_table_name);
103 
104  // get primary key information
105  $pk = $this->analyzer->getPrimaryKeyInformation($a_table_name);
106 
107  // get indices information
108  $indices = $this->analyzer->getIndicesInformation($a_table_name);
109 
110  // get constraints information
111  $constraints = $this->analyzer->getConstraintsInformation($a_table_name);
112 
113  // get field information
114  $fields = $this->analyzer->getFieldInformation($a_table_name);
115 
116  if (!$this->getTestMode()) {
117  // remove auto increment
118  $this->removeAutoIncrement($a_table_name, $auto_inc_field, $fields);
119  $this->storeStep($a_table_name, 20);
120 
121  // remove primary key
122  $this->removePrimaryKey($a_table_name, $pk);
123  $this->storeStep($a_table_name, 30);
124 
125  // remove indices
126  $this->removeIndices($a_table_name, $indices);
127  $this->storeStep($a_table_name, 40);
128 
129  // remove constraints
130  $this->removeConstraints($a_table_name, $constraints);
131  $this->storeStep($a_table_name, 45);
132  }
133 
134  // alter table using mdb2 field types
135  $this->alterTable($a_table_name, $fields, $a_set_text_ts_fields_notnull_false, $pk);
136  if ($this->getTestMode()) {
137  $a_table_name = strtolower($a_table_name) . "_copy";
138  } else {
139  $this->storeStep($a_table_name, 50);
140  }
141 
142  // lower case field names
143  $this->lowerCaseColumnNames($a_table_name);
144  if (!$this->getTestMode()) {
145  $this->storeStep($a_table_name, 60);
146  }
147 
148  // add primary key
149  $this->addPrimaryKey($a_table_name, $pk);
150  if (!$this->getTestMode()) {
151  $this->storeStep($a_table_name, 70);
152  }
153 
154  // add indices
155  $this->addIndices($a_table_name, $indices);
156  if (!$this->getTestMode()) {
157  $this->storeStep($a_table_name, 80);
158  }
159 
160  // add constraints
161  $this->addConstraints($a_table_name, $constraints);
162  if (!$this->getTestMode()) {
163  $this->storeStep($a_table_name, 85);
164  }
165 
166  // add "auto increment" sequence
167  if ($auto_inc_field != "") {
168  $this->addAutoIncrementSequence($a_table_name, $auto_inc_field);
169  }
170  if (!$this->getTestMode()) {
171  $this->storeStep($a_table_name, 90);
172  }
173 
174  // replace empty strings with null values in text fields
175  $this->replaceEmptyStringsWithNull($a_table_name);
176  if (!$this->getTestMode()) {
177  $this->storeStep($a_table_name, 100);
178  }
179 
180  // replace empty "0000-00-00..." dates with null
181  $this->replaceEmptyDatesWithNull($a_table_name);
182  if (!$this->getTestMode()) {
183  $this->storeStep($a_table_name, 110);
184  }
185 
186  $nr_rec2 = $this->countRecords($a_table_name);
187 
188  if (!$this->getTestMode()) {
189  if ($nr_rec != $nr_rec2) {
190  throw new ilDatabaseException(
191  "ilMySQLAbstraction: Unexpected difference in table record number, table '" . $a_table_name . "'." . " Before: " . ((int) $nr_rec) . ", After: " . ((int) $nr_rec2) . "."
192  );
193  }
194  }
195  }
lowerCaseColumnNames($a_table_name)
lower case column names
replaceEmptyStringsWithNull($a_table)
Replace empty strings with null values.
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.
addAutoIncrementSequence($a_table, $a_auto_inc_field)
Add autoincrement sequence.
replaceEmptyDatesWithNull($a_table)
Replace empty dates with null.
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.
addIndices($a_table, $a_indices)
Add indices.
removeIndices($a_table, $a_indices)
Remove Indices.
removeConstraints($a_table, $a_constraints)
Remove Constraints.
removePrimaryKey($a_table, $a_pk)
Remove primary key from table.
addConstraints($a_table, $a_constraints)
Add constraints.
+ Here is the call graph for this function:

◆ removeAutoIncrement()

ilMySQLAbstraction::removeAutoIncrement (   $a_table_name,
  $a_auto_inc_field 
)

Remove auto_increment attribute of a field.

Parameters
stringtable name
stringautoincrement field

Definition at line 354 of file class.ilMySQLAbstraction.php.

Referenced by performAbstraction().

355  {
356  if ($a_auto_inc_field != "") {
357  $this->ilDBInterface->modifyTableColumn($a_table_name, $a_auto_inc_field, array());
358  }
359  }
+ Here is the caller graph for this function:

◆ removeConstraints()

ilMySQLAbstraction::removeConstraints (   $a_table,
  $a_constraints 
)

Remove Constraints.

Parameters
stringtable name
arrayconstraints information

Definition at line 398 of file class.ilMySQLAbstraction.php.

References $c.

Referenced by performAbstraction().

399  {
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"] . "`");
404  }
405  }
406  }
407  }
+ Here is the caller graph for this function:

◆ removeIndices()

ilMySQLAbstraction::removeIndices (   $a_table,
  $a_indices 
)

Remove Indices.

Parameters
stringtable name
arrayindices information

Definition at line 382 of file class.ilMySQLAbstraction.php.

References $index.

Referenced by performAbstraction().

383  {
384  if (is_array($a_indices)) {
385  foreach ($a_indices as $index) {
386  $this->ilDBInterface->query("ALTER TABLE `" . $a_table . "` DROP INDEX `" . $index["name"] . "`");
387  }
388  }
389  }
$index
Definition: metadata.php:60
+ Here is the caller graph for this function:

◆ removePrimaryKey()

ilMySQLAbstraction::removePrimaryKey (   $a_table,
  $a_pk 
)

Remove primary key from table.

Parameters
stringtable name
arrayprimary key information

Definition at line 368 of file class.ilMySQLAbstraction.php.

Referenced by performAbstraction().

369  {
370  if ($a_pk["name"] != "") {
371  $this->ilDBInterface->dropPrimaryKey($a_table, $a_pk["name"]);
372  }
373  }
+ Here is the caller graph for this function:

◆ replaceEmptyDatesWithNull()

ilMySQLAbstraction::replaceEmptyDatesWithNull (   $a_table)

Replace empty dates with null.

Parameters
$a_table
Exceptions

Definition at line 277 of file class.ilMySQLAbstraction.php.

References $def, $DIC, and $ilDB.

Referenced by performAbstraction().

278  {
279  global $DIC;
280  $ilDB = $DIC->database();
281 
282  if (!$this->ilDBInterface->tableExists($a_table)) {
283  return;
284  }
285 
286  $fields = $this->analyzer->getFieldInformation($a_table);
287  $upfields = array();
288  foreach ($fields as $field => $def) {
289  if ($def["type"] == "timestamp") {
290  $upfields[] = $field;
291  }
292  }
293  foreach ($upfields as $uf) {
294  $ilDB->query("UPDATE `" . $a_table . "` SET `" . $uf . "` = null WHERE `" . $uf . "` = '0000-00-00 00:00:00'");
295  }
296 
297  $upfields = array();
298  reset($fields);
299  foreach ($fields as $field => $def) {
300  if ($def["type"] == "date") {
301  $upfields[] = $field;
302  }
303  }
304  foreach ($upfields as $uf) {
305  $ilDB->query("UPDATE `" . $a_table . "` SET `" . $uf . "` = null WHERE `" . $uf . "` = '0000-00-00'");
306  }
307  }
global $DIC
Definition: saml.php:7
global $ilDB
$def
Definition: croninfo.php:21
+ Here is the caller graph for this function:

◆ replaceEmptyStringsWithNull()

ilMySQLAbstraction::replaceEmptyStringsWithNull (   $a_table)

Replace empty strings with null values.

Parameters
$a_table
Exceptions

Definition at line 250 of file class.ilMySQLAbstraction.php.

References $def, $DIC, and $ilDB.

Referenced by performAbstraction().

251  {
252  global $DIC;
253  $ilDB = $DIC->database();
254 
255  $fields = $this->analyzer->getFieldInformation($a_table);
256  $upfields = array();
257  foreach ($fields as $field => $def) {
258  if ($def["type"] == "text"
259  && ($def["length"] >= 1 && $def["length"] <= 4000)
260  ) {
261  $upfields[] = $field;
262  }
263  }
264  foreach ($upfields as $uf) {
265  $ilDB->query("UPDATE `" . $a_table . "` SET `" . $uf . "` = null WHERE `" . $uf . "` = ''");
266  }
267  }
global $DIC
Definition: saml.php:7
global $ilDB
$def
Definition: croninfo.php:21
+ Here is the caller graph for this function:

◆ setTestMode()

ilMySQLAbstraction::setTestMode (   $a_testmode)
Parameters
$a_testmode

Definition at line 61 of file class.ilMySQLAbstraction.php.

Referenced by __construct().

62  {
63  $this->testmode = $a_testmode;
64  }
+ Here is the caller graph for this function:

◆ storeStep()

ilMySQLAbstraction::storeStep (   $a_table,
  $a_step 
)

Store performed step.

Parameters
$a_table
$a_step

Definition at line 224 of file class.ilMySQLAbstraction.php.

Referenced by performAbstraction().

225  {
226  $st = $this->ilDBInterface->prepareManip(
227  "REPLACE INTO abstraction_progress (table_name, step)" . " VALUES (?,?)",
228  array(
229  "text",
230  "integer",
231  )
232  );
233  $this->ilDBInterface->execute(
234  $st,
235  array(
236  $a_table,
237  $a_step,
238  )
239  );
240  }
+ Here is the caller graph for this function:

Field Documentation

◆ $analyzer

ilMySQLAbstraction::$analyzer

Definition at line 18 of file class.ilMySQLAbstraction.php.

◆ $ilDBInterface

ilMySQLAbstraction::$ilDBInterface
protected

Definition at line 22 of file class.ilMySQLAbstraction.php.

◆ $manager

ilMySQLAbstraction::$manager
protected

Definition at line 26 of file class.ilMySQLAbstraction.php.

◆ $reverse

ilMySQLAbstraction::$reverse
protected

Definition at line 30 of file class.ilMySQLAbstraction.php.

◆ $testmode

ilMySQLAbstraction::$testmode
protected

Definition at line 34 of file class.ilMySQLAbstraction.php.

Referenced by getTestMode().


The documentation for this class was generated from the following file: