44 if (!$this->query_utils) {
60 $table = $this->db_instance->quoteIdentifier($table_name);
61 $query =
"SHOW COLUMNS FROM $table LIKE " . $this->db_instance->quote($field_name);
64 while (
$data =
$res->fetch(PDO::FETCH_ASSOC)) {
68 $ilDBPdoFieldDefinition = $this->db_instance->getFieldDefinition();
71 $column = array_change_key_case($column, CASE_LOWER);
72 $column[
'name'] = $column[
'field'];
73 unset($column[
'field']);
81 $column = array_change_key_case($column, CASE_LOWER);
83 if ($field_name == $column[
'name']) {
84 $mapped_datatype = $ilDBPdoFieldDefinition->mapNativeDatatype($column);
86 list($types, $length, $unsigned, $fixed) = $mapped_datatype;
88 if (empty($column[
'null']) || $column[
'null'] !==
'YES') {
92 if (array_key_exists(
'default', $column)) {
93 $default = $column[
'default'];
94 if (is_null($default) && $notnull) {
98 $autoincrement =
false;
99 if (!empty($column[
'extra']) && $column[
'extra'] ==
'auto_increment') {
100 $autoincrement =
true;
103 $definition[0] = array(
104 'notnull' => $notnull,
105 'nativetype' => preg_replace(
'/^([a-z]+)[^a-z].*/i',
'\\1', $column[
'type']),
107 if (!is_null($length)) {
108 $definition[0][
'length'] = $length;
110 if (!is_null($unsigned)) {
111 $definition[0][
'unsigned'] = $unsigned;
113 if (!is_null($fixed)) {
114 $definition[0][
'fixed'] = $fixed;
116 if ($default !==
false) {
117 $definition[0][
'default'] = $default;
119 if ($autoincrement !==
false) {
120 $definition[0][
'autoincrement'] = $autoincrement;
122 foreach ($types as $key =>
$type) {
123 $definition[$key] = $definition[0];
125 unset($definition[$key][
'default']);
127 $definition[$key][
'type'] =
$type;
128 $definition[$key][
'mdb2type'] =
$type;
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)));
154 $index_name = $index_name_pdo;
157 $result = $this->db_instance->query(sprintf(
$query, $this->db_instance->quote($index_name)));
160 $definition = array();
161 while (is_object($row =
$result->fetchObject())) {
162 $row = array_change_key_case((array) $row, CASE_LOWER);
164 $key_name = $row[
'key_name'];
167 if ($index_name == $key_name) {
168 if (!$row[
'non_unique']) {
171 $column_name = $row[
'column_name'];
172 $definition[
'fields'][$column_name] = array(
173 'position' => $colpos++,
175 if (!empty($row[
'collation'])) {
176 $definition[
'fields'][$column_name][
'sorting'] = ($row[
'collation'] ==
'A' ?
'ascending' :
'descending');
181 if (empty($definition[
'fields'])) {
182 throw new ilDatabaseException(
'it was not specified an existing table index (index does not exist)');
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 */";
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)));
208 $constraint_name = strtolower($constraint_name_pdo);
212 $result = $this->db_instance->query(sprintf(
$query, $this->db_instance->quote($constraint_name)));
215 $definition = array();
216 while (is_object($row =
$result->fetchObject())) {
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);
224 $key_name = strtolower($key_name);
227 $key_name = strtolower($key_name);
228 if ($constraint_name == $key_name) {
229 if ($row[
'non_unique']) {
232 if ($row[
'key_name'] ==
'PRIMARY') {
233 $definition[
'primary'] =
true;
235 $definition[
'unique'] =
true;
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);
242 $column_name = strtoupper($column_name);
245 $definition[
'fields'][$column_name] = array(
246 'position' => $colpos++,
248 if (!empty($row[
'collation'])) {
249 $definition[
'fields'][$column_name][
'sorting'] = ($row[
'collation'] ==
'A' ?
'ascending' :
'descending');
254 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)
getTableConstraintDefinition($table, $constraint_name)