2 require_once(
'./Services/Database/interfaces/interface.ilDBReverse.php');
45 if (!$this->query_utils) {
61 $table = $this->db_instance->quoteIdentifier($table_name);
62 $query =
"SHOW COLUMNS FROM $table LIKE " . $this->db_instance->quote($field_name);
65 while (
$data =
$res->fetch(PDO::FETCH_ASSOC)) {
69 $ilDBPdoFieldDefinition = $this->db_instance->getFieldDefinition();
72 $column = array_change_key_case($column, CASE_LOWER);
73 $column[
'name'] = $column[
'field'];
74 unset($column[
'field']);
82 $column = array_change_key_case($column, CASE_LOWER);
84 if ($field_name == $column[
'name']) {
85 $mapped_datatype = $ilDBPdoFieldDefinition->mapNativeDatatype($column);
87 list($types, $length, $unsigned, $fixed) = $mapped_datatype;
89 if (empty($column[
'null']) || $column[
'null'] !==
'YES') {
93 if (array_key_exists(
'default', $column)) {
99 $autoincrement =
false;
100 if (!empty($column[
'extra']) && $column[
'extra'] ==
'auto_increment') {
101 $autoincrement =
true;
104 $definition[0] = array(
105 'notnull' => $notnull,
106 'nativetype' => preg_replace(
'/^([a-z]+)[^a-z].*/i',
'\\1', $column[
'type']),
108 if (!is_null($length)) {
109 $definition[0][
'length'] = $length;
111 if (!is_null($unsigned)) {
112 $definition[0][
'unsigned'] = $unsigned;
114 if (!is_null($fixed)) {
115 $definition[0][
'fixed'] = $fixed;
118 $definition[0][
'default'] =
$default;
120 if ($autoincrement !==
false) {
121 $definition[0][
'autoincrement'] = $autoincrement;
124 $definition[
$key] = $definition[0];
126 unset($definition[
$key][
'default']);
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)));
155 $index_name = $index_name_pdo;
158 $result = $this->db_instance->query(sprintf(
$query, $this->db_instance->quote($index_name)));
161 $definition = array();
163 $row = array_change_key_case((array)
$row, CASE_LOWER);
165 $key_name = $row[
'key_name'];
168 if ($index_name == $key_name) {
169 if (!$row[
'non_unique']) {
172 $column_name = $row[
'column_name'];
173 $definition[
'fields'][$column_name] = array(
174 'position' => $colpos++,
176 if (!empty($row[
'collation'])) {
177 $definition[
'fields'][$column_name][
'sorting'] = ($row[
'collation'] ==
'A' ?
'ascending' :
'descending');
182 if (empty($definition[
'fields'])) {
183 throw new ilDatabaseException(
'it was not specified an existing table index (index does not exist)');
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 */";
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)));
209 $constraint_name = strtolower($constraint_name_pdo);
213 $result = $this->db_instance->query(sprintf(
$query, $this->db_instance->quote($constraint_name)));
216 $definition = array();
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);
225 $key_name = strtolower($key_name);
228 $key_name = strtolower($key_name);
229 if ($constraint_name == $key_name) {
230 if (
$row[
'non_unique']) {
233 if (
$row[
'key_name'] ==
'PRIMARY') {
234 $definition[
'primary'] =
true;
236 $definition[
'unique'] =
true;
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);
243 $column_name = strtoupper($column_name);
246 $definition[
'fields'][$column_name] = array(
247 'position' => $colpos++,
249 if (!empty(
$row[
'collation'])) {
250 $definition[
'fields'][$column_name][
'sorting'] = (
$row[
'collation'] ==
'A' ?
'ascending' :
'descending');
255 if (empty($definition[
'fields'])) {
getTableFieldDefinition($table_name, $field_name)
getTableIndexDefinition($table, $index_name)
Class ilDatabaseException.
foreach($_POST as $key=> $value) $res
__construct(\PDO $pdo, ilDBPdo $db_instance)
ilDBPdoReverse constructor.
getTriggerDefinition($trigger)
if(empty($password)) $table
getTableConstraintDefinition($table, $constraint_name)