ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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)
 
 getTableFieldDefinition ($table_name, $field_name)
 
 getTableIndexDefinition ($table, $constraint_name)
 
 getTableConstraintDefinition ($table, $index_name)
 
 getTriggerDefinition ($trigger)
 

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.

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

References $db_instance, and $pdo.

Member Function Documentation

◆ getQueryUtils()

ilDBPdoReverse::getQueryUtils ( )
Returns
\ilMySQLQueryUtils

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

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

References $query_utils.

◆ getTableConstraintDefinition()

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

ilDatabaseException

Implements ilDBReverse.

Reimplemented in ilDBPdoReversePostgres.

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

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

References $data, $query, and $result.

◆ getTableFieldDefinition()

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

Implements ilDBReverse.

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

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

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

◆ getTableIndexDefinition()

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

ilDatabaseException

Implements ilDBReverse.

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

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

References $data, $query, and $result.

◆ getTriggerDefinition()

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

ilDatabaseException

Implements ilDBReverse.

Reimplemented in ilDBPdoReversePostgres.

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

268 {
269 throw new ilDatabaseException('not yet implemented ' . __METHOD__);
270 }

Field Documentation

◆ $db_instance

ilDBPdoReverse::$db_instance
protected

◆ $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 36 of file class.ilDBPdoReverse.php.

Referenced by getQueryUtils().


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