30 $query =
"SELECT a.attname AS name,
35 WHEN 'numeric' THEN (a.atttypmod / 65536)
36 WHEN 'decimal' THEN (a.atttypmod / 65536)
37 WHEN 'money' THEN (a.atttypmod / 65536)
46 WHEN 'numeric' THEN (a.atttypmod % 65536) - 4
47 WHEN 'decimal' THEN (a.atttypmod % 65536) - 4
48 WHEN 'money' THEN (a.atttypmod % 65536) - 4
54 (SELECT substring(pg_get_expr(d.adbin, d.adrelid) for 128)
56 WHERE d.adrelid = a.attrelid
57 AND d.adnum = a.attnum
63 WHERE c.relname = " . $db->quote($table,
'text') .
"
64 AND a.atttypid = t.oid
65 AND c.oid = a.attrelid
66 AND NOT a.attisdropped
68 AND a.attname = " . $db->quote($field_name,
'text') .
"
76 $column = array_change_key_case($column, CASE_LOWER);
77 $mapped_datatype = $db->getFieldDefinition()->mapNativeDatatype($column);
79 list($types, $length, $unsigned, $fixed) = $mapped_datatype;
81 if (!empty($column[
'attnotnull']) && $column[
'attnotnull'] ==
't') {
85 if ($column[
'atthasdef'] ===
't'
86 && !preg_match(
"/nextval\('([^']+)'/", $column[
'default'])
88 $default = $column[
'default'];#substr($column[
'adsrc'], 1, -1);
89 if (is_null($default) && $notnull) {
93 $autoincrement =
false;
94 if (preg_match(
"/nextval\('([^']+)'/", $column[
'default'], $nextvals)) {
95 $autoincrement =
true;
97 $definition[0] = array(
'notnull' => $notnull,
'nativetype' => $column[
'type'] );
98 if (!is_null($length)) {
99 $definition[0][
'length'] = $length;
101 if (!is_null($unsigned)) {
102 $definition[0][
'unsigned'] = $unsigned;
104 if (!is_null($fixed)) {
105 $definition[0][
'fixed'] = $fixed;
107 if ($default !==
false) {
108 $definition[0][
'default'] = $default;
110 if ($autoincrement !==
false) {
111 $definition[0][
'autoincrement'] = $autoincrement;
113 foreach ($types as $key =>
$type) {
114 $definition[$key] = $definition[0];
116 unset($definition[$key][
'default']);
118 $definition[$key][
'type'] =
$type;
119 $definition[$key][
'mdb2type'] =
$type;
140 $query =
'SELECT relname, indkey FROM pg_index, pg_class';
141 $query .=
' WHERE pg_class.oid = pg_index.indexrelid';
142 $query .=
" AND indisunique != 't' AND indisprimary != 't'";
143 $query .=
' AND pg_class.relname = %s';
144 $index_name_mdb2 = $db->getIndexName($index_name);
148 }
catch (Exception
$e) {
159 $row = array_change_key_case($row, CASE_LOWER);
161 $columns = $manager->listTableFields($table);
163 $definition = array();
165 $index_column_numbers = explode(
' ', $row[
'indkey']);
168 foreach ($index_column_numbers as $number) {
169 $definition[
'fields'][
$columns[($number - 1)]] = array(
170 'position' => $colpos++,
171 'sorting' =>
'ascending',
192 $query =
'SELECT relname, indisunique, indisprimary, indkey FROM pg_index, pg_class';
193 $query .=
' WHERE pg_class.oid = pg_index.indexrelid';
194 $query .=
" AND (indisunique = 't' OR indisprimary = 't')";
195 $query .=
' AND pg_class.relname = %s';
196 $constraint_name_mdb2 = $db->getIndexName($constraint_name);
199 }
catch (Exception
$e) {
202 if (
$e instanceof PDOException || empty($row)) {
211 $row = array_change_key_case($row, CASE_LOWER);
214 $definition = array();
215 if ($row[
'indisprimary'] ==
't') {
216 $definition[
'primary'] =
true;
217 } elseif ($row[
'indisunique'] ==
't') {
218 $definition[
'unique'] =
true;
221 $index_column_numbers = explode(
' ', $row[
'indkey']);
224 foreach ($index_column_numbers as $number) {
225 $definition[
'fields'][
$columns[($number - 1)]] = array(
226 'position' => $colpos++,
227 'sorting' =>
'ascending',
255 $query =
"SELECT trg.tgname AS trigger_name,
256 tbl.relname AS table_name,
258 WHEN p.proname IS NOT NULL THEN 'EXECUTE PROCEDURE ' || p.proname || '();'
261 CASE trg.tgtype & cast(2 as int2)
265 CASE trg.tgtype & cast(28 as int2)
266 WHEN 16 THEN 'UPDATE'
269 WHEN 20 THEN 'INSERT, UPDATE'
270 WHEN 28 THEN 'INSERT, UPDATE, DELETE'
271 WHEN 24 THEN 'UPDATE, DELETE'
272 WHEN 12 THEN 'INSERT, DELETE'
273 END AS trigger_event,
274 trg.tgenabled AS trigger_enabled,
275 obj_description(trg.oid, 'pg_trigger') AS trigger_comment
279 WHERE trg.tgrelid = tbl.oid
280 AND trg.tgfoid = p.oid
281 AND trg.tgname = " . $db->quote($trigger,
'text');
283 'trigger_name' =>
'text',
284 'table_name' =>
'text',
285 'trigger_body' =>
'text',
286 'trigger_type' =>
'text',
287 'trigger_event' =>
'text',
288 'trigger_comment' =>
'text',
289 'trigger_enabled' =>
'boolean',
An exception for terminatinating execution or to throw for unit testing.
getTriggerDefinition($trigger)
Get the structure of a trigger into an array.
getTableConstraintDefinition($table, $constraint_name)
Get the structure of a constraint into an array.
getTableIndexDefinition($table, $index_name)
getTableFieldDefinition($table_name, $field_name)
Class ilDatabaseException.