ILIAS  release_8 Revision v8.24
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 (string $table_name, string $field_name)
 
 getTableIndexDefinition (string $table, string $constraint_name)
 
 getTableConstraintDefinition (string $table, string $index_name)
 
 getTriggerDefinition (string $trigger)
 
 getTableFieldDefinition (string $table_name, string $field_name)
 
 getTableIndexDefinition (string $table, string $constraint_name)
 
 getTableConstraintDefinition (string $table, string $index_name)
 
 getTriggerDefinition (string $trigger)
 

Protected Attributes

PDO $pdo
 
ilDBPdo $db_instance
 
ilMySQLQueryUtils $query_utils = null
 

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 25 of file class.ilDBPdoReverse.php.

Constructor & Destructor Documentation

◆ __construct()

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

ilDBPdoReverse constructor.

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

35 {
36 $this->pdo = $pdo;
37 $this->db_instance = $db_instance;
38 }

References $db_instance, and $pdo.

Member Function Documentation

◆ getQueryUtils()

ilDBPdoReverse::getQueryUtils ( )

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

41 {
42 if ($this->query_utils === null) {
43 $this->query_utils = new ilMySQLQueryUtils($this->db_instance);
44 }
45
46 return $this->query_utils;
47 }
ilMySQLQueryUtils $query_utils
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $query_utils.

◆ getTableConstraintDefinition()

ilDBPdoReverse::getTableConstraintDefinition ( string  $table,
string  $index_name 
)
Returns
array<string, array<int|string, array<string, string|int>>&array>|array<string, bool>
Exceptions

ilDatabaseException

Implements ilDBReverse.

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

172 : array
173 {
174 $index_name = strtolower($index_name);
175 $table = $this->db_instance->quoteIdentifier($table, true);
176 $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */";
177
178 if (strtolower($index_name) !== 'primary') {
179 $constraint_name_pdo = $this->db_instance->getIndexName($index_name);
180 $result = $this->db_instance->query(sprintf($query, $this->db_instance->quote($constraint_name_pdo)));
181 $data = $this->db_instance->fetchAssoc($result);
182 if ($data) {
183 // apply 'idxname_format' only if the query succeeded, otherwise
184 // fallback to the given $index_name, without transformation
185 $index_name = strtolower($constraint_name_pdo);
186 }
187 }
188
189 $result = $this->db_instance->query(sprintf($query, $this->db_instance->quote($index_name)));
190
191 $colpos = 1;
192 $definition = array();
193 while (is_object($row = $result->fetchObject())) {
194 $row = (array) $row;
195 $row = array_change_key_case($row, CASE_LOWER);
196 $key_name = $row['key_name'];
197 if ($this->db_instance->options['portability'] ?? null) {
198 $key_name = strtolower($key_name);
199 }
200 $key_name = strtolower($key_name); // FSX fix
201 if ($index_name === $key_name) {
202 if ($row['non_unique']) {
203 throw new ilDatabaseException(' is not an existing table constraint');
204 }
205 if (strtolower($row['key_name']) === 'primary') {
206 $definition['primary'] = true;
207 } else {
208 $definition['unique'] = true;
209 }
210 $column_name = $row['column_name'];
211 if ($this->db_instance->options['portability'] ?? null) {
212 if ($this->db_instance->options['field_case'] == CASE_LOWER) {
213 $column_name = strtolower($column_name);
214 } else {
215 $column_name = strtoupper($column_name);
216 }
217 }
218 $definition['fields'][$column_name] = array(
219 'position' => $colpos++,
220 );
221 if (!empty($row['collation'])) {
222 $definition['fields'][$column_name]['sorting'] = ($row['collation'] === 'A' ? 'ascending' : 'descending');
223 }
224 }
225 }
226
227 if (empty($definition['fields'])) {
228 throw new ilDatabaseException(' is not an existing table constraint');
229 }
230
231 return $definition;
232 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$query

References $data, and $query.

◆ getTableFieldDefinition()

ilDBPdoReverse::getTableFieldDefinition ( string  $table_name,
string  $field_name 
)
Returns
array<int|string, array<string, mixed>>

Implements ilDBReverse.

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

52 : array
53 {
54 $table = $this->db_instance->quoteIdentifier($table_name);
55 $query = "SHOW COLUMNS FROM $table LIKE " . $this->db_instance->quote($field_name);
56 $res = $this->pdo->query($query);
57 $columns = array();
58 while ($data = $res->fetch(PDO::FETCH_ASSOC)) {
59 $columns[] = $data;
60 }
61
62 $ilDBPdoFieldDefinition = $this->db_instance->getFieldDefinition();
63
64 foreach ($columns as $column) {
65 $column = array_change_key_case($column, CASE_LOWER);
66 $column['name'] = $column['field'];
67 unset($column['field']);
68 $column = array_change_key_case($column, CASE_LOWER);
69 if ($field_name === $column['name'] && $ilDBPdoFieldDefinition !== null) {
70 [$types, $length, $unsigned, $fixed] = $ilDBPdoFieldDefinition->mapNativeDatatype($column);
71 $notnull = false;
72 if (empty($column['null']) || $column['null'] !== 'YES') {
73 $notnull = true;
74 }
75 $default = false;
76 if (array_key_exists('default', $column)) {
77 $default = $column['default'];
78 if ($notnull && is_null($default)) {
79 $default = '';
80 }
81 }
82 $autoincrement = false;
83 if (!empty($column['extra']) && $column['extra'] === 'auto_increment') {
84 $autoincrement = true;
85 }
86
87 $definition[0] = array(
88 'notnull' => $notnull,
89 'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type']),
90 );
91 if (!is_null($length)) {
92 $definition[0]['length'] = $length;
93 }
94 if (!is_null($unsigned)) {
95 $definition[0]['unsigned'] = $unsigned;
96 }
97 if (!is_null($fixed)) {
98 $definition[0]['fixed'] = $fixed;
99 }
100 if ($default !== false) {
101 $definition[0]['default'] = $default;
102 }
103 if ($autoincrement) {
104 $definition[0]['autoincrement'] = $autoincrement;
105 }
106 foreach ($types as $key => $type) {
107 $definition[$key] = $definition[0];
108 if ($type === 'clob' || $type === 'blob') {
109 unset($definition[$key]['default']);
110 }
111 $definition[$key]['type'] = $type;
112 $definition[$key]['mdb2type'] = $type;
113 }
114
115 return $definition;
116 }
117 }
118
119 throw new ilDatabaseException('it was not specified an existing table column');
120 }
$res
Definition: ltiservices.php:69
string $key
Consumer key/client ID value.
Definition: System.php:193
$type

References $data, ILIAS\LTI\ToolProvider\$key, $query, $res, and $type.

◆ getTableIndexDefinition()

ilDBPdoReverse::getTableIndexDefinition ( string  $table,
string  $constraint_name 
)
Returns
array<string, array<int|string, array<string, string|int>>&array>
Exceptions

ilDatabaseException

Implements ilDBReverse.

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

126 : array
127 {
128 $table = $this->db_instance->quoteIdentifier($table, true);
129 $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */";
130 $index_name_pdo = $this->db_instance->getIndexName($constraint_name);
131 $result = $this->db_instance->query(sprintf($query, $this->db_instance->quote($index_name_pdo)));
132 $data = $this->db_instance->fetchAssoc($result);
133
134 if ($data) {
135 $constraint_name = $index_name_pdo;
136 }
137
138 $result = $this->db_instance->query(sprintf($query, $this->db_instance->quote($constraint_name)));
139
140 $colpos = 1;
141 $definition = array();
142 while (is_object($row = $result->fetchObject())) {
143 $row = array_change_key_case((array) $row, CASE_LOWER);
144
145 $key_name = $row['key_name'];
146
147 if ($constraint_name === $key_name) {
148 if (!$row['non_unique']) {
149 throw new ilDatabaseException('it was not specified an existing table index');
150 }
151 $column_name = $row['column_name'];
152 $definition['fields'][$column_name] = array(
153 'position' => $colpos++,
154 );
155 if (!empty($row['collation'])) {
156 $definition['fields'][$column_name]['sorting'] = ($row['collation'] === 'A' ? 'ascending' : 'descending');
157 }
158 }
159 }
160
161 if (empty($definition['fields'])) {
162 throw new ilDatabaseException('it was not specified an existing table index (index does not exist)');
163 }
164
165 return $definition;
166 }

References $data, and $query.

◆ getTriggerDefinition()

ilDBPdoReverse::getTriggerDefinition ( string  $trigger)
Exceptions

ilDatabaseException

Implements ilDBReverse.

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

237 : array
238 {
239 throw new ilDatabaseException('not yet implemented ' . __METHOD__);
240 }

Field Documentation

◆ $db_instance

ilDBPdo ilDBPdoReverse::$db_instance
protected

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

Referenced by __construct().

◆ $pdo

PDO ilDBPdoReverse::$pdo
protected

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

Referenced by __construct().

◆ $query_utils

ilMySQLQueryUtils ilDBPdoReverse::$query_utils = null
protected

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

Referenced by getQueryUtils().


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