ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilDBPdoMySQL.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 require_once('./Services/Database/classes/PDO/FieldDefinition/class.ilDBPdoMySQLFieldDefinition.php');
4 require_once('class.ilDBPdo.php');
5 
11 abstract class ilDBPdoMySQL extends ilDBPdo implements ilDBInterface {
12 
16  public function supportsTransactions() {
17  return false;
18  }
19 
20 
21  public function initHelpers() {
22  $this->manager = new ilDBPdoManager($this->pdo, $this);
23  $this->reverse = new ilDBPdoReverse($this->pdo, $this);
24  $this->field_definition = new ilDBPdoMySQLFieldDefinition($this);
25  }
26 
27 
28  protected function initSQLMode() {
29  $this->pdo->query("SET SESSION sql_mode = 'IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';");
30  }
31 
32 
36  public function supportsEngineMigration() {
37  return true;
38  }
39 
40 
44  protected function getAdditionalAttributes() {
45  return array(
46  PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
47  PDO::ATTR_TIMEOUT => 300 * 60,
48  );
49  }
50 
51 
57  $engines = $this->queryCol('SHOW ENGINES');
58  if (!in_array($engine, $engines)) {
59  return array();
60  }
61 
62  $errors = array();
63  foreach ($this->listTables() as $table) {
64  try {
65  $this->pdo->exec("ALTER TABLE {$table} ENGINE={$engine}");
66  } catch (Exception $e) {
67  $errors[$table] = $e->getMessage();
68  }
69  }
70 
71  return $errors;
72  }
73 
74 
79  public function nextId($table_name) {
80  $sequence_name = $this->quoteIdentifier($this->getSequenceName($table_name), true);
81  $seqcol_name = 'sequence';
82  $query = "INSERT INTO $sequence_name ($seqcol_name) VALUES (NULL)";
83  try {
84  $this->pdo->exec($query);
85  } catch (PDOException $e) {
86  // no such table check
87  }
88 
89  $result = $this->query('SELECT LAST_INSERT_ID() AS next');
90  $value = $result->fetchObject()->next;
91 
92  if (is_numeric($value)) {
93  $query = "DELETE FROM $sequence_name WHERE $seqcol_name < $value";
94  $this->pdo->exec($query);
95  }
96 
97  return $value;
98  }
99 
100 
105  {
106  // Currently ILIAS does not support utf8mb4, after that ilDB could check like this:
107  // static $supported;
108  // if (!isset($supported)) {
109  // $q = "SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = %s;";
110  // $res = $this->queryF($q, ['text'], [$this->getDbname()]);
111  // $data = $this->fetchObject($res);
112  // $supported = ($data->default_character_set_name === 'utf8mb4');
113  // }
114 
115  return false;
116  }
117 }
118 
getSequenceName($table_name)
$result
migrateAllTablesToEngine($engine=ilDBConstants::MYSQL_ENGINE_INNODB)
$engine
Definition: workflow.php:90
Class ilDBPdoMySQL.
queryCol($query, $type=PDO::FETCH_ASSOC, $colnum=0)
Class pdoDB.
Interface ilDBInterface.
quoteIdentifier($identifier, $check_option=false)
query($query)
Create styles array
The data for the language used.
Class ilDBPdoMySQLFieldDefinition.
$errors
Class ilDBPdoReverse.
Class ilDBPdoManager.
nextId($table_name)