MDB2
[ class tree: MDB2 ] [ index: MDB2 ] [ all elements ]

Source for file ibase.php

Documentation is available at ibase.php

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP versions 4 and 5                                                 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox,                 |
  6. // | Stig. S. Bakken, Lukas Smith, Frank M. Kromann, Lorenzo Alberton     |
  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. // | Author: Lorenzo Alberton <l.alberton@quipo.it>                       |
  43. // +----------------------------------------------------------------------+
  44. //
  45. // $Id: ibase.php,v 1.78 2007/11/25 13:38:29 quipo Exp $
  46. //
  47.  
  48. require_once 'MDB2/Driver/Reverse/Common.php';
  49.  
  50. /**
  51.  * MDB2 InterbaseBase driver for the reverse engineering module
  52.  *
  53.  * @package MDB2
  54.  * @category Database
  55.  * @author Lorenzo Alberton  <l.alberton@quipo.it>
  56.  */
  57. class MDB2_Driver_Reverse_ibase extends MDB2_Driver_Reverse_Common
  58. {
  59.     /**
  60.      * Array for converting constant values to text values
  61.      * @var    array 
  62.      * @access public
  63.      */
  64.     var $types = array(
  65.         7   => 'smallint',
  66.         8   => 'integer',
  67.         9   => 'quad',
  68.         10  => 'float',
  69.         11  => 'd_float',
  70.         12  => 'date',      //dialect 3 DATE
  71.         13  => 'time',
  72.         14  => 'char',
  73.         16  => 'int64',
  74.         27  => 'double',
  75.         35  => 'timestamp'//DATE in older versions
  76.         37  => 'varchar',
  77.         40  => 'cstring',
  78.         261 => 'blob',
  79.     );
  80.  
  81.     /**
  82.      * Array for converting constant values to text values
  83.      * @var    array 
  84.      * @access public
  85.      */
  86.     var $subtypes = array(
  87.         //char subtypes
  88.         14 => array(
  89.             0 => 'unspecified',
  90.             1 => 'fixed'//BINARY data
  91.         ),
  92.         //blob subtypes
  93.         261 => array(
  94.             0 => 'unspecified',
  95.             1 => 'text',
  96.             2 => 'BLR'//Binary Language Representation
  97.             3 => 'access control list',
  98.             4 => 'reserved for future use',
  99.             5 => 'encoded description of a table\'s current metadata',
  100.             6 => 'description of multi-database transaction that finished irregularly',
  101.         ),
  102.         //smallint subtypes
  103.         7 => array(
  104.             0 => 'RDB$FIELD_TYPE',
  105.             1 => 'numeric',
  106.             2 => 'decimal',
  107.         ),
  108.         //integer subtypes
  109.         8 => array(
  110.             0 => 'RDB$FIELD_TYPE',
  111.             1 => 'numeric',
  112.             2 => 'decimal',
  113.         ),
  114.         //int64 subtypes
  115.         16 => array(
  116.             0 => 'RDB$FIELD_TYPE',
  117.             1 => 'numeric',
  118.             2 => 'decimal',
  119.         ),
  120.     );
  121.  
  122.     // {{{ getTableFieldDefinition()
  123.  
  124.     /**
  125.      * Get the structure of a field into an array
  126.      *
  127.      * @param string $table_name name of table that should be used in method
  128.      * @param string $field_name name of field that should be used in method
  129.      * @return mixed data array on success, a MDB2 error on failure
  130.      * @access public
  131.      */
  132.     function getTableFieldDefinition($table_name$field_name)
  133.     {
  134.         $db =$this->getDBInstance();
  135.         if (PEAR::isError($db)) {
  136.             return $db;
  137.         }
  138.  
  139.         $result $db->loadModule('Datatype'nulltrue);
  140.         if (PEAR::isError($result)) {
  141.             return $result;
  142.         }
  143.  
  144.         list($schema$table$this->splitTableSchema($table_name);
  145.  
  146.         $table $db->quote(strtoupper($table)'text');
  147.         $field_name $db->quote(strtoupper($field_name)'text');
  148.         $query = "SELECT RDB\$RELATION_FIELDS.RDB\$FIELD_NAME AS name,
  149.                          RDB\$FIELDS.RDB\$FIELD_LENGTH AS \"length\",
  150.                          RDB\$FIELDS.RDB\$FIELD_PRECISION AS \"precision\",
  151.                          (RDB\$FIELDS.RDB\$FIELD_SCALE * -1) AS \"scale\",
  152.                          RDB\$FIELDS.RDB\$FIELD_TYPE AS field_type_code,
  153.                          RDB\$FIELDS.RDB\$FIELD_SUB_TYPE AS field_sub_type_code,
  154.                          RDB\$RELATION_FIELDS.RDB\$DESCRIPTION AS description,
  155.                          RDB\$RELATION_FIELDS.RDB\$NULL_FLAG AS null_flag,
  156.                          RDB\$FIELDS.RDB\$DEFAULT_SOURCE AS default_source
  157.                     FROM RDB\$FIELDS
  158.                LEFT JOIN RDB\$RELATION_FIELDS ON RDB\$FIELDS.RDB\$FIELD_NAME = RDB\$RELATION_FIELDS.RDB\$FIELD_SOURCE
  159.                    WHERE UPPER(RDB\$RELATION_FIELDS.RDB\$RELATION_NAME)=$table
  160.                      AND UPPER(RDB\$RELATION_FIELDS.RDB\$FIELD_NAME)=$field_name;";
  161.         $column $db->queryRow($querynullMDB2_FETCHMODE_ASSOC);
  162.         if (PEAR::isError($column)) {
  163.             return $column;
  164.         }
  165.         if (empty($column)) {
  166.             return $db->raiseError(MDB2_ERROR_NOT_FOUNDnullnull,
  167.                 'it was not specified an existing table column'__FUNCTION__);
  168.         }
  169.         $column array_change_key_case($columnCASE_LOWER);
  170.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  171.             if ($db->options['field_case'== CASE_LOWER{
  172.                 $column['name'strtolower($column['name']);
  173.             else {
  174.                 $column['name'strtoupper($column['name']);
  175.             }
  176.         }
  177.  
  178.         $column['type'array_key_exists((int)$column['field_type_code']$this->types)
  179.             ? $this->types[(int)$column['field_type_code']] 'undefined';
  180.         if ($column['field_sub_type_code']
  181.             && array_key_exists((int)$column['field_type_code']$this->subtypes)
  182.             && array_key_exists($column['field_sub_type_code']$this->subtypes[(int)$column['field_type_code']])
  183.         {
  184.             $column['field_sub_type'$this->subtypes[(int)$column['field_type_code']][$column['field_sub_type_code']];
  185.         else {
  186.             $column['field_sub_type'= null;
  187.         }
  188.         $mapped_datatype $db->datatype->mapNativeDatatype($column);
  189.         if (PEAR::isError($mapped_datatype)) {
  190.             return $mapped_datatype;
  191.         }
  192.         list($types$length$unsigned$fixed$mapped_datatype;
  193.         $notnull !empty($column['null_flag']);
  194.         $default $column['default_source'];
  195.         if (is_null($default&& $notnull{
  196.             $default ($types[0== 'integer'? 0 : '';
  197.         }
  198.  
  199.         $definition[0= array('notnull' => $notnull'nativetype' => $column['type']);
  200.         if (!is_null($length)) {
  201.             $definition[0]['length'$length;
  202.         }
  203.         if (!is_null($unsigned)) {
  204.             $definition[0]['unsigned'$unsigned;
  205.         }
  206.         if (!is_null($fixed)) {
  207.             $definition[0]['fixed'$fixed;
  208.         }
  209.         if ($default !== false{
  210.             $definition[0]['default'$default;
  211.         }
  212.         foreach ($types as $key => $type{
  213.             $definition[$key$definition[0];
  214.             if ($type == 'clob' || $type == 'blob'{
  215.                 unset($definition[$key]['default']);
  216.             }
  217.             $definition[$key]['type'$type;
  218.             $definition[$key]['mdb2type'$type;
  219.         }
  220.         return $definition;
  221.     }
  222.  
  223.     // }}}
  224.     // {{{ getTableIndexDefinition()
  225.  
  226.     /**
  227.      * Get the structure of an index into an array
  228.      *
  229.      * @param string $table_name name of table that should be used in method
  230.      * @param string $index_name name of index that should be used in method
  231.      * @return mixed data array on success, a MDB2 error on failure
  232.      * @access public
  233.      */
  234.     function getTableIndexDefinition($table_name$index_name$format_index_name = true)
  235.     {
  236.         $db =$this->getDBInstance();
  237.         if (PEAR::isError($db)) {
  238.             return $db;
  239.         }
  240.  
  241.         list($schema$table$this->splitTableSchema($table_name);
  242.  
  243.         $table $db->quote(strtoupper($table)'text');
  244.         $query = "SELECT RDB\$INDEX_SEGMENTS.RDB\$FIELD_NAME AS field_name,
  245.                          RDB\$INDICES.RDB\$DESCRIPTION AS description,
  246.                          (RDB\$INDEX_SEGMENTS.RDB\$FIELD_POSITION + 1) AS field_position
  247.                     FROM RDB\$INDEX_SEGMENTS
  248.                LEFT JOIN RDB\$INDICES ON RDB\$INDICES.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME
  249.                LEFT JOIN RDB\$RELATION_CONSTRAINTS ON RDB\$RELATION_CONSTRAINTS.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME
  250.                    WHERE UPPER(RDB\$INDICES.RDB\$RELATION_NAME)=$table
  251.                      AND UPPER(RDB\$INDICES.RDB\$INDEX_NAME)=%s
  252.                      AND RDB\$RELATION_CONSTRAINTS.RDB\$CONSTRAINT_TYPE IS NULL
  253.                 ORDER BY RDB\$INDEX_SEGMENTS.RDB\$FIELD_POSITION";
  254.         $index_name_mdb2 $db->quote(strtoupper($db->getIndexName($index_name))'text');
  255.         $result $db->queryRow(sprintf($query$index_name_mdb2));
  256.         if (!PEAR::isError($result&& !is_null($result)) {
  257.             // apply 'idxname_format' only if the query succeeded, otherwise
  258.             // fallback to the given $index_name, without transformation
  259.             $index_name $index_name_mdb2;
  260.         else {
  261.             $index_name $db->quote(strtoupper($index_name)'text');
  262.         }
  263.         $result $db->query(sprintf($query$index_name));
  264.         if (PEAR::isError($result)) {
  265.             return $result;
  266.         }
  267.         
  268.         $definition = array();
  269.         while (is_array($row $result->fetchRow(MDB2_FETCHMODE_ASSOC))) {
  270.             $row array_change_key_case($rowCASE_LOWER);
  271.             $column_name $row['field_name'];
  272.             if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  273.                 if ($db->options['field_case'== CASE_LOWER{
  274.                     $column_name strtolower($column_name);
  275.                 else {
  276.                     $column_name strtoupper($column_name);
  277.                 }
  278.             }
  279.             $definition['fields'][$column_name= array(
  280.                 'position' => (int)$row['field_position'],
  281.             );
  282.             /*
  283.             if (!empty($row['collation'])) {
  284.                 $definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'A'
  285.                     ? 'ascending' : 'descending');
  286.             }
  287.             */
  288.         }
  289.  
  290.         $result->free();
  291.         if (empty($definition)) {
  292.             return $db->raiseError(MDB2_ERROR_NOT_FOUNDnullnull,
  293.                 'it was not specified an existing table index'__FUNCTION__);
  294.         }
  295.         return $definition;
  296.     }
  297.  
  298.     // }}}
  299.     // {{{ getTableConstraintDefinition()
  300.  
  301.     /**
  302.      * Get the structure of a constraint into an array
  303.      *
  304.      * @param string $table_name      name of table that should be used in method
  305.      * @param string $constraint_name name of constraint that should be used in method
  306.      * @return mixed data array on success, a MDB2 error on failure
  307.      * @access public
  308.      */
  309.     function getTableConstraintDefinition($table_name$constraint_name)
  310.     {
  311.         $db =$this->getDBInstance();
  312.         if (PEAR::isError($db)) {
  313.             return $db;
  314.         }
  315.  
  316.         list($schema$table$this->splitTableSchema($table_name);
  317.         
  318.         $table $db->quote(strtoupper($table)'text');
  319.         $query = "SELECT rc.RDB\$CONSTRAINT_NAME,
  320.                          s.RDB\$FIELD_NAME AS field_name,
  321.                          CASE WHEN rc.RDB\$CONSTRAINT_TYPE = 'PRIMARY KEY' THEN 1 ELSE 0 END AS \"primary\",
  322.                          CASE WHEN rc.RDB\$CONSTRAINT_TYPE = 'FOREIGN KEY' THEN 1 ELSE 0 END AS \"foreign\",
  323.                          CASE WHEN rc.RDB\$CONSTRAINT_TYPE = 'UNIQUE'      THEN 1 ELSE 0 END AS \"unique\",
  324.                          CASE WHEN rc.RDB\$CONSTRAINT_TYPE = 'CHECK'       THEN 1 ELSE 0 END AS \"check\",
  325.                          i.RDB\$DESCRIPTION AS description,
  326.                          CASE WHEN rc.RDB\$DEFERRABLE = 'NO' THEN 0 ELSE 1 END AS deferrable,
  327.                          CASE WHEN rc.RDB\$INITIALLY_DEFERRED = 'NO' THEN 0 ELSE 1 END AS initiallydeferred,
  328.                          refc.RDB\$UPDATE_RULE AS onupdate,
  329.                          refc.RDB\$DELETE_RULE AS ondelete,
  330.                          refc.RDB\$MATCH_OPTION AS \"match\",
  331.                          i2.RDB\$RELATION_NAME AS references_table,
  332.                          s2.RDB\$FIELD_NAME AS references_field,
  333.                          (s.RDB\$FIELD_POSITION + 1) AS field_position
  334.                     FROM RDB\$INDEX_SEGMENTS s
  335.                LEFT JOIN RDB\$INDICES i ON i.RDB\$INDEX_NAME = s.RDB\$INDEX_NAME
  336.                LEFT JOIN RDB\$RELATION_CONSTRAINTS rc ON rc.RDB\$INDEX_NAME = s.RDB\$INDEX_NAME
  337.                LEFT JOIN RDB\$REF_CONSTRAINTS refc ON rc.RDB\$CONSTRAINT_NAME = refc.RDB\$CONSTRAINT_NAME
  338.                LEFT JOIN RDB\$RELATION_CONSTRAINTS rc2 ON rc2.RDB\$CONSTRAINT_NAME = refc.RDB\$CONST_NAME_UQ
  339.                LEFT JOIN RDB\$INDICES i2 ON i2.RDB\$INDEX_NAME = rc2.RDB\$INDEX_NAME
  340.                LEFT JOIN RDB\$INDEX_SEGMENTS s2 ON i2.RDB\$INDEX_NAME = s2.RDB\$INDEX_NAME
  341.                      AND s.RDB\$FIELD_POSITION = s2.RDB\$FIELD_POSITION
  342.                    WHERE UPPER(i.RDB\$RELATION_NAME)=$table
  343.                      AND UPPER(rc.RDB\$CONSTRAINT_NAME)=%s
  344.                      AND rc.RDB\$CONSTRAINT_TYPE IS NOT NULL
  345.                 ORDER BY s.RDB\$FIELD_POSITION";
  346.         $constraint_name_mdb2 $db->quote(strtoupper($db->getIndexName($constraint_name))'text');
  347.         $result $db->queryRow(sprintf($query$constraint_name_mdb2));
  348.         if (!PEAR::isError($result&& !is_null($result)) {
  349.             // apply 'idxname_format' only if the query succeeded, otherwise
  350.             // fallback to the given $index_name, without transformation
  351.             $constraint_name $constraint_name_mdb2;
  352.         else {
  353.             $constraint_name $db->quote(strtoupper($constraint_name)'text');
  354.         }
  355.         $result $db->query(sprintf($query$constraint_name));
  356.         if (PEAR::isError($result)) {
  357.             return $result;
  358.         }
  359.         
  360.         $definition = array();
  361.         while (is_array($row $result->fetchRow(MDB2_FETCHMODE_ASSOC))) {
  362.             $row array_change_key_case($rowCASE_LOWER);
  363.             $column_name $row['field_name'];
  364.             if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  365.                 if ($db->options['field_case'== CASE_LOWER{
  366.                     $column_name strtolower($column_name);
  367.                 else {
  368.                     $column_name strtoupper($column_name);
  369.                 }
  370.             }
  371.             $definition['fields'][$column_name= array(
  372.                 'position' => (int)$row['field_position']
  373.             );
  374.             if ($row['foreign']{
  375.                 $ref_column_name $row['references_field'];
  376.                 $ref_table_name  $row['references_table'];
  377.                 if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  378.                     if ($db->options['field_case'== CASE_LOWER{
  379.                         $ref_column_name strtolower($ref_column_name);
  380.                         $ref_table_name  strtolower($ref_table_name);
  381.                     else {
  382.                         $ref_column_name strtoupper($ref_column_name);
  383.                         $ref_table_name  strtoupper($ref_table_name);
  384.                     }
  385.                 }
  386.                 $definition['references']['table'$ref_table_name;
  387.                 $definition['references']['fields'][$ref_column_name= array(
  388.                     'position' => (int)$row['field_position']
  389.                 );
  390.             }
  391.             //collation?!?
  392.             /*
  393.             if (!empty($row['collation'])) {
  394.                 $definition['fields'][$field]['sorting'] = ($row['collation'] == 'A'
  395.                     ? 'ascending' : 'descending');
  396.             }
  397.             */
  398.             $lastrow $row;
  399.             // otherwise $row is no longer usable on exit from loop
  400.         }
  401.         $result->free();
  402.         if (empty($definition)) {
  403.             return $db->raiseError(MDB2_ERROR_NOT_FOUNDnullnull,
  404.                 $constraint_name ' is not an existing table constraint'__FUNCTION__);
  405.         }
  406.         
  407.         $definition['primary'= (boolean)$lastrow['primary'];
  408.         $definition['unique']  = (boolean)$lastrow['unique'];
  409.         $definition['foreign'= (boolean)$lastrow['foreign'];
  410.         $definition['check']   = (boolean)$lastrow['check'];
  411.         $definition['deferrable'= (boolean)$lastrow['deferrable'];
  412.         $definition['initiallydeferred'= (boolean)$lastrow['initiallydeferred'];
  413.         $definition['onupdate'$lastrow['onupdate'];
  414.         $definition['ondelete'$lastrow['ondelete'];
  415.         $definition['match']    $lastrow['match'];
  416.         
  417.         return $definition;
  418.     }
  419.  
  420.     // }}}
  421.     // {{{ getTriggerDefinition()
  422.  
  423.     /**
  424.      * Get the structure of a trigger into an array
  425.      *
  426.      * EXPERIMENTAL
  427.      *
  428.      * WARNING: this function is experimental and may change the returned value
  429.      * at any time until labelled as non-experimental
  430.      *
  431.      * @param string    $trigger    name of trigger that should be used in method
  432.      * @return mixed data array on success, a MDB2 error on failure
  433.      * @access public
  434.      */
  435.     function getTriggerDefinition($trigger)
  436.     {
  437.         $db =$this->getDBInstance();
  438.         if (PEAR::isError($db)) {
  439.             return $db;
  440.         }
  441.  
  442.         $trigger $db->quote(strtoupper($trigger)'text');
  443.         $query = "SELECT RDB\$TRIGGER_NAME AS trigger_name,
  444.                          RDB\$RELATION_NAME AS table_name,
  445.                          RDB\$TRIGGER_SOURCE AS trigger_body,
  446.                          CASE RDB\$TRIGGER_TYPE
  447.                             WHEN 1 THEN 'BEFORE'
  448.                             WHEN 2 THEN 'AFTER'
  449.                             WHEN 3 THEN 'BEFORE'
  450.                             WHEN 4 THEN 'AFTER'
  451.                             WHEN 5 THEN 'BEFORE'
  452.                             WHEN 6 THEN 'AFTER'
  453.                          END AS trigger_type,
  454.                          CASE RDB\$TRIGGER_TYPE
  455.                             WHEN 1 THEN 'INSERT'
  456.                             WHEN 2 THEN 'INSERT'
  457.                             WHEN 3 THEN 'UPDATE'
  458.                             WHEN 4 THEN 'UPDATE'
  459.                             WHEN 5 THEN 'DELETE'
  460.                             WHEN 6 THEN 'DELETE'
  461.                          END AS trigger_event,
  462.                          CASE RDB\$TRIGGER_INACTIVE
  463.                             WHEN 1 THEN 0 ELSE 1
  464.                          END AS trigger_enabled,
  465.                          RDB\$DESCRIPTION AS trigger_comment
  466.                     FROM RDB\$TRIGGERS
  467.                    WHERE UPPER(RDB\$TRIGGER_NAME)=$trigger";
  468.         $types = array(
  469.             'trigger_name'    => 'text',
  470.             'table_name'      => 'text',
  471.             'trigger_body'    => 'clob',
  472.             'trigger_type'    => 'text',
  473.             'trigger_event'   => 'text',
  474.             'trigger_comment' => 'text',
  475.             'trigger_enabled' => 'boolean',
  476.         );
  477.  
  478.         $def $db->queryRow($query$typesMDB2_FETCHMODE_ASSOC);
  479.         if (PEAR::isError($def)) {
  480.             return $def;
  481.         }
  482.  
  483.         $clob $def['trigger_body'];
  484.         if (!PEAR::isError($clob&& is_resource($clob)) {
  485.             $value '';
  486.             while (!feof($clob)) {
  487.                 $data fread($clob8192);
  488.                 $value.= $data;
  489.             }
  490.             $db->datatype->destroyLOB($clob);
  491.             $def['trigger_body'$value;
  492.         }
  493.  
  494.         return $def;
  495.     }
  496.  
  497.     // }}}
  498.     // {{{ tableInfo()
  499.  
  500.     /**
  501.      * Returns information about a table or a result set
  502.      *
  503.      * NOTE: only supports 'table' and 'flags' if <var>$result</var>
  504.      * is a table name.
  505.      *
  506.      * @param object|string $result  MDB2_result object from a query or a
  507.      *                                  string containing the name of a table.
  508.      *                                  While this also accepts a query result
  509.      *                                  resource identifier, this behavior is
  510.      *                                  deprecated.
  511.      * @param int            $mode    a valid tableInfo mode
  512.      *
  513.      * @return array  an associative array with the information requested.
  514.      *                  A MDB2_Error object on failure.
  515.      *
  516.      * @see MDB2_Driver_Common::tableInfo()
  517.      */
  518.     function tableInfo($result$mode = null)
  519.     {
  520.         if (is_string($result)) {
  521.            return parent::tableInfo($result$mode);
  522.         }
  523.  
  524.         $db =$this->getDBInstance();
  525.         if (PEAR::isError($db)) {
  526.             return $db;
  527.         }
  528.  
  529.         $resource = MDB2::isResultCommon($result$result->getResource($result;
  530.         if (!is_resource($resource)) {
  531.             return $db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  532.                 'Could not generate result resource'__FUNCTION__);
  533.         }
  534.  
  535.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  536.             if ($db->options['field_case'== CASE_LOWER{
  537.                 $case_func 'strtolower';
  538.             else {
  539.                 $case_func 'strtoupper';
  540.             }
  541.         else {
  542.             $case_func 'strval';
  543.         }
  544.  
  545.         $count @ibase_num_fields($resource);
  546.         $res   = array();
  547.  
  548.         if ($mode{
  549.             $res['num_fields'$count;
  550.         }
  551.  
  552.         $db->loadModule('Datatype'nulltrue);
  553.         for ($i = 0; $i $count$i++{
  554.             $info @ibase_field_info($resource$i);
  555.             if (($pos strpos($info['type']'(')) !== false{
  556.                 $info['type'substr($info['type']0$pos);
  557.             }
  558.             $res[$i= array(
  559.                 'table'  => $case_func($info['relation']),
  560.                 'name'   => $case_func($info['name']),
  561.                 'type'   => $info['type'],
  562.                 'length' => $info['length'],
  563.                 'flags'  => '',
  564.             );
  565.             $mdb2type_info $db->datatype->mapNativeDatatype($res[$i]);
  566.             if (PEAR::isError($mdb2type_info)) {
  567.                return $mdb2type_info;
  568.             }
  569.             $res[$i]['mdb2type'$mdb2type_info[0][0];
  570.             if ($mode MDB2_TABLEINFO_ORDER{
  571.                 $res['order'][$res[$i]['name']] $i;
  572.             }
  573.             if ($mode MDB2_TABLEINFO_ORDERTABLE{
  574.                 $res['ordertable'][$res[$i]['table']][$res[$i]['name']] $i;
  575.             }
  576.         }
  577.  
  578.         return $res;
  579.     }
  580. }
  581. ?>

Documentation generated on Mon, 11 Mar 2019 15:11:58 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.