ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilDBPdoReverse Class Reference

Class ilDBPdoReverse. 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)
 
 tableInfo ($result, $mode=null)
 

Protected Attributes

 $pdo
 
 $db_instance
 
 $query_utils
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

ilDBPdoReverse constructor.

Parameters
\PDO$pdo
\ilDBPdo$db_instance

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

References $db_instance, and $pdo.

27  {
28  $this->pdo = $pdo;
29  $this->db_instance = $db_instance;
30  }

Member Function Documentation

◆ getQueryUtils()

ilDBPdoReverse::getQueryUtils ( )
Returns

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

References $query_utils.

41  {
42  if (!$this->query_utils) {
43  $this->query_utils = new ilMySQLQueryUtils($this->db_instance);
44  }
45 
46  return $this->query_utils;
47  }
Class ilMySQLQueryUtils.

◆ getTableConstraintDefinition()

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

Implements ilDBReverse.

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

References $data, $query, $result, $row, and array.

192  {
193  $constraint_name = strtolower($constraint_name);
194  $table = $this->db_instance->quoteIdentifier($table, true);
195  $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */";
196 
197  if (strtolower($constraint_name) != 'primary') {
198  $constraint_name_pdo = $this->db_instance->getIndexName($constraint_name);
199  $result = $this->db_instance->query(sprintf($query, $this->db_instance->quote($constraint_name_pdo)));
200  $data = $this->db_instance->fetchAssoc($result);
201  if ($data) {
202  // apply 'idxname_format' only if the query succeeded, otherwise
203  // fallback to the given $index_name, without transformation
204  $constraint_name = strtolower($constraint_name_pdo);
205  }
206  }
207 
208  $result = $this->db_instance->query(sprintf($query, $this->db_instance->quote($constraint_name)));
209 
210  $colpos = 1;
211  $definition = array();
212  while (is_object($row = $result->fetchObject())) {
213  $row = (array)$row;
214  $row = array_change_key_case($row, CASE_LOWER);
215  $key_name = $row['key_name'];
216  if ($this->db_instance->options['portability']) {
217  if ($this->db_instance->options['field_case'] == CASE_LOWER) {
218  $key_name = strtolower($key_name);
219  } else {
220  $key_name = strtolower($key_name);
221  }
222  }
223  $key_name = strtolower($key_name); // FSX fix
224  if ($constraint_name == $key_name) {
225  if ($row['non_unique']) {
226  throw new ilDatabaseException(' is not an existing table constraint');
227  }
228  if ($row['key_name'] == 'PRIMARY') {
229  $definition['primary'] = true;
230  } else {
231  $definition['unique'] = true;
232  }
233  $column_name = $row['column_name'];
234  if ($this->db_instance->options['portability']) {
235  if ($this->db_instance->options['field_case'] == CASE_LOWER) {
236  $column_name = strtolower($column_name);
237  } else {
238  $column_name = strtoupper($column_name);
239  }
240  }
241  $definition['fields'][$column_name] = array(
242  'position' => $colpos ++,
243  );
244  if (!empty($row['collation'])) {
245  $definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'A' ? 'ascending' : 'descending');
246  }
247  }
248  }
249 
250  if (empty($definition['fields'])) {
251  throw new ilDatabaseException(' is not an existing table constraint');
252  }
253 
254  return $definition;
255  }
$result
Class ilDatabaseException.
Create styles array
The data for the language used.

◆ getTableFieldDefinition()

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

Implements ilDBReverse.

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

References $column, $columns, $data, $query, $res, and array.

54  {
55 
56  $return = array();
57 
58  $table = $this->db_instance->quoteIdentifier($table_name);
59  $query = "SHOW COLUMNS FROM $table LIKE " . $this->db_instance->quote($field_name);
60  $res = $this->pdo->query($query);
61  $columns = array();
62  while ($data = $res->fetch(PDO::FETCH_ASSOC)) {
63  $columns[] = $data;
64  }
65 
66  $ilDBPdoFieldDefinition = $this->db_instance->getFieldDefinition();
67 
68  foreach ($columns as $column) {
69  $column = array_change_key_case($column, CASE_LOWER);
70  $column['name'] = $column['field'];
71  unset($column['field']);
72  // if ($this->db_instance->options['portability']) {
73  // if ($this->db_instance->options['field_case'] == CASE_LOWER) {
74  // $column['name'] = strtolower($column['name']);
75  // } else {
76  // $column['name'] = strtoupper($column['name']);
77  // }
78  // } else {
79  $column = array_change_key_case($column, CASE_LOWER);
80  // }
81  if ($field_name == $column['name']) {
82  $mapped_datatype = $ilDBPdoFieldDefinition->mapNativeDatatype($column);
83 
84  list($types, $length, $unsigned, $fixed) = $mapped_datatype;
85  $notnull = false;
86  if (empty($column['null']) || $column['null'] !== 'YES') {
87  $notnull = true;
88  }
89  $default = false;
90  if (array_key_exists('default', $column)) {
91  $default = $column['default'];
92  if (is_null($default) && $notnull) {
93  $default = '';
94  }
95  }
96  $autoincrement = false;
97  if (!empty($column['extra']) && $column['extra'] == 'auto_increment') {
98  $autoincrement = true;
99  }
100 
101  $definition[0] = array(
102  'notnull' => $notnull,
103  'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type']),
104  );
105  if (!is_null($length)) {
106  $definition[0]['length'] = $length;
107  }
108  if (!is_null($unsigned)) {
109  $definition[0]['unsigned'] = $unsigned;
110  }
111  if (!is_null($fixed)) {
112  $definition[0]['fixed'] = $fixed;
113  }
114  if ($default !== false) {
115  $definition[0]['default'] = $default;
116  }
117  if ($autoincrement !== false) {
118  $definition[0]['autoincrement'] = $autoincrement;
119  }
120  foreach ($types as $key => $type) {
121  $definition[$key] = $definition[0];
122  if ($type == 'clob' || $type == 'blob') {
123  unset($definition[$key]['default']);
124  }
125  $definition[$key]['type'] = $type;
126  $definition[$key]['mdb2type'] = $type;
127  }
128 
129  return $definition;
130  }
131  }
132 
133  throw new ilDatabaseException('it was not specified an existing table column');
134  }
Class ilDatabaseException.
$column
Definition: 39dropdown.php:62
Create styles array
The data for the language used.
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 143 of file class.ilDBPdoReverse.php.

References $data, $query, $result, $row, and array.

143  {
144  $table = $this->db_instance->quoteIdentifier($table, true);
145  $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */";
146  $index_name_pdo = $this->db_instance->getIndexName($index_name);
147  $result = $this->db_instance->query(sprintf($query, $this->db_instance->quote($index_name_pdo)));
148  $data = $this->db_instance->fetchAssoc($result);
149 
150  if ($data) {
151  $index_name = $index_name_pdo;
152  }
153 
154  $result = $this->db_instance->query(sprintf($query, $this->db_instance->quote($index_name)));
155 
156  $colpos = 1;
157  $definition = array();
158  while (is_object($row = $result->fetchObject())) {
159  $row = array_change_key_case((array)$row, CASE_LOWER);
160 
161  $key_name = $row['key_name'];
162 
163 
164  if ($index_name == $key_name) {
165  if (!$row['non_unique']) {
166  throw new ilDatabaseException('it was not specified an existing table index');
167  }
168  $column_name = $row['column_name'];
169  $definition['fields'][$column_name] = array(
170  'position' => $colpos ++,
171  );
172  if (!empty($row['collation'])) {
173  $definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'A' ? 'ascending' : 'descending');
174  }
175  }
176  }
177 
178  if (empty($definition['fields'])) {
179  throw new ilDatabaseException('it was not specified an existing table index (index does not exist)');
180  }
181 
182  return $definition;
183  }
$result
Class ilDatabaseException.
Create styles array
The data for the language used.

◆ getTriggerDefinition()

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

Implements ilDBReverse.

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

263  {
264  throw new ilDatabaseException('not yet implemented ' . __METHOD__);
265  }
Class ilDatabaseException.

◆ tableInfo()

ilDBPdoReverse::tableInfo (   $result,
  $mode = null 
)
Parameters
$result
null$mode
Returns
array|void
Exceptions

Implements ilDBReverse.

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

274  {
275  throw new ilDatabaseException('not yet implemented ' . __METHOD__);
276  }
Class ilDatabaseException.

Field Documentation

◆ $db_instance

◆ $pdo

ilDBPdoReverse::$pdo
protected

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

Referenced by __construct().

◆ $query_utils

ilDBPdoReverse::$query_utils
protected

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

Referenced by getQueryUtils().


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