ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilDBPdoReverse Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilDBPdoReverse:
+ Collaboration diagram for ilDBPdoReverse:

Public Member Functions

 __construct (\PDO $pdo, ilDBPdo $db_instance)
 ilDBPdoReverse constructor. More...
 
 getQueryUtils ()
 
 getTableFieldDefinition ($table_name, $field_name)
 
 getTableIndexDefinition ($table, $index_name)
 
 getTableConstraintDefinition ($table, $constraint_name)
 
 getTriggerDefinition ($trigger)
 

Protected Attributes

 $pdo
 
 $db_instance
 
 $query_utils
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilDBPdoReverse

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 24 of file class.ilDBPdoReverse.php.

Constructor & Destructor Documentation

◆ __construct()

ilDBPdoReverse::__construct ( \PDO  $pdo,
ilDBPdo  $db_instance 
)

ilDBPdoReverse constructor.

Parameters
\PDO$pdo
\ilDBPdo$db_instance

Definition at line 43 of file class.ilDBPdoReverse.php.

References $db_instance, and $pdo.

44  {
45  $this->pdo = $pdo;
46  $this->db_instance = $db_instance;
47  }

Member Function Documentation

◆ getQueryUtils()

ilDBPdoReverse::getQueryUtils ( )
Returns

Definition at line 58 of file class.ilDBPdoReverse.php.

References $query_utils.

59  {
60  if (!$this->query_utils) {
61  $this->query_utils = new ilMySQLQueryUtils($this->db_instance);
62  }
63 
64  return $this->query_utils;
65  }
Class ilMySQLQueryUtils.

◆ getTableConstraintDefinition()

ilDBPdoReverse::getTableConstraintDefinition (   $table,
  $constraint_name 
)
Parameters
$table
$constraint_name
Returns
array
Exceptions

Implements ilDBReverse.

Definition at line 211 of file class.ilDBPdoReverse.php.

References $data, $query, and $result.

212  {
213  $constraint_name = strtolower($constraint_name);
214  $table = $this->db_instance->quoteIdentifier($table, true);
215  $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */";
216 
217  if (strtolower($constraint_name) != 'primary') {
218  $constraint_name_pdo = $this->db_instance->getIndexName($constraint_name);
219  $result = $this->db_instance->query(sprintf($query, $this->db_instance->quote($constraint_name_pdo)));
220  $data = $this->db_instance->fetchAssoc($result);
221  if ($data) {
222  // apply 'idxname_format' only if the query succeeded, otherwise
223  // fallback to the given $index_name, without transformation
224  $constraint_name = strtolower($constraint_name_pdo);
225  }
226  }
227 
228  $result = $this->db_instance->query(sprintf($query, $this->db_instance->quote($constraint_name)));
229 
230  $colpos = 1;
231  $definition = array();
232  while (is_object($row = $result->fetchObject())) {
233  $row = (array) $row;
234  $row = array_change_key_case($row, CASE_LOWER);
235  $key_name = $row['key_name'];
236  if ($this->db_instance->options['portability'] ?? false) {
237  if (($this->db_instance->options['field_case'] ?? null) == CASE_LOWER) {
238  $key_name = strtolower($key_name);
239  } else {
240  $key_name = strtolower($key_name);
241  }
242  }
243  $key_name = strtolower($key_name); // FSX fix
244  if ($constraint_name == $key_name) {
245  if ($row['non_unique']) {
246  throw new ilDatabaseException(' is not an existing table constraint');
247  }
248  if (($row['key_name'] ?? '') === 'PRIMARY') {
249  $definition['primary'] = true;
250  } else {
251  $definition['unique'] = true;
252  }
253  $column_name = $row['column_name'];
254  if ($this->db_instance->options['portability'] ?? false) {
255  if (($this->db_instance->options['field_case'] ?? null) == CASE_LOWER) {
256  $column_name = strtolower($column_name);
257  } else {
258  $column_name = strtoupper($column_name);
259  }
260  }
261  $definition['fields'][$column_name] = array(
262  'position' => $colpos++,
263  );
264  if (!empty($row['collation'])) {
265  $definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'A' ? 'ascending' : 'descending');
266  }
267  }
268  }
269 
270  if (empty($definition['fields'])) {
271  throw new ilDatabaseException(' is not an existing table constraint');
272  }
273 
274  return $definition;
275  }
$data
Definition: storeScorm.php:23
$result
Class ilDatabaseException.
$query

◆ getTableFieldDefinition()

ilDBPdoReverse::getTableFieldDefinition (   $table_name,
  $field_name 
)
Parameters
$table_name
$field_name
Returns
array

Implements ilDBReverse.

Definition at line 72 of file class.ilDBPdoReverse.php.

References $columns, $data, $query, $res, and $type.

73  {
74  $return = array();
75 
76  $table = $this->db_instance->quoteIdentifier($table_name);
77  $query = "SHOW COLUMNS FROM $table LIKE " . $this->db_instance->quote($field_name);
78  $res = $this->pdo->query($query);
79  $columns = array();
80  while ($data = $res->fetch(PDO::FETCH_ASSOC)) {
81  $columns[] = $data;
82  }
83 
84  $ilDBPdoFieldDefinition = $this->db_instance->getFieldDefinition();
85 
86  foreach ($columns as $column) {
87  $column = array_change_key_case($column, CASE_LOWER);
88  $column['name'] = $column['field'];
89  unset($column['field']);
90  // if ($this->db_instance->options['portability']) {
91  // if ($this->db_instance->options['field_case'] == CASE_LOWER) {
92  // $column['name'] = strtolower($column['name']);
93  // } else {
94  // $column['name'] = strtoupper($column['name']);
95  // }
96  // } else {
97  $column = array_change_key_case($column, CASE_LOWER);
98  // }
99  if ($field_name == $column['name']) {
100  $mapped_datatype = $ilDBPdoFieldDefinition->mapNativeDatatype($column);
101 
102  list($types, $length, $unsigned, $fixed) = $mapped_datatype;
103  $notnull = false;
104  if (empty($column['null']) || $column['null'] !== 'YES') {
105  $notnull = true;
106  }
107  $default = false;
108  if (array_key_exists('default', $column)) {
109  $default = $column['default'];
110  if (is_null($default) && $notnull) {
111  $default = '';
112  }
113  }
114  $autoincrement = false;
115  if (!empty($column['extra']) && $column['extra'] == 'auto_increment') {
116  $autoincrement = true;
117  }
118 
119  $definition[0] = array(
120  'notnull' => $notnull,
121  'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type']),
122  );
123  if (!is_null($length)) {
124  $definition[0]['length'] = $length;
125  }
126  if (!is_null($unsigned)) {
127  $definition[0]['unsigned'] = $unsigned;
128  }
129  if (!is_null($fixed)) {
130  $definition[0]['fixed'] = $fixed;
131  }
132  if ($default !== false) {
133  $definition[0]['default'] = $default;
134  }
135  if ($autoincrement !== false) {
136  $definition[0]['autoincrement'] = $autoincrement;
137  }
138  foreach ($types as $key => $type) {
139  $definition[$key] = $definition[0];
140  if ($type == 'clob' || $type == 'blob') {
141  unset($definition[$key]['default']);
142  }
143  $definition[$key]['type'] = $type;
144  $definition[$key]['mdb2type'] = $type;
145  }
146 
147  return $definition;
148  }
149  }
150 
151  throw new ilDatabaseException('it was not specified an existing table column');
152  }
$data
Definition: storeScorm.php:23
$type
Class ilDatabaseException.
foreach($_POST as $key=> $value) $res
$query
if(! $in) $columns
Definition: Utf8Test.php:45

◆ getTableIndexDefinition()

ilDBPdoReverse::getTableIndexDefinition (   $table,
  $index_name 
)
Parameters
$table
$index_name
Returns
array
Exceptions

Implements ilDBReverse.

Definition at line 161 of file class.ilDBPdoReverse.php.

References $data, $query, and $result.

162  {
163  $table = $this->db_instance->quoteIdentifier($table, true);
164  $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */";
165  $index_name_pdo = $this->db_instance->getIndexName($index_name);
166  $result = $this->db_instance->query(sprintf($query, $this->db_instance->quote($index_name_pdo)));
167  $data = $this->db_instance->fetchAssoc($result);
168 
169  if ($data) {
170  $index_name = $index_name_pdo;
171  }
172 
173  $result = $this->db_instance->query(sprintf($query, $this->db_instance->quote($index_name)));
174 
175  $colpos = 1;
176  $definition = array();
177  while (is_object($row = $result->fetchObject())) {
178  $row = array_change_key_case((array) $row, CASE_LOWER);
179 
180  $key_name = $row['key_name'];
181 
182 
183  if ($index_name == $key_name) {
184  if (!$row['non_unique']) {
185  throw new ilDatabaseException('it was not specified an existing table index');
186  }
187  $column_name = $row['column_name'];
188  $definition['fields'][$column_name] = array(
189  'position' => $colpos++,
190  );
191  if (!empty($row['collation'])) {
192  $definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'A' ? 'ascending' : 'descending');
193  }
194  }
195  }
196 
197  if (empty($definition['fields'])) {
198  throw new ilDatabaseException('it was not specified an existing table index (index does not exist)');
199  }
200 
201  return $definition;
202  }
$data
Definition: storeScorm.php:23
$result
Class ilDatabaseException.
$query

◆ getTriggerDefinition()

ilDBPdoReverse::getTriggerDefinition (   $trigger)
Parameters
$trigger
Returns
array|void
Exceptions

Implements ilDBReverse.

Definition at line 283 of file class.ilDBPdoReverse.php.

284  {
285  throw new ilDatabaseException('not yet implemented ' . __METHOD__);
286  }
Class ilDatabaseException.

Field Documentation

◆ $db_instance

ilDBPdoReverse::$db_instance
protected

◆ $pdo

ilDBPdoReverse::$pdo
protected

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

Referenced by __construct().

◆ $query_utils

ilDBPdoReverse::$query_utils
protected

Definition at line 52 of file class.ilDBPdoReverse.php.

Referenced by getQueryUtils().


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