ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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)
 
 getTableFieldDefinition ($table_name, $field_name)
 
 getTableIndexDefinition ($table, $constraint_name)
 
 getTableConstraintDefinition ($table, $index_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 28 of file class.ilDBPdoReverse.php.

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

References $db_instance, and $pdo.

Member Function Documentation

◆ getQueryUtils()

ilDBPdoReverse::getQueryUtils ( )
Returns
\ilMySQLQueryUtils

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

44 {
45 if (!$this->query_utils) {
46 $this->query_utils = new ilMySQLQueryUtils($this->db_instance);
47 }
48
49 return $this->query_utils;
50 }
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 196 of file class.ilDBPdoReverse.php.

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

References $data, $query, $result, $row, $table, and sprintf.

◆ getTableFieldDefinition()

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

Implements ilDBReverse.

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

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

References $column, $columns, $data, $key, $query, $res, $table, and $type.

◆ getTableIndexDefinition()

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

ilDatabaseException

Implements ilDBReverse.

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

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

References $data, $query, $result, $row, $table, and sprintf.

◆ getTriggerDefinition()

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

ilDatabaseException

Implements ilDBReverse.

Reimplemented in ilDBPdoReversePostgres.

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

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

◆ tableInfo()

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

ilDatabaseException

Implements ilDBReverse.

Reimplemented in ilDBPdoReversePostgres.

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

281 {
282 throw new ilDatabaseException('not yet implemented ' . __METHOD__);
283 }

Field Documentation

◆ $db_instance

◆ $pdo

ilDBPdoReverse::$pdo
protected

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

Referenced by __construct().

◆ $query_utils

ilDBPdoReverse::$query_utils
protected

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

Referenced by getQueryUtils().


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