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

Source for file oci8.php

Documentation is available at oci8.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                                         |
  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: oci8.php,v 1.19 2005/04/19 12:53:41 lsmith Exp $
  46.  
  47. require_once 'MDB2/Driver/Datatype/Common.php';
  48.  
  49. /**
  50.  * MDB2 OCI8 driver
  51.  *
  52.  * @package MDB2
  53.  * @category Database
  54.  * @author Lukas Smith <smith@backendmedia.com>
  55.  */
  56. {
  57.     // {{{ convertResult()
  58.  
  59.     /**
  60.      * convert a value to a RDBMS indepdenant MDB2 type
  61.      *
  62.      * @param mixed $value value to be converted
  63.      * @param int $type constant that specifies which type to convert to
  64.      * @return mixed converted value
  65.      * @access public
  66.      */
  67.     function convertResult($value$type)
  68.     {
  69.         if (is_null($value)) {
  70.             return null;
  71.         }
  72.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  73.         switch ($type{
  74.         case 'date':
  75.             return substr($value0strlen('YYYY-MM-DD'));
  76.         case 'time':
  77.             return substr($valuestrlen('YYYY-MM-DD ')strlen('HH:MI:SS'));
  78.         default:
  79.             return $this->_baseConvertResult($value$type);
  80.         }
  81.     }
  82.  
  83.     // }}}
  84.     // {{{ _getTypeDeclaration()
  85.  
  86.     /**
  87.      * Obtain DBMS specific SQL code portion needed to declare an text type
  88.      * field to be used in statements like CREATE TABLE.
  89.      *
  90.      * @param array $field  associative array with the name of the properties
  91.      *       of the field being declared as array indexes. Currently, the types
  92.      *       of supported field properties are as follows:
  93.      *
  94.      *       length
  95.      *           Integer value that determines the maximum length of the text
  96.      *           field. If this argument is missing the field should be
  97.      *           declared to have the longest length allowed by the DBMS.
  98.      *
  99.      *       default
  100.      *           Text value to be used as default for this field.
  101.      *
  102.      *       notnull
  103.      *           Boolean flag that indicates whether this field is constrained
  104.      *           to not be set to null.
  105.      * @return string  DBMS specific SQL code portion that should be used to
  106.      *       declare the specified field.
  107.      * @access protected
  108.      */
  109.     function _getTypeDeclaration($field)
  110.     {
  111.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  112.         switch ($field['type']{
  113.         case 'text':
  114.             $length (isset($field['length']$field['length'(($length $db->options['default_text_field_length']$length : 4000));
  115.             return 'VARCHAR ('.$length.')';
  116.         case 'clob':
  117.             return 'CLOB';
  118.         case 'blob':
  119.             return 'BLOB';
  120.         case 'integer':
  121.             return 'INT';
  122.         case 'boolean':
  123.             return 'CHAR (1)';
  124.         case 'date':
  125.         case 'time':
  126.         case 'timestamp':
  127.             return 'DATE';
  128.         case 'float':
  129.             return 'NUMBER';
  130.         case 'decimal':
  131.             return 'NUMBER(*,'.$db->options['decimal_places'].')';
  132.         }
  133.     }
  134.  
  135.     // }}}
  136.     // {{{ _getIntegerDeclaration()
  137.  
  138.     /**
  139.      * Obtain DBMS specific SQL code portion needed to declare an integer type
  140.      * field to be used in statements like CREATE TABLE.
  141.      *
  142.      * @param string $name name the field to be declared.
  143.      * @param array $field associative array with the name of the properties
  144.      *         of the field being declared as array indexes. Id
  145.      *  ently, the types
  146.      *         of supported field properties are as follows:
  147.      *
  148.      *         unsigned
  149.      *             Boolean flag that indicates whether the field should be
  150.      *             declared as unsigned integer if possible.
  151.      *
  152.      *         default
  153.      *             Integer value to be used as default for this field.
  154.      *
  155.      *         notnull
  156.      *             Boolean flag that indicates whether this field is constrained
  157.      *             to not be set to null.
  158.      * @return string DBMS specific SQL code portion that should be used to
  159.      *         declare the specified field.
  160.      * @access protected
  161.      */
  162.     function _getIntegerDeclaration($name$field)
  163.     {
  164.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  165.         if (isset($field['unsigned'])) {
  166.             $db->warning = "unsigned integer field \"$name\" is being declared as signed integer";
  167.         }
  168.         $default = isset($field['default']' DEFAULT '.
  169.             $this->quote($field['default']'integer''';
  170.         $notnull = isset($field['notnull']' NOT NULL' '';
  171.         return $name.' '.$this->_getTypeDeclaration($field).$default.$notnull;
  172.     }
  173.  
  174.     // }}}
  175.     // {{{ _getTextDeclaration()
  176.  
  177.     /**
  178.      * Obtain DBMS specific SQL code portion needed to declare an text type
  179.      * field to be used in statements like CREATE TABLE.
  180.      *
  181.      * @param string $name name the field to be declared.
  182.      * @param array $field associative array with the name of the properties
  183.      *         of the field being declared as array indexes. Currently, the types
  184.      *         of supported field properties are as follows:
  185.      *
  186.      *         length
  187.      *             Integer value that determines the maximum length of the text
  188.      *             field. If this argument is missing the field should be
  189.      *             declared to have the longest length allowed by the DBMS.
  190.      *
  191.      *         default
  192.      *             Text value to be used as default for this field.
  193.      *
  194.      *         notnull
  195.      *             Boolean flag that indicates whether this field is constrained
  196.      *             to not be set to null.
  197.      * @return string DBMS specific SQL code portion that should be used to
  198.      *         declare the specified field.
  199.      * @access protected
  200.      */
  201.     function _getTextDeclaration($name$field)
  202.     {
  203.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  204.         $type $this->_getTypeDeclaration($field);
  205.         $default = isset($field['default']' DEFAULT TIME'.
  206.             $this->quote($field['default']'text''';
  207.         $notnull = isset($field['notnull']' NOT NULL' '';
  208.         return $name.' '.$type.$default.$notnull;
  209.     }
  210.  
  211.     // }}}
  212.     // {{{ _getCLOBDeclaration()
  213.  
  214.     /**
  215.      * Obtain DBMS specific SQL code portion needed to declare an character
  216.      * large object type field to be used in statements like CREATE TABLE.
  217.      *
  218.      * @param string $name name the field to be declared.
  219.      * @param array $field associative array with the name of the properties
  220.      *         of the field being declared as array indexes. Currently, the types
  221.      *         of supported field properties are as follows:
  222.      *
  223.      *         length
  224.      *             Integer value that determines the maximum length of the large
  225.      *             object field. If this argument is missing the field should be
  226.      *             declared to have the longest length allowed by the DBMS.
  227.      *
  228.      *         notnull
  229.      *             Boolean flag that indicates whether this field is constrained
  230.      *             to not be set to null.
  231.      * @return string DBMS specific SQL code portion that should be used to
  232.      *         declare the specified field.
  233.      * @access public
  234.      */
  235.     function _getCLOBDeclaration($name$field)
  236.     {
  237.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  238.         $notnull = isset($field['notnull']' NOT NULL' '';
  239.         return $name.' '.$this->_getTypeDeclaration($field).$notnull;
  240.     }
  241.  
  242.     // }}}
  243.     // {{{ _getBLOBDeclaration()
  244.  
  245.     /**
  246.      * Obtain DBMS specific SQL code portion needed to declare an binary large
  247.      * object type field to be used in statements like CREATE TABLE.
  248.      *
  249.      * @param string $name name the field to be declared.
  250.      * @param array $field associative array with the name of the properties
  251.      *         of the field being declared as array indexes. Currently, the types
  252.      *         of supported field properties are as follows:
  253.      *
  254.      *         length
  255.      *             Integer value that determines the maximum length of the large
  256.      *             object field. If this argument is missing the field should be
  257.      *             declared to have the longest length allowed by the DBMS.
  258.      *
  259.      *         notnull
  260.      *             Boolean flag that indicates whether this field is constrained
  261.      *             to not be set to null.
  262.      * @return string DBMS specific SQL code portion that should be used to
  263.      *         declare the specified field.
  264.      * @access protected
  265.      */
  266.     function _getBLOBDeclaration($name$field)
  267.     {
  268.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  269.         $notnull = isset($field['notnull']' NOT NULL' '';
  270.         return $name.' '.$this->_getTypeDeclaration($field).$notnull;
  271.     }
  272.  
  273.     // }}}
  274.     // {{{ _getDateDeclaration()
  275.  
  276.     /**
  277.      * Obtain DBMS specific SQL code portion needed to declare a date type
  278.      * field to be used in statements like CREATE TABLE.
  279.      *
  280.      * @param string $name name the field to be declared.
  281.      * @param array $field associative array with the name of the properties
  282.      *         of the field being declared as array indexes. Currently, the types
  283.      *         of supported field properties are as follows:
  284.      *
  285.      *         default
  286.      *             Date value to be used as default for this field.
  287.      *
  288.      *         notnull
  289.      *             Boolean flag that indicates whether this field is constrained
  290.      *             to not be set to null.
  291.      * @return string DBMS specific SQL code portion that should be used to
  292.      *         declare the specified field.
  293.      * @access protected
  294.      */
  295.     function _getDateDeclaration($name$field)
  296.     {
  297.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  298.         $default = isset($field['default']' DEFAULT '.
  299.             $this->quote($field['default']'date''';
  300.         $notnull = isset($field['notnull']' NOT NULL' '';
  301.         return $name.' '.$this->_getTypeDeclaration($field).$default.$notnull;
  302.     }
  303.  
  304.     // }}}
  305.     // {{{ _getTimestampDeclaration()
  306.  
  307.     /**
  308.      * Obtain DBMS specific SQL code portion needed to declare a timestamp
  309.      * field to be used in statements like CREATE TABLE.
  310.      *
  311.      * @param string $name name the field to be declared.
  312.      * @param array $field associative array with the name of the properties
  313.      *         of the field being declared as array indexes. Currently, the types
  314.      *         of supported field properties are as follows:
  315.      *
  316.      *         default
  317.      *             Timestamp value to be used as default for this field.
  318.      *
  319.      *         notnull
  320.      *             Boolean flag that indicates whether this field is constrained
  321.      *             to not be set to null.
  322.      * @return string DBMS specific SQL code portion that should be used to
  323.      *         declare the specified field.
  324.      * @access protected
  325.      */
  326.     function _getTimestampDeclaration($name$field)
  327.     {
  328.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  329.         $default = isset($field['default']' DEFAULT '.
  330.             $this->quoteTimstamp($field['default']'';
  331.         $notnull = isset($field['notnull']' NOT NULL' '';
  332.         return $name.' '.$this->_getTypeDeclaration($field).$default.$notnull;    }
  333.  
  334.     // }}}
  335.     // {{{ _getTimeDeclaration()
  336.  
  337.     /**
  338.      * Obtain DBMS specific SQL code portion needed to declare a time
  339.      * field to be used in statements like CREATE TABLE.
  340.      *
  341.      * @param string $name name the field to be declared.
  342.      * @param array $field associative array with the name of the properties
  343.      *         of the field being declared as array indexes. Currently, the types
  344.      *         of supported field properties are as follows:
  345.      *
  346.      *         default
  347.      *             Time value to be used as default for this field.
  348.      *
  349.      *         notnull
  350.      *             Boolean flag that indicates whether this field is constrained
  351.      *             to not be set to null.
  352.      * @return string DBMS specific SQL code portion that should be used to
  353.      *         declare the specified field.
  354.      * @access protected
  355.      */
  356.     function _getTimeDeclaration($name$field)
  357.     {
  358.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  359.         $default = isset($field['default']' DEFAULT '.
  360.             $db->quoteime($field['default']'';
  361.         $notnull = isset($field['notnull']' NOT NULL' '';
  362.         return $name.' '.$this->_getTypeDeclaration($field).$default.$notnull;
  363.     }
  364.  
  365.     // }}}
  366.     // {{{ _getFloatDeclaration()
  367.  
  368.     /**
  369.      * Obtain DBMS specific SQL code portion needed to declare a float type
  370.      * field to be used in statements like CREATE TABLE.
  371.      *
  372.      * @param string $name name the field to be declared.
  373.      * @param array $field associative array with the name of the properties
  374.      *         of the field being declared as array indexes. Currently, the types
  375.      *         of supported field properties are as follows:
  376.      *
  377.      *         default
  378.      *             Float value to be used as default for this field.
  379.      *
  380.      *         notnull
  381.      *             Boolean flag that indicates whether this field is constrained
  382.      *             to not be set to null.
  383.      * @return string DBMS specific SQL code portion that should be used to
  384.      *         declare the specified field.
  385.      * @access protected
  386.      */
  387.     function _getFloatDeclaration($name$field)
  388.     {
  389.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  390.         $default = isset($field['default']' DEFAULT '.
  391.             $this->quote($field['default']'float''';
  392.         $notnull = isset($field['notnull']' NOT NULL' '';
  393.         return $name.' '.$this->_getTypeDeclaration($field).$default.$notnull;
  394.     }
  395.  
  396.     // }}}
  397.     // {{{ _getDecimalDeclaration()
  398.  
  399.     /**
  400.      * Obtain DBMS specific SQL code portion needed to declare a decimal type
  401.      * field to be used in statements like CREATE TABLE.
  402.      *
  403.      * @param string $name name the field to be declared.
  404.      * @param array $field associative array with the name of the properties
  405.      *         of the field being declared as array indexes. Currently, the types
  406.      *         of supported field properties are as follows:
  407.      *
  408.      *         default
  409.      *             Decimal value to be used as default for this field.
  410.      *
  411.      *         notnull
  412.      *             Boolean flag that indicates whether this field is constrained
  413.      *             to not be set to null.
  414.      * @return string DBMS specific SQL code portion that should be used to
  415.      *         declare the specified field.
  416.      * @access protected
  417.      */
  418.     function _getDecimalDeclaration($name$field)
  419.     {
  420.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  421.         $default = isset($field['default']' DEFAULT '.
  422.             $this->quote($field['default']'decimal''';
  423.         $notnull = isset($field['notnull']' NOT NULL' '';
  424.         return $name.' '.$this->_getTypeDeclaration($field).$default.$notnull;
  425.     }
  426.  
  427.     // }}}
  428.     // {{{ _quoteCLOB()
  429.  
  430.     /**
  431.      * Convert a text value into a DBMS specific format that is suitable to
  432.      * compose query statements.
  433.      *
  434.      * @param  $value 
  435.      * @return string text string that represents the given argument value in
  436.      *         a DBMS specific format.
  437.      * @access protected
  438.      */
  439.     function _quoteCLOB($value)
  440.     {
  441.         return 'EMPTY_CLOB()';
  442.     }
  443.  
  444.     // }}}
  445.     // {{{ _quoteBLOB()
  446.  
  447.     /**
  448.      * Convert a text value into a DBMS specific format that is suitable to
  449.      * compose query statements.
  450.      *
  451.      * @param  $value 
  452.      * @return string text string that represents the given argument value in
  453.      *         a DBMS specific format.
  454.      * @access protected
  455.      */
  456.     function _quoteBLOB($value)
  457.     {
  458.         return 'EMPTY_BLOB()';
  459.     }
  460.  
  461.     // }}}
  462.     // {{{ _quoteDate()
  463.  
  464.     /**
  465.      * Convert a text value into a DBMS specific format that is suitable to
  466.      * compose query statements.
  467.      *
  468.      * @param string $value text string value that is intended to be converted.
  469.      * @return string text string that represents the given argument value in
  470.      *         a DBMS specific format.
  471.      * @access protected
  472.      */
  473.     function _quoteDate($value)
  474.     {
  475.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  476.         return "'$value 00:00:00'";
  477.     }
  478.  
  479.     // }}}
  480.     // {{{ _quoteTimestamp()
  481.  
  482.     /**
  483.      * Convert a text value into a DBMS specific format that is suitable to
  484.      * compose query statements.
  485.      *
  486.      * @param string $value text string value that is intended to be converted.
  487.      * @return string text string that represents the given argument value in
  488.      *         a DBMS specific format.
  489.      * @access protected
  490.      */
  491.     function _quoteTimestamp($value)
  492.     {
  493.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  494.         return "'$value'";
  495.     }
  496.  
  497.     // }}}
  498.     // {{{ _quoteTime()
  499.  
  500.     /**
  501.      * Convert a text value into a DBMS specific format that is suitable to
  502.      *        compose query statements.
  503.      *
  504.      * @param string $value text string value that is intended to be converted.
  505.      * @return string text string that represents the given argument value in
  506.      *         a DBMS specific format.
  507.      * @access protected
  508.      */
  509.     function _quoteTime($value)
  510.     {
  511.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  512.         return "'0001-01-01 $value'";
  513.     }
  514.  
  515.     // }}}
  516.     // {{{ _quoteFloat()
  517.  
  518.     /**
  519.      * Convert a text value into a DBMS specific format that is suitable to
  520.      * compose query statements.
  521.      *
  522.      * @param string $value text string value that is intended to be converted.
  523.      * @return string text string that represents the given argument value in
  524.      *         a DBMS specific format.
  525.      * @access protected
  526.      */
  527.     function _quoteFloat($value)
  528.     {
  529.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  530.         return (float)$value;
  531.     }
  532.  
  533.     // }}}
  534.     // {{{ _quoteDecimal()
  535.  
  536.     /**
  537.      * Convert a text value into a DBMS specific format that is suitable to
  538.      * compose query statements.
  539.      *
  540.      * @param string $value text string value that is intended to be converted.
  541.      * @return string text string that represents the given argument value in
  542.      *         a DBMS specific format.
  543.      * @access protected
  544.      */
  545.     function _quoteDecimal($value)
  546.     {
  547.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  548.         return $value;
  549.     }
  550.  
  551.     // }}}
  552.     // {{{ _retrieveLOB()
  553.  
  554.     /**
  555.      * retrieve LOB from the database
  556.      *
  557.      * @param int $lob handle to a lob created by the createLOB() function
  558.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  559.      * @access protected
  560.      */
  561.     function _retrieveLOB($lob)
  562.     {
  563.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  564.         if (!isset($db->lobs[$lob])) {
  565.             return $db->raiseError(MDB2_ERRORnullnull,
  566.                 'it was not specified a valid lob');
  567.         }
  568.         if (!isset($db->lobs[$lob]['loaded'])) {
  569.             if (!is_object($db->lobs[$lob]['value'])) {
  570.                return $db->raiseError(MDB2_ERRORnullnull,
  571.                    'attemped to retrieve LOB from non existing or NULL column');
  572.             }
  573.             $db->lobs[$lob]['value'$db->lobs[$lob]['value']->load();
  574.             $db->lobs[$lob]['loaded'= true;
  575.         }
  576.         return MDB2_OK;
  577.     }
  578. }
  579.  
  580. ?>

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