2require_once(
'class.ilDBPdoReverse.php');
29 $query =
"SELECT a.attname AS name,
34 WHEN 'numeric' THEN (a.atttypmod / 65536)
35 WHEN 'decimal' THEN (a.atttypmod / 65536)
36 WHEN 'money' THEN (a.atttypmod / 65536)
45 WHEN 'numeric' THEN (a.atttypmod % 65536) - 4
46 WHEN 'decimal' THEN (a.atttypmod % 65536) - 4
47 WHEN 'money' THEN (a.atttypmod % 65536) - 4
53 (SELECT substring(pg_get_expr(d.adbin, d.adrelid) for 128)
55 WHERE d.adrelid = a.attrelid
56 AND d.adnum = a.attnum
62 WHERE c.relname = " . $db->quote($table,
'text') .
"
63 AND a.atttypid = t.oid
64 AND c.oid = a.attrelid
65 AND NOT a.attisdropped
67 AND a.attname = " . $db->quote($field_name,
'text') .
"
76 $mapped_datatype = $db->getFieldDefinition()->mapNativeDatatype(
$column);
78 list($types, $length, $unsigned, $fixed) = $mapped_datatype;
80 if (!empty(
$column[
'attnotnull']) &&
$column[
'attnotnull'] ==
't') {
84 if (
$column[
'atthasdef'] ===
't'
85 && !preg_match(
"/nextval\('([^']+)'/",
$column[
'default'])
88 if (is_null($default) && $notnull) {
92 $autoincrement =
false;
93 if (preg_match(
"/nextval\('([^']+)'/",
$column[
'default'], $nextvals)) {
94 $autoincrement =
true;
96 $definition[0] = array(
'notnull' => $notnull,
'nativetype' =>
$column[
'type'] );
97 if (!is_null($length)) {
98 $definition[0][
'length'] = $length;
100 if (!is_null($unsigned)) {
101 $definition[0][
'unsigned'] = $unsigned;
103 if (!is_null($fixed)) {
104 $definition[0][
'fixed'] = $fixed;
106 if ($default !==
false) {
107 $definition[0][
'default'] = $default;
109 if ($autoincrement !==
false) {
110 $definition[0][
'autoincrement'] = $autoincrement;
112 foreach ($types as $key => $type) {
113 $definition[$key] = $definition[0];
114 if ($type ==
'clob' || $type ==
'blob') {
115 unset($definition[$key][
'default']);
117 $definition[$key][
'type'] = $type;
118 $definition[$key][
'mdb2type'] = $type;
138 $query =
'SELECT relname, indkey FROM pg_index, pg_class';
139 $query .=
' WHERE pg_class.oid = pg_index.indexrelid';
140 $query .=
" AND indisunique != 't' AND indisprimary != 't'";
141 $query .=
' AND pg_class.relname = %s';
142 $index_name_mdb2 = $db->getIndexName($index_name);
146 }
catch (Exception $e) {
157 $row = array_change_key_case(
$row, CASE_LOWER);
159 $columns = $manager->listTableFields($table);
161 $definition = array();
163 $index_column_numbers = explode(
' ',
$row[
'indkey']);
166 foreach ($index_column_numbers as $number) {
167 $definition[
'fields'][
$columns[($number - 1)]] = array(
168 'position' => $colpos ++,
169 'sorting' =>
'ascending',
189 $query =
'SELECT relname, indisunique, indisprimary, indkey FROM pg_index, pg_class';
190 $query .=
' WHERE pg_class.oid = pg_index.indexrelid';
191 $query .=
" AND (indisunique = 't' OR indisprimary = 't')";
192 $query .=
' AND pg_class.relname = %s';
193 $constraint_name_mdb2 = $db->getIndexName($constraint_name);
196 }
catch (Exception $e) {
199 if ($e instanceof PDOException || empty(
$row)) {
208 $row = array_change_key_case(
$row, CASE_LOWER);
211 $definition = array();
212 if (
$row[
'indisprimary'] ==
't') {
213 $definition[
'primary'] =
true;
214 } elseif (
$row[
'indisunique'] ==
't') {
215 $definition[
'unique'] =
true;
218 $index_column_numbers = explode(
' ',
$row[
'indkey']);
221 foreach ($index_column_numbers as $number) {
222 $definition[
'fields'][
$columns[($number - 1)]] = array(
223 'position' => $colpos ++,
224 'sorting' =>
'ascending',
251 $query =
"SELECT trg.tgname AS trigger_name,
252 tbl.relname AS table_name,
254 WHEN p.proname IS NOT NULL THEN 'EXECUTE PROCEDURE ' || p.proname || '();'
257 CASE trg.tgtype & cast(2 as int2)
261 CASE trg.tgtype & cast(28 as int2)
262 WHEN 16 THEN 'UPDATE'
265 WHEN 20 THEN 'INSERT, UPDATE'
266 WHEN 28 THEN 'INSERT, UPDATE, DELETE'
267 WHEN 24 THEN 'UPDATE, DELETE'
268 WHEN 12 THEN 'INSERT, DELETE'
269 END AS trigger_event,
270 trg.tgenabled AS trigger_enabled,
271 obj_description(trg.oid, 'pg_trigger') AS trigger_comment
275 WHERE trg.tgrelid = tbl.oid
276 AND trg.tgfoid = p.oid
277 AND trg.tgname = " . $db->quote($trigger,
'text');
279 'trigger_name' =>
'text',
280 'table_name' =>
'text',
281 'trigger_body' =>
'text',
282 'trigger_type' =>
'text',
283 'trigger_event' =>
'text',
284 'trigger_comment' =>
'text',
285 'trigger_enabled' =>
'boolean',
314 return parent::tableInfo(
$result, $mode);
320 if (!is_resource($resource)) {
324 if ($db->options[
'portability']) {
325 if ($db->options[
'field_case'] == CASE_LOWER) {
326 $case_func =
'strtolower';
328 $case_func =
'strtoupper';
331 $case_func =
'strval';
334 $count = @pg_num_fields($resource);
338 $res[
'num_fields'] = $count;
341 $db->loadModule(
'Datatype',
null,
true);
342 for ($i = 0; $i < $count; $i ++) {
344 'table' => function_exists(
'pg_field_table') ? @pg_field_table($resource, $i) :
'',
345 'name' => $case_func(@pg_field_name($resource, $i)),
346 'type' => @pg_field_type($resource, $i),
347 'length' => @pg_field_size($resource, $i),
350 $mdb2type_info = $db->datatype->mapNativeDatatype(
$res[$i]);
352 return $mdb2type_info;
354 $res[$i][
'mdb2type'] = $mdb2type_info[0][0];
356 $res[
'order'][
$res[$i][
'name']] = $i;
359 $res[
'ordertable'][
$res[$i][
'table']][
$res[$i][
'name']] = $i;
sprintf('%.4f', $callTime)
const MDB2_ERROR_NEED_MORE_DATA
const MDB2_FETCHMODE_ASSOC
Column data indexed by column names.
const MDB2_TABLEINFO_ORDERTABLE
const MDB2_TABLEINFO_ORDER
These are constants for the tableInfo-function they are bitwised or'ed.
An exception for terminatinating execution or to throw for unit testing.
isResultCommon($value)
Tell whether a value is a MDB2 result implementing the common interface.
isError($data, $code=null)
Tell whether a value is a PEAR error.
tableInfo($result, $mode=null)
Returns information about a table or a result set.
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.