pgsql.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP versions 4 and 5 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
  6. // | Stig. S. Bakken, Lukas Smith |
  7. // | All rights reserved. |
  8. // +----------------------------------------------------------------------+
  9. // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
  10. // | API as well as database abstraction for PHP applications. |
  11. // | This LICENSE is in the BSD license style. |
  12. // | |
  13. // | Redistribution and use in source and binary forms, with or without |
  14. // | modification, are permitted provided that the following conditions |
  15. // | are met: |
  16. // | |
  17. // | Redistributions of source code must retain the above copyright |
  18. // | notice, this list of conditions and the following disclaimer. |
  19. // | |
  20. // | Redistributions in binary form must reproduce the above copyright |
  21. // | notice, this list of conditions and the following disclaimer in the |
  22. // | documentation and/or other materials provided with the distribution. |
  23. // | |
  24. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
  25. // | Lukas Smith nor the names of his contributors may be used to endorse |
  26. // | or promote products derived from this software without specific prior|
  27. // | written permission. |
  28. // | |
  29. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
  30. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
  31. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
  32. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
  33. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
  34. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  35. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  36. // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
  37. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
  38. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  39. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
  40. // | POSSIBILITY OF SUCH DAMAGE. |
  41. // +----------------------------------------------------------------------+
  42. // | Authors: Paul Cooper <pgc@ucecom.com> |
  43. // | Lorenzo Alberton <l.alberton@quipo.it> |
  44. // +----------------------------------------------------------------------+
  45. //
  46. // $Id$
  47. require_once 'MDB2/Driver/Reverse/Common.php';
  48. /**
  49. * MDB2 PostGreSQL driver for the schema reverse engineering module
  50. *
  51. * @package MDB2
  52. * @category Database
  53. * @author Paul Cooper <pgc@ucecom.com>
  54. * @author Lorenzo Alberton <l.alberton@quipo.it>
  55. */
  56. class MDB2_Driver_Reverse_pgsql extends MDB2_Driver_Reverse_Common
  57. {
  58. // {{{ getTableFieldDefinition()
  59. /**
  60. * Get the structure of a field into an array
  61. *
  62. * @param string $table_name name of table that should be used in method
  63. * @param string $field_name name of field that should be used in method
  64. * @return mixed data array on success, a MDB2 error on failure
  65. * @access public
  66. */
  67. function getTableFieldDefinition($table_name, $field_name)
  68. {
  69. $db = $this->getDBInstance();
  70. if (MDB2::isError($db)) {
  71. return $db;
  72. }
  73. $result = $db->loadModule('Datatype', null, true);
  74. if (MDB2::isError($result)) {
  75. return $result;
  76. }
  77. list($schema, $table) = $this->splitTableSchema($table_name);
  78. $query = "SELECT a.attname AS name,
  79. t.typname AS type,
  80. CASE a.attlen
  81. WHEN -1 THEN
  82. CASE t.typname
  83. WHEN 'numeric' THEN (a.atttypmod / 65536)
  84. WHEN 'decimal' THEN (a.atttypmod / 65536)
  85. WHEN 'money' THEN (a.atttypmod / 65536)
  86. ELSE CASE a.atttypmod
  87. WHEN -1 THEN NULL
  88. ELSE a.atttypmod - 4
  89. END
  90. END
  91. ELSE a.attlen
  92. END AS length,
  93. CASE t.typname
  94. WHEN 'numeric' THEN (a.atttypmod % 65536) - 4
  95. WHEN 'decimal' THEN (a.atttypmod % 65536) - 4
  96. WHEN 'money' THEN (a.atttypmod % 65536) - 4
  97. ELSE 0
  98. END AS scale,
  99. a.attnotnull,
  100. a.atttypmod,
  101. a.atthasdef,
  102. (SELECT substring(pg_get_expr(d.adbin, d.adrelid) for 128)
  103. FROM pg_attrdef d
  104. WHERE d.adrelid = a.attrelid
  105. AND d.adnum = a.attnum
  106. AND a.atthasdef
  107. ) as default
  108. FROM pg_attribute a,
  109. pg_class c,
  110. pg_type t
  111. WHERE c.relname = ".$db->quote($table, 'text')."
  112. AND a.atttypid = t.oid
  113. AND c.oid = a.attrelid
  114. AND NOT a.attisdropped
  115. AND a.attnum > 0
  116. AND a.attname = ".$db->quote($field_name, 'text')."
  117. ORDER BY a.attnum";
  118. $column = $db->queryRow($query, null, MDB2_FETCHMODE_ASSOC);
  119. if (MDB2::isError($column)) {
  120. return $column;
  121. }
  122. if (empty($column)) {
  123. return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  124. 'it was not specified an existing table column', __FUNCTION__);
  125. }
  126. $column = array_change_key_case($column, CASE_LOWER);
  127. $mapped_datatype = $db->datatype->mapNativeDatatype($column);
  128. if (MDB2::isError($mapped_datatype)) {
  129. return $mapped_datatype;
  130. }
  131. list($types, $length, $unsigned, $fixed) = $mapped_datatype;
  132. $notnull = false;
  133. if (!empty($column['attnotnull']) && $column['attnotnull'] == 't') {
  134. $notnull = true;
  135. }
  136. $default = null;
  137. if ($column['atthasdef'] === 't'
  138. && strpos($column['default'], 'NULL') !== 0
  139. && !preg_match("/nextval\('([^']+)'/", $column['default'])
  140. ) {
  141. $pattern = '/^\'(.*)\'::[\w ]+$/i';
  142. $default = $column['default'];#substr($column['adsrc'], 1, -1);
  143. if ((null === $default) && $notnull) {
  144. $default = '';
  145. } elseif (!empty($default) && preg_match($pattern, $default)) {
  146. //remove data type cast
  147. $default = preg_replace ($pattern, '\\1', $default);
  148. }
  149. }
  150. $autoincrement = false;
  151. if (preg_match("/nextval\('([^']+)'/", $column['default'], $nextvals)) {
  152. $autoincrement = true;
  153. }
  154. $definition[0] = array('notnull' => $notnull, 'nativetype' => $column['type']);
  155. if (null !== $length) {
  156. $definition[0]['length'] = $length;
  157. }
  158. if (null !== $unsigned) {
  159. $definition[0]['unsigned'] = $unsigned;
  160. }
  161. if (null !== $fixed) {
  162. $definition[0]['fixed'] = $fixed;
  163. }
  164. if ($default !== false) {
  165. $definition[0]['default'] = $default;
  166. }
  167. if ($autoincrement !== false) {
  168. $definition[0]['autoincrement'] = $autoincrement;
  169. }
  170. foreach ($types as $key => $type) {
  171. $definition[$key] = $definition[0];
  172. if ($type == 'clob' || $type == 'blob') {
  173. unset($definition[$key]['default']);
  174. }
  175. $definition[$key]['type'] = $type;
  176. $definition[$key]['mdb2type'] = $type;
  177. }
  178. return $definition;
  179. }
  180. // }}}
  181. // {{{ getTableIndexDefinition()
  182. /**
  183. * Get the structure of an index into an array
  184. *
  185. * @param string $table_name name of table that should be used in method
  186. * @param string $index_name name of index that should be used in method
  187. * @return mixed data array on success, a MDB2 error on failure
  188. * @access public
  189. */
  190. function getTableIndexDefinition($table_name, $index_name)
  191. {
  192. $db = $this->getDBInstance();
  193. if (MDB2::isError($db)) {
  194. return $db;
  195. }
  196. list($schema, $table) = $this->splitTableSchema($table_name);
  197. $query = 'SELECT relname, indkey FROM pg_index, pg_class';
  198. $query.= ' WHERE pg_class.oid = pg_index.indexrelid';
  199. $query.= " AND indisunique != 't' AND indisprimary != 't'";
  200. $query.= ' AND pg_class.relname = %s';
  201. $index_name_mdb2 = $db->getIndexName($index_name);
  202. $row = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
  203. if (MDB2::isError($row) || empty($row)) {
  204. // fallback to the given $index_name, without transformation
  205. $row = $db->queryRow(sprintf($query, $db->quote($index_name, 'text')), null, MDB2_FETCHMODE_ASSOC);
  206. }
  207. if (MDB2::isError($row)) {
  208. return $row;
  209. }
  210. if (empty($row)) {
  211. return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  212. 'it was not specified an existing table index', __FUNCTION__);
  213. }
  214. $row = array_change_key_case($row, CASE_LOWER);
  215. $db->loadModule('Manager', null, true);
  216. $columns = $db->manager->listTableFields($table_name);
  217. $definition = array();
  218. $index_column_numbers = explode(' ', $row['indkey']);
  219. $colpos = 1;
  220. foreach ($index_column_numbers as $number) {
  221. $definition['fields'][$columns[($number - 1)]] = array(
  222. 'position' => $colpos++,
  223. 'sorting' => 'ascending',
  224. );
  225. }
  226. return $definition;
  227. }
  228. // }}}
  229. // {{{ getTableConstraintDefinition()
  230. /**
  231. * Get the structure of a constraint into an array
  232. *
  233. * @param string $table_name name of table that should be used in method
  234. * @param string $constraint_name name of constraint that should be used in method
  235. * @return mixed data array on success, a MDB2 error on failure
  236. * @access public
  237. */
  238. function getTableConstraintDefinition($table_name, $constraint_name)
  239. {
  240. $db = $this->getDBInstance();
  241. if (MDB2::isError($db)) {
  242. return $db;
  243. }
  244. list($schema, $table) = $this->splitTableSchema($table_name);
  245. $query = "SELECT c.oid,
  246. c.conname AS constraint_name,
  247. CASE WHEN c.contype = 'c' THEN 1 ELSE 0 END AS \"check\",
  248. CASE WHEN c.contype = 'f' THEN 1 ELSE 0 END AS \"foreign\",
  249. CASE WHEN c.contype = 'p' THEN 1 ELSE 0 END AS \"primary\",
  250. CASE WHEN c.contype = 'u' THEN 1 ELSE 0 END AS \"unique\",
  251. CASE WHEN c.condeferrable = 'f' THEN 0 ELSE 1 END AS deferrable,
  252. CASE WHEN c.condeferred = 'f' THEN 0 ELSE 1 END AS initiallydeferred,
  253. --array_to_string(c.conkey, ' ') AS constraint_key,
  254. t.relname AS table_name,
  255. t2.relname AS references_table,
  256. CASE confupdtype
  257. WHEN 'a' THEN 'NO ACTION'
  258. WHEN 'r' THEN 'RESTRICT'
  259. WHEN 'c' THEN 'CASCADE'
  260. WHEN 'n' THEN 'SET NULL'
  261. WHEN 'd' THEN 'SET DEFAULT'
  262. END AS onupdate,
  263. CASE confdeltype
  264. WHEN 'a' THEN 'NO ACTION'
  265. WHEN 'r' THEN 'RESTRICT'
  266. WHEN 'c' THEN 'CASCADE'
  267. WHEN 'n' THEN 'SET NULL'
  268. WHEN 'd' THEN 'SET DEFAULT'
  269. END AS ondelete,
  270. CASE confmatchtype
  271. WHEN 'u' THEN 'UNSPECIFIED'
  272. WHEN 'f' THEN 'FULL'
  273. WHEN 'p' THEN 'PARTIAL'
  274. END AS match,
  275. --array_to_string(c.confkey, ' ') AS fk_constraint_key,
  276. consrc
  277. FROM pg_constraint c
  278. LEFT JOIN pg_class t ON c.conrelid = t.oid
  279. LEFT JOIN pg_class t2 ON c.confrelid = t2.oid
  280. WHERE c.conname = %s
  281. AND t.relname = " . $db->quote($table, 'text');
  282. $constraint_name_mdb2 = $db->getIndexName($constraint_name);
  283. $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
  284. if (MDB2::isError($row) || empty($row)) {
  285. // fallback to the given $index_name, without transformation
  286. $constraint_name_mdb2 = $constraint_name;
  287. $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
  288. }
  289. if (MDB2::isError($row)) {
  290. return $row;
  291. }
  292. $uniqueIndex = false;
  293. if (empty($row)) {
  294. // We might be looking for a UNIQUE index that was not created
  295. // as a constraint but should be treated as such.
  296. $query = 'SELECT relname AS constraint_name,
  297. indkey,
  298. 0 AS "check",
  299. 0 AS "foreign",
  300. 0 AS "primary",
  301. 1 AS "unique",
  302. 0 AS deferrable,
  303. 0 AS initiallydeferred,
  304. NULL AS references_table,
  305. NULL AS onupdate,
  306. NULL AS ondelete,
  307. NULL AS match
  308. FROM pg_index, pg_class
  309. WHERE pg_class.oid = pg_index.indexrelid
  310. AND indisunique = \'t\'
  311. AND pg_class.relname = %s';
  312. $constraint_name_mdb2 = $db->getIndexName($constraint_name);
  313. $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
  314. if (MDB2::isError($row) || empty($row)) {
  315. // fallback to the given $index_name, without transformation
  316. $constraint_name_mdb2 = $constraint_name;
  317. $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
  318. }
  319. if (MDB2::isError($row)) {
  320. return $row;
  321. }
  322. if (empty($row)) {
  323. return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  324. $constraint_name . ' is not an existing table constraint', __FUNCTION__);
  325. }
  326. $uniqueIndex = true;
  327. }
  328. $row = array_change_key_case($row, CASE_LOWER);
  329. $definition = array(
  330. 'primary' => (boolean)$row['primary'],
  331. 'unique' => (boolean)$row['unique'],
  332. 'foreign' => (boolean)$row['foreign'],
  333. 'check' => (boolean)$row['check'],
  334. 'fields' => array(),
  335. 'references' => array(
  336. 'table' => $row['references_table'],
  337. 'fields' => array(),
  338. ),
  339. 'deferrable' => (boolean)$row['deferrable'],
  340. 'initiallydeferred' => (boolean)$row['initiallydeferred'],
  341. 'onupdate' => $row['onupdate'],
  342. 'ondelete' => $row['ondelete'],
  343. 'match' => $row['match'],
  344. );
  345. if ($uniqueIndex) {
  346. $db->loadModule('Manager', null, true);
  347. $columns = $db->manager->listTableFields($table_name);
  348. $index_column_numbers = explode(' ', $row['indkey']);
  349. $colpos = 1;
  350. foreach ($index_column_numbers as $number) {
  351. $definition['fields'][$columns[($number - 1)]] = array(
  352. 'position' => $colpos++,
  353. 'sorting' => 'ascending',
  354. );
  355. }
  356. return $definition;
  357. }
  358. $query = 'SELECT a.attname
  359. FROM pg_constraint c
  360. LEFT JOIN pg_class t ON c.conrelid = t.oid
  361. LEFT JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(c.conkey)
  362. WHERE c.conname = %s
  363. AND t.relname = ' . $db->quote($table, 'text');
  364. $fields = $db->queryCol(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null);
  365. if (MDB2::isError($fields)) {
  366. return $fields;
  367. }
  368. $colpos = 1;
  369. foreach ($fields as $field) {
  370. $definition['fields'][$field] = array(
  371. 'position' => $colpos++,
  372. 'sorting' => 'ascending',
  373. );
  374. }
  375. if ($definition['foreign']) {
  376. $query = 'SELECT a.attname
  377. FROM pg_constraint c
  378. LEFT JOIN pg_class t ON c.confrelid = t.oid
  379. LEFT JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(c.confkey)
  380. WHERE c.conname = %s
  381. AND t.relname = ' . $db->quote($definition['references']['table'], 'text');
  382. $foreign_fields = $db->queryCol(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null);
  383. if (MDB2::isError($foreign_fields)) {
  384. return $foreign_fields;
  385. }
  386. $colpos = 1;
  387. foreach ($foreign_fields as $foreign_field) {
  388. $definition['references']['fields'][$foreign_field] = array(
  389. 'position' => $colpos++,
  390. );
  391. }
  392. }
  393. if ($definition['check']) {
  394. $check_def = $db->queryOne("SELECT pg_get_constraintdef(" . $row['oid'] . ", 't')");
  395. // ...
  396. }
  397. return $definition;
  398. }
  399. // }}}
  400. // {{{ getTriggerDefinition()
  401. /**
  402. * Get the structure of a trigger into an array
  403. *
  404. * EXPERIMENTAL
  405. *
  406. * WARNING: this function is experimental and may change the returned value
  407. * at any time until labelled as non-experimental
  408. *
  409. * @param string $trigger name of trigger that should be used in method
  410. * @return mixed data array on success, a MDB2 error on failure
  411. * @access public
  412. *
  413. * @TODO: add support for plsql functions and functions with args
  414. */
  415. function getTriggerDefinition($trigger)
  416. {
  417. $db = $this->getDBInstance();
  418. if (MDB2::isError($db)) {
  419. return $db;
  420. }
  421. $query = "SELECT trg.tgname AS trigger_name,
  422. tbl.relname AS table_name,
  423. CASE
  424. WHEN p.proname IS NOT NULL THEN 'EXECUTE PROCEDURE ' || p.proname || '();'
  425. ELSE ''
  426. END AS trigger_body,
  427. CASE trg.tgtype & cast(2 as int2)
  428. WHEN 0 THEN 'AFTER'
  429. ELSE 'BEFORE'
  430. END AS trigger_type,
  431. CASE trg.tgtype & cast(28 as int2)
  432. WHEN 16 THEN 'UPDATE'
  433. WHEN 8 THEN 'DELETE'
  434. WHEN 4 THEN 'INSERT'
  435. WHEN 20 THEN 'INSERT, UPDATE'
  436. WHEN 28 THEN 'INSERT, UPDATE, DELETE'
  437. WHEN 24 THEN 'UPDATE, DELETE'
  438. WHEN 12 THEN 'INSERT, DELETE'
  439. END AS trigger_event,
  440. CASE trg.tgenabled
  441. WHEN 'O' THEN 't'
  442. ELSE trg.tgenabled
  443. END AS trigger_enabled,
  444. obj_description(trg.oid, 'pg_trigger') AS trigger_comment
  445. FROM pg_trigger trg,
  446. pg_class tbl,
  447. pg_proc p
  448. WHERE trg.tgrelid = tbl.oid
  449. AND trg.tgfoid = p.oid
  450. AND trg.tgname = ". $db->quote($trigger, 'text');
  451. $types = array(
  452. 'trigger_name' => 'text',
  453. 'table_name' => 'text',
  454. 'trigger_body' => 'text',
  455. 'trigger_type' => 'text',
  456. 'trigger_event' => 'text',
  457. 'trigger_comment' => 'text',
  458. 'trigger_enabled' => 'boolean',
  459. );
  460. return $db->queryRow($query, $types, MDB2_FETCHMODE_ASSOC);
  461. }
  462. // }}}
  463. // {{{ tableInfo()
  464. /**
  465. * Returns information about a table or a result set
  466. *
  467. * NOTE: only supports 'table' and 'flags' if <var>$result</var>
  468. * is a table name.
  469. *
  470. * @param object|string $result MDB2_result object from a query or a
  471. * string containing the name of a table.
  472. * While this also accepts a query result
  473. * resource identifier, this behavior is
  474. * deprecated.
  475. * @param int $mode a valid tableInfo mode
  476. *
  477. * @return array an associative array with the information requested.
  478. * A MDB2_Error object on failure.
  479. *
  480. * @see MDB2_Driver_Common::tableInfo()
  481. */
  482. function tableInfo($result, $mode = null)
  483. {
  484. if (is_string($result)) {
  485. return parent::tableInfo($result, $mode);
  486. }
  487. $db = $this->getDBInstance();
  488. if (MDB2::isError($db)) {
  489. return $db;
  490. }
  491. $resource = MDB2::isResultCommon($result) ? $result->getResource() : $result;
  492. if (!is_resource($resource)) {
  493. return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
  494. 'Could not generate result resource', __FUNCTION__);
  495. }
  496. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  497. if ($db->options['field_case'] == CASE_LOWER) {
  498. $case_func = 'strtolower';
  499. } else {
  500. $case_func = 'strtoupper';
  501. }
  502. } else {
  503. $case_func = 'strval';
  504. }
  505. $count = @pg_num_fields($resource);
  506. $res = array();
  507. if ($mode) {
  508. $res['num_fields'] = $count;
  509. }
  510. $db->loadModule('Datatype', null, true);
  511. for ($i = 0; $i < $count; $i++) {
  512. $res[$i] = array(
  513. 'table' => function_exists('pg_field_table') ? @pg_field_table($resource, $i) : '',
  514. 'name' => $case_func(@pg_field_name($resource, $i)),
  515. 'type' => @pg_field_type($resource, $i),
  516. 'length' => @pg_field_size($resource, $i),
  517. 'flags' => '',
  518. );
  519. $mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]);
  520. if (MDB2::isError($mdb2type_info)) {
  521. return $mdb2type_info;
  522. }
  523. $res[$i]['mdb2type'] = $mdb2type_info[0][0];
  524. if ($mode & MDB2_TABLEINFO_ORDER) {
  525. $res['order'][$res[$i]['name']] = $i;
  526. }
  527. if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
  528. $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
  529. }
  530. }
  531. return $res;
  532. }
  533. }
  534. ?>