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-2004 Manuel Lemos, Tomas V.V.Cox,                 |
  6. // | Stig. S. Bakken, Lukas Smith, Frank M. Kromann                       |
  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: Lukas Smith <smith@backendmedia.com>                         |
  43. // +----------------------------------------------------------------------+
  44. //
  45. // $Id: ibase.php,v 1.13 2005/04/19 12:53:42 lsmith 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  Lukas Smith <smith@dybnet.de>
  56.  */
  57. {
  58.     // }}}
  59.     // {{{ tableInfo()
  60.  
  61.     /**
  62.      * Returns information about a table or a result set
  63.      *
  64.      * NOTE: only supports 'table' and 'flags' if <var>$result</var>
  65.      * is a table name.
  66.      *
  67.      * @param object|string $result  MDB2_result object from a query or a
  68.      *                                  string containing the name of a table.
  69.      *                                  While this also accepts a query result
  70.      *                                  resource identifier, this behavior is
  71.      *                                  deprecated.
  72.      * @param int            $mode    a valid tableInfo mode
  73.      *
  74.      * @return array  an associative array with the information requested.
  75.      *                  A MDB2_Error object on failure.
  76.      *
  77.      * @see MDB2_common::tableInfo()
  78.      */
  79.     function tableInfo($result$mode = null)
  80.     {
  81.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  82.         if (is_string($result)) {
  83.             /*
  84.              * Probably received a table name.
  85.              * Create a result resource identifier.
  86.              */
  87.             $id $db->_doQuery("SELECT * FROM $result WHERE 1=0");
  88.             if (PEAR::isError($id)) {
  89.                 return $id;
  90.             }
  91.             $got_string = true;
  92.         elseif (MDB2::isResultCommon($result)) {
  93.             /*
  94.              * Probably received a result object.
  95.              * Extract the result resource identifier.
  96.              */
  97.             $id $result->getResource();
  98.             $got_string = false;
  99.         else {
  100.             /*
  101.              * Probably received a result resource identifier.
  102.              * Copy it.
  103.              * Deprecated.  Here for compatibility only.
  104.              */
  105.             $id $result;
  106.             $got_string = false;
  107.         }
  108.  
  109.         if (!is_resource($id)) {
  110.             return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA);
  111.         }
  112.  
  113.         if ($db->options['portability'MDB2_PORTABILITY_LOWERCASE{
  114.             $case_func 'strtolower';
  115.         else {
  116.             $case_func 'strval';
  117.         }
  118.  
  119.         $count @ibase_num_fields($id);
  120.         $res   = array();
  121.  
  122.         if ($mode{
  123.             $res['num_fields'$count;
  124.         }
  125.  
  126.         for ($i = 0; $i $count$i++{
  127.             $info @ibase_field_info($id$i);
  128.             $res[$i= array(
  129.                 'table' => $got_string $case_func($result'',
  130.                 'name'  => $case_func($info['name']),
  131.                 'type'  => $info['type'],
  132.                 'len'   => $info['length'],
  133.                 'flags' => ($got_string)
  134.                             ? $this->_ibaseFieldFlags($info['name']$result'',
  135.             );
  136.             if ($mode MDB2_TABLEINFO_ORDER{
  137.                 $res['order'][$res[$i]['name']] $i;
  138.             }
  139.             if ($mode MDB2_TABLEINFO_ORDERTABLE{
  140.                 $res['ordertable'][$res[$i]['table']][$res[$i]['name']] $i;
  141.             }
  142.         }
  143.  
  144.         // free the result only if we were called on a table
  145.         if ($got_string{
  146.             @ibase_free_result($id);
  147.         }
  148.         return $res;
  149.     }
  150.  
  151.     // }}}
  152.     // {{{ _ibaseFieldFlags()
  153.  
  154.     /**
  155.      * Get the column's flags
  156.      *
  157.      * Supports "primary_key", "unique_key", "not_null", "default",
  158.      * "computed" and "blob".
  159.      *
  160.      * @param string $field_name  the name of the field
  161.      * @param string $table_name  the name of the table
  162.      *
  163.      * @return string  the flags
  164.      *
  165.      * @access protected
  166.      */
  167.     function _ibaseFieldFlags($field_name$table_name)
  168.     {
  169.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  170.  
  171.         $query 'SELECT R.RDB$CONSTRAINT_TYPE CTYPE'
  172.                .' FROM RDB$INDEX_SEGMENTS I'
  173.                .'  JOIN RDB$RELATION_CONSTRAINTS R ON I.RDB$INDEX_NAME=R.RDB$INDEX_NAME'
  174.                .' WHERE I.RDB$FIELD_NAME=\'' $field_name '\''
  175.                .'  AND UPPER(R.RDB$RELATION_NAME)=\'' strtoupper($table_name'\'';
  176.  
  177.         $result $db->_doQuery($query);
  178.         if (PEAR::isError($result)) {
  179.             return $result;
  180.         }
  181.  
  182.         $flags '';
  183.         if ($obj @ibase_fetch_object($result)) {
  184.             @ibase_free_result($result);
  185.             if (isset($obj->CTYPE)  && trim($obj->CTYPE== 'PRIMARY KEY'{
  186.                 $flags .= 'primary_key ';
  187.             }
  188.             if (isset($obj->CTYPE)  && trim($obj->CTYPE== 'UNIQUE'{
  189.                 $flags .= 'unique_key ';
  190.             }
  191.         }
  192.  
  193.         $query 'SELECT R.RDB$NULL_FLAG AS NFLAG,'
  194.                .'  R.RDB$DEFAULT_SOURCE AS DSOURCE,'
  195.                .'  F.RDB$FIELD_TYPE AS FTYPE,'
  196.                .'  F.RDB$COMPUTED_SOURCE AS CSOURCE'
  197.                .' FROM RDB$RELATION_FIELDS R '
  198.                .'  JOIN RDB$FIELDS F ON R.RDB$FIELD_SOURCE=F.RDB$FIELD_NAME'
  199.                .' WHERE UPPER(R.RDB$RELATION_NAME)=\'' strtoupper($table_name'\''
  200.                .'  AND R.RDB$FIELD_NAME=\'' $field_name '\'';
  201.  
  202.         $result $db->_doQuery($query);
  203.         if (PEAR::isError($result)) {
  204.             return $result;
  205.         }
  206.  
  207.         if ($obj @ibase_fetch_object($result)) {
  208.             @ibase_free_result($result);
  209.             if (isset($obj->NFLAG)) {
  210.                 $flags .= 'not_null ';
  211.             }
  212.             if (isset($obj->DSOURCE)) {
  213.                 $flags .= 'default ';
  214.             }
  215.             if (isset($obj->CSOURCE)) {
  216.                 $flags .= 'computed ';
  217.             }
  218.             if (isset($obj->FTYPE)  && $obj->FTYPE == 261{
  219.                 $flags .= 'blob ';
  220.             }
  221.         }
  222.  
  223.         return trim($flags);
  224.     }
  225. }
  226. ?>

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