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

Source for file oci8.php

Documentation is available at oci8.php

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

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