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 327310 2012-08-27 15:16:18Z danielc $
  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 (MDB2::isError($db)) {
  136.             return $db;
  137.         }
  138.  
  139.         $result $db->loadModule('Datatype'nulltrue);
  140.         if (MDB2::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.                          RDB\$CHARACTER_SETS.RDB\$CHARACTER_SET_NAME AS \"charset\",
  158.                          RDB\$COLLATIONS.RDB\$COLLATION_NAME AS \"collation\"
  159.                     FROM RDB\$FIELDS
  160.                LEFT JOIN RDB\$RELATION_FIELDS ON RDB\$FIELDS.RDB\$FIELD_NAME = RDB\$RELATION_FIELDS.RDB\$FIELD_SOURCE
  161.                LEFT JOIN RDB\$CHARACTER_SETS ON RDB\$FIELDS.RDB\$CHARACTER_SET_ID = RDB\$CHARACTER_SETS.RDB\$CHARACTER_SET_ID
  162.                LEFT JOIN RDB\$COLLATIONS ON RDB\$FIELDS.RDB\$COLLATION_ID = RDB\$COLLATIONS.RDB\$COLLATION_ID
  163.                    WHERE UPPER(RDB\$RELATION_FIELDS.RDB\$RELATION_NAME)=$table
  164.                      AND UPPER(RDB\$RELATION_FIELDS.RDB\$FIELD_NAME)=$field_name;";
  165.         $column $db->queryRow($querynullMDB2_FETCHMODE_ASSOC);
  166.         if (MDB2::isError($column)) {
  167.             return $column;
  168.         }
  169.         if (empty($column)) {
  170.             return $db->raiseError(MDB2_ERROR_NOT_FOUNDnullnull,
  171.                 'it was not specified an existing table column'__FUNCTION__);
  172.         }
  173.         $column array_change_key_case($columnCASE_LOWER);
  174.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  175.             if ($db->options['field_case'== CASE_LOWER{
  176.                 $column['name'strtolower($column['name']);
  177.             else {
  178.                 $column['name'strtoupper($column['name']);
  179.             }
  180.         }
  181.  
  182.         $column['type'array_key_exists((int)$column['field_type_code']$this->types)
  183.             ? $this->types[(int)$column['field_type_code']] 'undefined';
  184.         if ($column['field_sub_type_code']
  185.             && array_key_exists((int)$column['field_type_code']$this->subtypes)
  186.             && array_key_exists($column['field_sub_type_code']$this->subtypes[(int)$column['field_type_code']])
  187.         {
  188.             $column['field_sub_type'$this->subtypes[(int)$column['field_type_code']][$column['field_sub_type_code']];
  189.         else {
  190.             $column['field_sub_type'= null;
  191.         }
  192.         $mapped_datatype $db->datatype->mapNativeDatatype($column);
  193.         if (MDB2::isError($mapped_datatype)) {
  194.             return $mapped_datatype;
  195.         }
  196.         list($types$length$unsigned$fixed$mapped_datatype;
  197.         $notnull !empty($column['null_flag']);
  198.         $default $column['default_source'];
  199.         if ((null === $default&& $notnull{
  200.             $default ($types[0== 'integer'? 0 : '';
  201.         }
  202.  
  203.         $definition[0= array(
  204.             'notnull'    => $notnull,
  205.             'nativetype' => $column['type'],
  206.             'charset'    => $column['charset'],
  207.             'collation'  => $column['collation'],
  208.         );
  209.         if (null !== $length{
  210.             $definition[0]['length'$length;
  211.         }
  212.         if (null !== $unsigned{
  213.             $definition[0]['unsigned'$unsigned;
  214.         }
  215.         if (null !== $fixed{
  216.             $definition[0]['fixed'$fixed;
  217.         }
  218.         if (false !== $default{
  219.             $definition[0]['default'$default;
  220.         }
  221.         foreach ($types as $key => $type{
  222.             $definition[$key$definition[0];
  223.             if ($type == 'clob' || $type == 'blob'{
  224.                 unset($definition[$key]['default']);
  225.             }
  226.             $definition[$key]['type'$type;
  227.             $definition[$key]['mdb2type'$type;
  228.         }
  229.         return $definition;
  230.     }
  231.  
  232.     // }}}
  233.     // {{{ getTableIndexDefinition()
  234.  
  235.     /**
  236.      * Get the structure of an index into an array
  237.      *
  238.      * @param string $table_name name of table that should be used in method
  239.      * @param string $index_name name of index that should be used in method
  240.      * @return mixed data array on success, a MDB2 error on failure
  241.      * @access public
  242.      */
  243.     function getTableIndexDefinition($table_name$index_name$format_index_name = true)
  244.     {
  245.         $db $this->getDBInstance();
  246.         if (MDB2::isError($db)) {
  247.             return $db;
  248.         }
  249.  
  250.         list($schema$table$this->splitTableSchema($table_name);
  251.  
  252.         $table $db->quote(strtoupper($table)'text');
  253.         $query = "SELECT RDB\$INDEX_SEGMENTS.RDB\$FIELD_NAME AS field_name,
  254.                          RDB\$INDICES.RDB\$DESCRIPTION AS description,
  255.                          (RDB\$INDEX_SEGMENTS.RDB\$FIELD_POSITION + 1) AS field_position
  256.                     FROM RDB\$INDEX_SEGMENTS
  257.                LEFT JOIN RDB\$INDICES ON RDB\$INDICES.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME
  258.                LEFT JOIN RDB\$RELATION_CONSTRAINTS ON RDB\$RELATION_CONSTRAINTS.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME
  259.                    WHERE UPPER(RDB\$INDICES.RDB\$RELATION_NAME)=$table
  260.                      AND UPPER(RDB\$INDICES.RDB\$INDEX_NAME)=%s
  261.                      AND RDB\$RELATION_CONSTRAINTS.RDB\$CONSTRAINT_TYPE IS NULL
  262.                 ORDER BY RDB\$INDEX_SEGMENTS.RDB\$FIELD_POSITION";
  263.         $index_name_mdb2 $db->quote(strtoupper($db->getIndexName($index_name))'text');
  264.         $result $db->queryRow(sprintf($query$index_name_mdb2));
  265.         if (!MDB2::isError($result&& (null !== $result)) {
  266.             // apply 'idxname_format' only if the query succeeded, otherwise
  267.             // fallback to the given $index_name, without transformation
  268.             $index_name $index_name_mdb2;
  269.         else {
  270.             $index_name $db->quote(strtoupper($index_name)'text');
  271.         }
  272.         $result $db->query(sprintf($query$index_name));
  273.         if (MDB2::isError($result)) {
  274.             return $result;
  275.         }
  276.         
  277.         $definition = array();
  278.         while (is_array($row $result->fetchRow(MDB2_FETCHMODE_ASSOC))) {
  279.             $row array_change_key_case($rowCASE_LOWER);
  280.             $column_name $row['field_name'];
  281.             if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  282.                 if ($db->options['field_case'== CASE_LOWER{
  283.                     $column_name strtolower($column_name);
  284.                 else {
  285.                     $column_name strtoupper($column_name);
  286.                 }
  287.             }
  288.             $definition['fields'][$column_name= array(
  289.                 'position' => (int)$row['field_position'],
  290.             );
  291.             /*
  292.             if (!empty($row['collation'])) {
  293.                 $definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'A'
  294.                     ? 'ascending' : 'descending');
  295.             }
  296.             */
  297.         }
  298.  
  299.         $result->free();
  300.         if (empty($definition)) {
  301.             return $db->raiseError(MDB2_ERROR_NOT_FOUNDnullnull,
  302.                 'it was not specified an existing table index'__FUNCTION__);
  303.         }
  304.         return $definition;
  305.     }
  306.  
  307.     // }}}
  308.     // {{{ getTableConstraintDefinition()
  309.  
  310.     /**
  311.      * Get the structure of a constraint into an array
  312.      *
  313.      * @param string $table_name      name of table that should be used in method
  314.      * @param string $constraint_name name of constraint that should be used in method
  315.      * @return mixed data array on success, a MDB2 error on failure
  316.      * @access public
  317.      */
  318.     function getTableConstraintDefinition($table_name$constraint_name)
  319.     {
  320.         $db $this->getDBInstance();
  321.         if (MDB2::isError($db)) {
  322.             return $db;
  323.         }
  324.  
  325.         list($schema$table$this->splitTableSchema($table_name);
  326.         
  327.         $table $db->quote(strtoupper($table)'text');
  328.         $query = "SELECT rc.RDB\$CONSTRAINT_NAME,
  329.                          s.RDB\$FIELD_NAME AS field_name,
  330.                          CASE WHEN rc.RDB\$CONSTRAINT_TYPE = 'PRIMARY KEY' THEN 1 ELSE 0 END AS \"primary\",
  331.                          CASE WHEN rc.RDB\$CONSTRAINT_TYPE = 'FOREIGN KEY' THEN 1 ELSE 0 END AS \"foreign\",
  332.                          CASE WHEN rc.RDB\$CONSTRAINT_TYPE = 'UNIQUE'      THEN 1 ELSE 0 END AS \"unique\",
  333.                          CASE WHEN rc.RDB\$CONSTRAINT_TYPE = 'CHECK'       THEN 1 ELSE 0 END AS \"check\",
  334.                          i.RDB\$DESCRIPTION AS description,
  335.                          CASE WHEN rc.RDB\$DEFERRABLE = 'NO' THEN 0 ELSE 1 END AS deferrable,
  336.                          CASE WHEN rc.RDB\$INITIALLY_DEFERRED = 'NO' THEN 0 ELSE 1 END AS initiallydeferred,
  337.                          refc.RDB\$UPDATE_RULE AS onupdate,
  338.                          refc.RDB\$DELETE_RULE AS ondelete,
  339.                          refc.RDB\$MATCH_OPTION AS \"match\",
  340.                          i2.RDB\$RELATION_NAME AS references_table,
  341.                          s2.RDB\$FIELD_NAME AS references_field,
  342.                          (s.RDB\$FIELD_POSITION + 1) AS field_position
  343.                     FROM RDB\$INDEX_SEGMENTS s
  344.                LEFT JOIN RDB\$INDICES i ON i.RDB\$INDEX_NAME = s.RDB\$INDEX_NAME
  345.                LEFT JOIN RDB\$RELATION_CONSTRAINTS rc ON rc.RDB\$INDEX_NAME = s.RDB\$INDEX_NAME
  346.                LEFT JOIN RDB\$REF_CONSTRAINTS refc ON rc.RDB\$CONSTRAINT_NAME = refc.RDB\$CONSTRAINT_NAME
  347.                LEFT JOIN RDB\$RELATION_CONSTRAINTS rc2 ON rc2.RDB\$CONSTRAINT_NAME = refc.RDB\$CONST_NAME_UQ
  348.                LEFT JOIN RDB\$INDICES i2 ON i2.RDB\$INDEX_NAME = rc2.RDB\$INDEX_NAME
  349.                LEFT JOIN RDB\$INDEX_SEGMENTS s2 ON i2.RDB\$INDEX_NAME = s2.RDB\$INDEX_NAME
  350.                      AND s.RDB\$FIELD_POSITION = s2.RDB\$FIELD_POSITION
  351.                    WHERE UPPER(i.RDB\$RELATION_NAME)=$table
  352.                      AND UPPER(rc.RDB\$CONSTRAINT_NAME)=%s
  353.                      AND rc.RDB\$CONSTRAINT_TYPE IS NOT NULL
  354.                 ORDER BY s.RDB\$FIELD_POSITION";
  355.         $constraint_name_mdb2 $db->quote(strtoupper($db->getIndexName($constraint_name))'text');
  356.         $result $db->queryRow(sprintf($query$constraint_name_mdb2));
  357.         if (!MDB2::isError($result&& (null !== $result)) {
  358.             // apply 'idxname_format' only if the query succeeded, otherwise
  359.             // fallback to the given $index_name, without transformation
  360.             $constraint_name $constraint_name_mdb2;
  361.         else {
  362.             $constraint_name $db->quote(strtoupper($constraint_name)'text');
  363.         }
  364.         $result $db->query(sprintf($query$constraint_name));
  365.         if (MDB2::isError($result)) {
  366.             return $result;
  367.         }
  368.         
  369.         $definition = array();
  370.         while (is_array($row $result->fetchRow(MDB2_FETCHMODE_ASSOC))) {
  371.             $row array_change_key_case($rowCASE_LOWER);
  372.             $column_name $row['field_name'];
  373.             if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  374.                 if ($db->options['field_case'== CASE_LOWER{
  375.                     $column_name strtolower($column_name);
  376.                 else {
  377.                     $column_name strtoupper($column_name);
  378.                 }
  379.             }
  380.             $definition['fields'][$column_name= array(
  381.                 'position' => (int)$row['field_position']
  382.             );
  383.             if ($row['foreign']{
  384.                 $ref_column_name $row['references_field'];
  385.                 $ref_table_name  $row['references_table'];
  386.                 if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  387.                     if ($db->options['field_case'== CASE_LOWER{
  388.                         $ref_column_name strtolower($ref_column_name);
  389.                         $ref_table_name  strtolower($ref_table_name);
  390.                     else {
  391.                         $ref_column_name strtoupper($ref_column_name);
  392.                         $ref_table_name  strtoupper($ref_table_name);
  393.                     }
  394.                 }
  395.                 $definition['references']['table'$ref_table_name;
  396.                 $definition['references']['fields'][$ref_column_name= array(
  397.                     'position' => (int)$row['field_position']
  398.                 );
  399.             }
  400.             //collation?!?
  401.             /*
  402.             if (!empty($row['collation'])) {
  403.                 $definition['fields'][$field]['sorting'] = ($row['collation'] == 'A'
  404.                     ? 'ascending' : 'descending');
  405.             }
  406.             */
  407.             $lastrow $row;
  408.             // otherwise $row is no longer usable on exit from loop
  409.         }
  410.         $result->free();
  411.         if (empty($definition)) {
  412.             return $db->raiseError(MDB2_ERROR_NOT_FOUNDnullnull,
  413.                 $constraint_name ' is not an existing table constraint'__FUNCTION__);
  414.         }
  415.         
  416.         $definition['primary'= (boolean)$lastrow['primary'];
  417.         $definition['unique']  = (boolean)$lastrow['unique'];
  418.         $definition['foreign'= (boolean)$lastrow['foreign'];
  419.         $definition['check']   = (boolean)$lastrow['check'];
  420.         $definition['deferrable'= (boolean)$lastrow['deferrable'];
  421.         $definition['initiallydeferred'= (boolean)$lastrow['initiallydeferred'];
  422.         $definition['onupdate'$lastrow['onupdate'];
  423.         $definition['ondelete'$lastrow['ondelete'];
  424.         $definition['match']    $lastrow['match'];
  425.         
  426.         return $definition;
  427.     }
  428.  
  429.     // }}}
  430.     // {{{ getTriggerDefinition()
  431.  
  432.     /**
  433.      * Get the structure of a trigger into an array
  434.      *
  435.      * EXPERIMENTAL
  436.      *
  437.      * WARNING: this function is experimental and may change the returned value
  438.      * at any time until labelled as non-experimental
  439.      *
  440.      * @param string    $trigger    name of trigger that should be used in method
  441.      * @return mixed data array on success, a MDB2 error on failure
  442.      * @access public
  443.      */
  444.     function getTriggerDefinition($trigger)
  445.     {
  446.         $db $this->getDBInstance();
  447.         if (MDB2::isError($db)) {
  448.             return $db;
  449.         }
  450.  
  451.         $trigger $db->quote(strtoupper($trigger)'text');
  452.         $query = "SELECT RDB\$TRIGGER_NAME AS trigger_name,
  453.                          RDB\$RELATION_NAME AS table_name,
  454.                          RDB\$TRIGGER_SOURCE AS trigger_body,
  455.                          CASE RDB\$TRIGGER_TYPE
  456.                             WHEN 1 THEN 'BEFORE'
  457.                             WHEN 2 THEN 'AFTER'
  458.                             WHEN 3 THEN 'BEFORE'
  459.                             WHEN 4 THEN 'AFTER'
  460.                             WHEN 5 THEN 'BEFORE'
  461.                             WHEN 6 THEN 'AFTER'
  462.                          END AS trigger_type,
  463.                          CASE RDB\$TRIGGER_TYPE
  464.                             WHEN 1 THEN 'INSERT'
  465.                             WHEN 2 THEN 'INSERT'
  466.                             WHEN 3 THEN 'UPDATE'
  467.                             WHEN 4 THEN 'UPDATE'
  468.                             WHEN 5 THEN 'DELETE'
  469.                             WHEN 6 THEN 'DELETE'
  470.                          END AS trigger_event,
  471.                          CASE RDB\$TRIGGER_INACTIVE
  472.                             WHEN 1 THEN 0 ELSE 1
  473.                          END AS trigger_enabled,
  474.                          RDB\$DESCRIPTION AS trigger_comment
  475.                     FROM RDB\$TRIGGERS
  476.                    WHERE UPPER(RDB\$TRIGGER_NAME)=$trigger";
  477.         $types = array(
  478.             'trigger_name'    => 'text',
  479.             'table_name'      => 'text',
  480.             'trigger_body'    => 'clob',
  481.             'trigger_type'    => 'text',
  482.             'trigger_event'   => 'text',
  483.             'trigger_comment' => 'text',
  484.             'trigger_enabled' => 'boolean',
  485.         );
  486.  
  487.         $def $db->queryRow($query$typesMDB2_FETCHMODE_ASSOC);
  488.         if (MDB2::isError($def)) {
  489.             return $def;
  490.         }
  491.  
  492.         $clob $def['trigger_body'];
  493.         if (!MDB2::isError($clob&& is_resource($clob)) {
  494.             $value '';
  495.             while (!feof($clob)) {
  496.                 $data fread($clob8192);
  497.                 $value.= $data;
  498.             }
  499.             $db->datatype->destroyLOB($clob);
  500.             $def['trigger_body'$value;
  501.         }
  502.  
  503.         return $def;
  504.     }
  505.  
  506.     // }}}
  507.     // {{{ tableInfo()
  508.  
  509.     /**
  510.      * Returns information about a table or a result set
  511.      *
  512.      * NOTE: only supports 'table' and 'flags' if <var>$result</var>
  513.      * is a table name.
  514.      *
  515.      * @param object|string $result  MDB2_result object from a query or a
  516.      *                                  string containing the name of a table.
  517.      *                                  While this also accepts a query result
  518.      *                                  resource identifier, this behavior is
  519.      *                                  deprecated.
  520.      * @param int            $mode    a valid tableInfo mode
  521.      *
  522.      * @return array  an associative array with the information requested.
  523.      *                  A MDB2_Error object on failure.
  524.      *
  525.      * @see MDB2_Driver_Common::tableInfo()
  526.      */
  527.     function tableInfo($result$mode = null)
  528.     {
  529.         if (is_string($result)) {
  530.            return parent::tableInfo($result$mode);
  531.         }
  532.  
  533.         $db $this->getDBInstance();
  534.         if (MDB2::isError($db)) {
  535.             return $db;
  536.         }
  537.  
  538.         $resource = MDB2::isResultCommon($result$result->getResource($result;
  539.         if (!is_resource($resource)) {
  540.             return $db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  541.                 'Could not generate result resource'__FUNCTION__);
  542.         }
  543.  
  544.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  545.             if ($db->options['field_case'== CASE_LOWER{
  546.                 $case_func 'strtolower';
  547.             else {
  548.                 $case_func 'strtoupper';
  549.             }
  550.         else {
  551.             $case_func 'strval';
  552.         }
  553.  
  554.         $count @ibase_num_fields($resource);
  555.         $res   = array();
  556.  
  557.         if ($mode{
  558.             $res['num_fields'$count;
  559.         }
  560.  
  561.         $db->loadModule('Datatype'nulltrue);
  562.         for ($i = 0; $i $count$i++{
  563.             $info @ibase_field_info($resource$i);
  564.             if (($pos strpos($info['type']'(')) !== false{
  565.                 $info['type'substr($info['type']0$pos);
  566.             }
  567.             $res[$i= array(
  568.                 'table'  => $case_func($info['relation']),
  569.                 'name'   => $case_func($info['name']),
  570.                 'type'   => $info['type'],
  571.                 'length' => $info['length'],
  572.                 'flags'  => '',
  573.             );
  574.             $mdb2type_info $db->datatype->mapNativeDatatype($res[$i]);
  575.             if (MDB2::isError($mdb2type_info)) {
  576.                return $mdb2type_info;
  577.             }
  578.             $res[$i]['mdb2type'$mdb2type_info[0][0];
  579.             if ($mode MDB2_TABLEINFO_ORDER{
  580.                 $res['order'][$res[$i]['name']] $i;
  581.             }
  582.             if ($mode MDB2_TABLEINFO_ORDERTABLE{
  583.                 $res['ordertable'][$res[$i]['table']][$res[$i]['name']] $i;
  584.             }
  585.         }
  586.  
  587.         return $res;
  588.     }
  589. }
  590. ?>

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