ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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  $this->analyzer = new ilDBAnalyzer();
49  $this->setTestMode(false);
50  }
global $DIC
Definition: goto.php:24
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 631 of file class.ilMySQLAbstraction.php.

Referenced by performAbstraction().

632  {
633  if ($a_auto_inc_field != "") {
634  $set = $this->ilDBInterface->query("SELECT MAX(`" . strtolower($a_auto_inc_field) . "`) ma FROM `" . $a_table . "`");
635  $rec = $this->ilDBInterface->fetchAssoc($set);
636  $next = $rec["ma"] + 1;
637  $this->ilDBInterface->createSequence($a_table, $next);
638  }
639  }
+ 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 570 of file class.ilMySQLAbstraction.php.

References $c, and Vendor\Package\$f.

Referenced by performAbstraction().

571  {
572  if (is_array($a_constraints)) {
573  $all_valid = true;
574 
575  foreach ($a_constraints as $c) {
576  if (strlen($c["name"]) > 3) {
577  $all_valid = false;
578  }
579  }
580 
581  $cnt = 1;
582  foreach ($a_constraints as $c) {
583  if (is_array($c["fields"])) {
584  if (!$all_valid) {
585  $c["name"] = "c" . $cnt;
586  }
587  $fields = array();
588  foreach ($c["fields"] as $f => $pos) {
589  $fields[] = strtolower($f);
590  }
591  $this->ilDBInterface->addUniqueConstraint($a_table, $fields, strtolower($c["name"]));
592  $cnt++;
593  }
594  }
595  }
596  }
$c
Definition: cli.php:37
+ 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 535 of file class.ilMySQLAbstraction.php.

References Vendor\Package\$f, and $index.

Referenced by fixIndexNames(), and performAbstraction().

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

◆ addPrimaryKey()

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

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

References Vendor\Package\$f.

Referenced by performAbstraction().

518  {
519  if (is_array($a_pk["fields"])) {
520  $fields = array();
521  foreach ($a_pk["fields"] as $f => $pos) {
522  $fields[] = strtolower($f);
523  }
524  $this->ilDBInterface->addPrimaryKey($a_table, $fields);
525  }
526  }
+ 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 414 of file class.ilMySQLAbstraction.php.

References Vendor\Package\$a, $d, and getTestMode().

Referenced by performAbstraction().

415  {
416  $n_fields = array();
417  foreach ($a_fields as $field => $d) {
418  $def = $this->reverse->getTableFieldDefinition($a_table, $field);
419  $this->ilDBInterface->handleError($def);
420  $best_alt = $this->analyzer->getBestDefinitionAlternative($def);
421  $def = $def[$best_alt];
422 
423  // remove "current_timestamp" default for timestamps (not supported)
424  if (strtolower($def["nativetype"]) == "timestamp"
425  && strtolower($def["default"]) == "current_timestamp"
426  ) {
427  unset($def["default"]);
428  }
429 
430  if (strtolower($def["type"]) == "float") {
431  unset($def["length"]);
432  }
433 
434  // remove all invalid attributes
435  foreach ($def as $k => $v) {
436  if (!in_array(
437  $k,
438  array(
439  "type",
440  "default",
441  "notnull",
442  "length",
443  "unsigned",
444  "fixed",
445  )
446  )
447  ) {
448  unset($def[$k]);
449  }
450  }
451 
452  // determine length for decimal type
453  if ($def["type"] == "decimal") {
454  $l_arr = explode(",", $def["length"]);
455  $def["length"] = $l_arr[0];
456  }
457 
458  // remove length values for float
459  if ($def["type"] == "float") {
460  unset($def["length"]);
461  }
462 
463  // set notnull to false for text/timestamp/date fields
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]))
469  ) {
470  $def["notnull"] = false;
471  }
472 
473  // set unsigned to false for integers
474  if ($def["type"] == "integer") {
475  $def["unsigned"] = false;
476  }
477 
478  // set notnull to false for blob and clob
479  if ($def["type"] == "blob" || $def["type"] == "clob") {
480  $def["notnull"] = false;
481  }
482 
483  // remove "0000-00-00..." default values
484  if (($def["type"] == "timestamp" && $def["default"] == "0000-00-00 00:00:00")
485  || ($def["type"] == "date" && $def["default"] == "0000-00-00")
486  ) {
487  unset($def["default"]);
488  }
489 
490  $a = array();
491  foreach ($def as $k => $v) {
492  $a[$k] = $v;
493  }
494  $def["definition"] = $a;
495 
496  $n_fields[$field] = $def;
497  }
498 
499  $changes = array(
500  "change" => $n_fields,
501  );
502 
503  if (!$this->getTestMode()) {
504  $r = $this->manager->alterTable($a_table, $changes, false);
505  } else {
506  $r = $this->manager->createTable(strtolower($a_table) . "_copy", $n_fields);
507  }
508 
509  return true;
510  }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
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 200 of file class.ilMySQLAbstraction.php.

References $DIC, $ilDB, and $res.

Referenced by performAbstraction().

201  {
202  global $DIC;
203  $ilDB = $DIC->database();
204 
205  $st = $ilDB->prepare("SELECT count(*) AS cnt FROM `" . $a_table_name . "`");
206  $res = $ilDB->execute($st);
207  $rec = $ilDB->fetchAssoc($res);
208 
209  return $rec["cnt"];
210  }
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
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 646 of file class.ilMySQLAbstraction.php.

References $name.

647  {
648  if (!$this->ilDBInterface->tableExists($a_table)) {
649  return;
650  }
651  $all_valid = true;
652  $fields = $this->analyzer->getFieldInformation($a_table);
653  foreach ($fields as $name => $def) {
654  if ($def["type"] == "clob" && $def["notnull"] == true) {
655  $this->ilDBInterface->modifyTableColumn(
656  $a_table,
657  $name,
658  array(
659  "type" => "clob",
660  "notnull" => false,
661  )
662  );
663  }
664  }
665  }
if($format !==null) $name
Definition: metadata.php:230

◆ fixDatetimeValues()

ilMySQLAbstraction::fixDatetimeValues (   $a_table)

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

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

References $name, and $nd.

673  {
674  if (!$this->ilDBInterface->tableExists($a_table)) {
675  return;
676  }
677  $all_valid = 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")
682  ) {
683  $nd = array(
684  "type" => "timestamp",
685  "notnull" => false,
686  );
687  if ($def["default"] == "0000-00-00 00:00:00") {
688  $nd["default"] = null;
689  }
690  $this->ilDBInterface->modifyTableColumn($a_table, $name, $nd);
691  }
692  if ($def["type"] == "date"
693  && ($def["notnull"] == true || $def["default"] == "0000-00-00")
694  ) {
695  $nd = array(
696  "type" => "date",
697  "notnull" => false,
698  );
699  if ($def["default"] == "0000-00-00") {
700  $nd["default"] = null;
701  }
702  $this->ilDBInterface->modifyTableColumn($a_table, $name, $nd);
703  }
704  }
705  }
if($format !==null) $name
Definition: metadata.php:230
$nd
Definition: error.php:12

◆ fixIndexNames()

ilMySQLAbstraction::fixIndexNames (   $a_table)

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

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

References $index, and addIndices().

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

◆ getTestMode()

ilMySQLAbstraction::getTestMode ( )
Returns
bool

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

References $testmode.

Referenced by alterTable(), and performAbstraction().

66  {
67  return $this->testmode;
68  }
+ 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 329 of file class.ilMySQLAbstraction.php.

References $DIC, $ilDB, and $result.

Referenced by performAbstraction().

330  {
331  global $DIC;
332  $ilDB = $DIC->database();
333 
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"]));
338  }
339  }
340  }
$result
global $DIC
Definition: goto.php:24
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 310 of file class.ilMySQLAbstraction.php.

References $DIC, and $ilDB.

Referenced by performAbstraction().

311  {
312  global $DIC;
313  $ilDB = $DIC->database();
314 
315  if ($a_table_name != strtolower($a_table_name)) {
316  // this may look strange, but it does not work directly
317  // (seems that mysql does not see no difference whether upper or lowercase characters are used
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) . "`");
320  }
321  }
global $DIC
Definition: goto.php:24
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 82 of file class.ilMySQLAbstraction.php.

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

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

Referenced by performAbstraction().

350  {
351  if ($a_auto_inc_field != "") {
352  $this->ilDBInterface->modifyTableColumn($a_table_name, $a_auto_inc_field, array());
353  }
354  }
+ 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 393 of file class.ilMySQLAbstraction.php.

References $c.

Referenced by performAbstraction().

394  {
395  if (is_array($a_constraints)) {
396  foreach ($a_constraints as $c) {
397  if ($c["type"] == "unique") {
398  $this->ilDBInterface->query("ALTER TABLE `" . $a_table . "` DROP INDEX `" . $c["name"] . "`");
399  }
400  }
401  }
402  }
$c
Definition: cli.php:37
+ 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 377 of file class.ilMySQLAbstraction.php.

References $index.

Referenced by performAbstraction().

378  {
379  if (is_array($a_indices)) {
380  foreach ($a_indices as $index) {
381  $this->ilDBInterface->query("ALTER TABLE `" . $a_table . "` DROP INDEX `" . $index["name"] . "`");
382  }
383  }
384  }
$index
Definition: metadata.php:128
+ 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 363 of file class.ilMySQLAbstraction.php.

Referenced by performAbstraction().

364  {
365  if ($a_pk["name"] != "") {
366  $this->ilDBInterface->dropPrimaryKey($a_table, $a_pk["name"]);
367  }
368  }
+ 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 272 of file class.ilMySQLAbstraction.php.

References $DIC, and $ilDB.

Referenced by performAbstraction().

273  {
274  global $DIC;
275  $ilDB = $DIC->database();
276 
277  if (!$this->ilDBInterface->tableExists($a_table)) {
278  return;
279  }
280 
281  $fields = $this->analyzer->getFieldInformation($a_table);
282  $upfields = array();
283  foreach ($fields as $field => $def) {
284  if ($def["type"] == "timestamp") {
285  $upfields[] = $field;
286  }
287  }
288  foreach ($upfields as $uf) {
289  $ilDB->query("UPDATE `" . $a_table . "` SET `" . $uf . "` = null WHERE `" . $uf . "` = '0000-00-00 00:00:00'");
290  }
291 
292  $upfields = array();
293  reset($fields);
294  foreach ($fields as $field => $def) {
295  if ($def["type"] == "date") {
296  $upfields[] = $field;
297  }
298  }
299  foreach ($upfields as $uf) {
300  $ilDB->query("UPDATE `" . $a_table . "` SET `" . $uf . "` = null WHERE `" . $uf . "` = '0000-00-00'");
301  }
302  }
global $DIC
Definition: goto.php:24
global $ilDB
+ 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 245 of file class.ilMySQLAbstraction.php.

References $DIC, and $ilDB.

Referenced by performAbstraction().

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

◆ setTestMode()

ilMySQLAbstraction::setTestMode (   $a_testmode)
Parameters
$a_testmode

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

Referenced by __construct().

57  {
58  $this->testmode = $a_testmode;
59  }
+ 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 219 of file class.ilMySQLAbstraction.php.

Referenced by performAbstraction().

220  {
221  $st = $this->ilDBInterface->prepareManip(
222  "REPLACE INTO abstraction_progress (table_name, step)" . " VALUES (?,?)",
223  array(
224  "text",
225  "integer",
226  )
227  );
228  $this->ilDBInterface->execute(
229  $st,
230  array(
231  $a_table,
232  $a_step,
233  )
234  );
235  }
+ 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: