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

Source for file Common.php

Documentation is available at Common.php

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP versions 4 and 5                                                 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1998-2006 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@pooteeweet.org>                           |
  43. // +----------------------------------------------------------------------+
  44. //
  45. // $Id: Common.php,v 1.68 2006/05/14 05:48:16 lsmith Exp $
  46.  
  47. require_once 'MDB2/LOB.php';
  48.  
  49. /**
  50.  * @package  MDB2
  51.  * @category Database
  52.  * @author   Lukas Smith <smith@pooteeweet.org>
  53.  */
  54.  
  55. /**
  56.  * MDB2_Driver_Common: Base class that is extended by each MDB2 driver
  57.  *
  58.  * @package MDB2
  59.  * @category Database
  60.  * @author Lukas Smith <smith@pooteeweet.org>
  61.  */
  62. {
  63.     var $valid_types = array(
  64.         'text'      => '',
  65.         'boolean'   => true,
  66.         'integer'   => 0,
  67.         'decimal'   => 0.0,
  68.         'float'     => 0.0,
  69.         'timestamp' => '1970-01-01 00:00:00',
  70.         'time'      => '00:00:00',
  71.         'date'      => '1970-01-01',
  72.         'clob'      => '',
  73.         'blob'      => '',
  74.     );
  75.  
  76.     /**
  77.      * contains all LOB objects created with this MDB2 instance
  78.      * @var array 
  79.      * @access protected
  80.      */
  81.     var $lobs = array();
  82.  
  83.     // }}}
  84.     // {{{ checkResultTypes()
  85.  
  86.     /**
  87.      * Define the list of types to be associated with the columns of a given
  88.      * result set.
  89.      *
  90.      * This function may be called before invoking fetchRow(), fetchOne()
  91.      * fetchCole() and fetchAll() so that the necessary data type
  92.      * conversions are performed on the data to be retrieved by them. If this
  93.      * function is not called, the type of all result set columns is assumed
  94.      * to be text, thus leading to not perform any conversions.
  95.      *
  96.      * @param string $types array variable that lists the
  97.      *        data types to be expected in the result set columns. If this array
  98.      *        contains less types than the number of columns that are returned
  99.      *        in the result set, the remaining columns are assumed to be of the
  100.      *        type text. Currently, the types clob and blob are not fully
  101.      *        supported.
  102.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  103.      * @access public
  104.      */
  105.     function checkResultTypes($types)
  106.     {
  107.         $types is_array($types$types : array($types);
  108.         foreach ($types as $key => $type{
  109.             if (!isset($this->valid_types[$type])) {
  110.                 $db =$this->getDBInstance();
  111.                 if (PEAR::isError($db)) {
  112.                     return $db;
  113.                 }
  114.  
  115.                 return $db->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  116.                     'checkResultTypes: ' $type ' for '$key .' is not a supported column type');
  117.             }
  118.         }
  119.         return $types;
  120.     }
  121.  
  122.     // }}}
  123.     // {{{ _baseConvertResult()
  124.  
  125.     /**
  126.      * general type conversion method
  127.      *
  128.      * @param mixed $value refernce to a value to be converted
  129.      * @param int $type constant that specifies which type to convert to
  130.      * @return object MDB2 error on failure
  131.      * @access protected
  132.      */
  133.     function _baseConvertResult($value$type)
  134.     {
  135.         switch ($type{
  136.         case 'text':
  137.             return $value;
  138.         case 'integer':
  139.             return intval($value);
  140.         case 'boolean':
  141.             return !empty($value);
  142.         case 'decimal':
  143.             return $value;
  144.         case 'float':
  145.             return doubleval($value);
  146.         case 'date':
  147.             return $value;
  148.         case 'time':
  149.             return $value;
  150.         case 'timestamp':
  151.             return $value;
  152.         case 'clob':
  153.         case 'blob':
  154.             $this->lobs[= array(
  155.                 'buffer' => null,
  156.                 'position' => 0,
  157.                 'lob_index' => null,
  158.                 'endOfLOB' => false,
  159.                 'resource' => $value,
  160.                 'value' => null,
  161.                 'loaded' => false,
  162.             );
  163.             end($this->lobs);
  164.             $lob_index key($this->lobs);
  165.             $this->lobs[$lob_index]['lob_index'$lob_index;
  166.             return fopen('MDB2LOB://'.$lob_index.'@'.$this->db_index'r+');
  167.         }
  168.  
  169.         $db =$this->getDBInstance();
  170.         if (PEAR::isError($db)) {
  171.             return $db;
  172.         }
  173.  
  174.         return $db->raiseError(MDB2_ERROR_INVALIDnullnull,
  175.             'attempt to convert result value to an unknown type ' $type);
  176.     }
  177.  
  178.     // }}}
  179.     // {{{ convertResult()
  180.  
  181.     /**
  182.      * convert a value to a RDBMS indepdenant MDB2 type
  183.      *
  184.      * @param mixed $value value to be converted
  185.      * @param int $type constant that specifies which type to convert to
  186.      * @return mixed converted value or a MDB2 error on failure
  187.      * @access public
  188.      */
  189.     function convertResult($value$type)
  190.     {
  191.         if (is_null($value)) {
  192.             return null;
  193.         }
  194.         return $this->_baseConvertResult($value$type);
  195.     }
  196.  
  197.     // }}}
  198.     // {{{ convertResultRow()
  199.  
  200.     /**
  201.      * convert a result row
  202.      *
  203.      * @param resource $result result identifier
  204.      * @param array $row array with data
  205.      * @return mixed MDB2_OK on success,  a MDB2 error on failure
  206.      * @access public
  207.      */
  208.     function convertResultRow($types$row)
  209.     {
  210.         if (is_array($types)) {
  211.             reset($types);
  212.             $current_column = -1;
  213.             foreach ($row as $key => $column{
  214.                 ++$current_column;
  215.                 if (!isset($column)) {
  216.                     continue;
  217.                 }
  218.                 if (isset($types[$current_column])) {
  219.                     $type $types[$current_column];
  220.                 elseif (isset($types[$key])) {
  221.                     $type $types[$key];
  222.                 elseif (current($types)) {
  223.                     $type current($types);
  224.                     next($types);
  225.                 else {
  226.                     continue;
  227.                 }
  228.                 $value $this->convertResult($row[$key]$type);
  229.                 if (PEAR::isError($value)) {
  230.                     return $value;
  231.                 }
  232.                 $row[$key$value;
  233.             }
  234.         }
  235.         return $row;
  236.     }
  237.  
  238.     // }}}
  239.     // {{{ getDeclaration()
  240.  
  241.     /**
  242.      * Obtain DBMS specific SQL code portion needed to declare
  243.      * of the given type
  244.      *
  245.      * @param string $type type to which the value should be converted to
  246.      * @param string  $name   name the field to be declared.
  247.      * @param string  $field  definition of the field
  248.      * @return string  DBMS specific SQL code portion that should be used to
  249.      *                  declare the specified field.
  250.      * @access public
  251.      */
  252.     function getDeclaration($type$name$field)
  253.     {
  254.         if (!method_exists($this"_get{$type}Declaration")) {
  255.             $db =$this->getDBInstance();
  256.             if (PEAR::isError($db)) {
  257.                 return $db;
  258.             }
  259.  
  260.             return $db->raiseError(MDB2_ERROR_NOT_FOUNDnullnull,
  261.                 'type not defined: '.$type);
  262.         }
  263.         return $this->{"_get{$type}Declaration"}($name$field);
  264.     }
  265.  
  266.     // }}}
  267.     // {{{ getTypeDeclaration()
  268.  
  269.     /**
  270.      * Obtain DBMS specific SQL code portion needed to declare an text type
  271.      * field to be used in statements like CREATE TABLE.
  272.      *
  273.      * @param array $field  associative array with the name of the properties
  274.      *       of the field being declared as array indexes. Currently, the types
  275.      *       of supported field properties are as follows:
  276.      *
  277.      *       length
  278.      *           Integer value that determines the maximum length of the text
  279.      *           field. If this argument is missing the field should be
  280.      *           declared to have the longest length allowed by the DBMS.
  281.      *
  282.      *       default
  283.      *           Text value to be used as default for this field.
  284.      *
  285.      *       notnull
  286.      *           Boolean flag that indicates whether this field is constrained
  287.      *           to not be set to null.
  288.      * @return string  DBMS specific SQL code portion that should be used to
  289.      *       declare the specified field.
  290.      * @access public
  291.      */
  292.     function getTypeDeclaration($field)
  293.     {
  294.         $db =$this->getDBInstance();
  295.         if (PEAR::isError($db)) {
  296.             return $db;
  297.         }
  298.  
  299.         switch ($field['type']{
  300.         case 'text':
  301.             $length array_key_exists('length'$field)
  302.                 ? $field['length'$db->options['default_text_field_length'];
  303.             $fixed array_key_exists('fixed'$field$field['fixed': false;
  304.             return $fixed ($length 'CHAR('.$length.')' 'CHAR('.$db->options['default_text_field_length'].')')
  305.                 : ($length 'VARCHAR('.$length.')' 'TEXT');
  306.         case 'clob':
  307.             return 'TEXT';
  308.         case 'blob':
  309.             return 'TEXT';
  310.         case 'integer':
  311.             return 'INT';
  312.         case 'boolean':
  313.             return 'INT';
  314.         case 'date':
  315.             return 'CHAR ('.strlen('YYYY-MM-DD').')';
  316.         case 'time':
  317.             return 'CHAR ('.strlen('HH:MM:SS').')';
  318.         case 'timestamp':
  319.             return 'CHAR ('.strlen('YYYY-MM-DD HH:MM:SS').')';
  320.         case 'float':
  321.             return 'TEXT';
  322.         case 'decimal':
  323.             return 'TEXT';
  324.         }
  325.         return '';
  326.     }
  327.  
  328.     // }}}
  329.     // {{{ _getDeclaration()
  330.  
  331.     /**
  332.      * Obtain DBMS specific SQL code portion needed to declare a generic type
  333.      * field to be used in statements like CREATE TABLE.
  334.      *
  335.      * @param string $name   name the field to be declared.
  336.      * @param array  $field  associative array with the name of the properties
  337.      *       of the field being declared as array indexes. Currently, the types
  338.      *       of supported field properties are as follows:
  339.      *
  340.      *       length
  341.      *           Integer value that determines the maximum length of the text
  342.      *           field. If this argument is missing the field should be
  343.      *           declared to have the longest length allowed by the DBMS.
  344.      *
  345.      *       default
  346.      *           Text value to be used as default for this field.
  347.      *
  348.      *       notnull
  349.      *           Boolean flag that indicates whether this field is constrained
  350.      *           to not be set to null.
  351.      * @return string  DBMS specific SQL code portion that should be used to
  352.      *       declare the specified field.
  353.      * @access protected
  354.      */
  355.     function _getDeclaration($name$field)
  356.     {
  357.         $db =$this->getDBInstance();
  358.         if (PEAR::isError($db)) {
  359.             return $db;
  360.         }
  361.  
  362.         $default '';
  363.         if (array_key_exists('default'$field)) {
  364.             if ($field['default'=== ''{
  365.                 $field['default'(array_key_exists('notnull'$field&& $field['notnull'])
  366.                     ? $this->valid_types[$field['type']] : null;
  367.                 if ($field['default'=== ''
  368.                     && $db->options['portability'MDB2_PORTABILITY_EMPTY_TO_NULL
  369.                 {
  370.                     $field['default'' ';
  371.                 }
  372.             }
  373.  
  374.             $default ' DEFAULT '.$this->quote($field['default']$field['type']);
  375.         }
  376.  
  377.         $notnull (array_key_exists('notnull'$field&& $field['notnull']' NOT NULL' '';
  378.         $name $db->quoteIdentifier($nametrue);
  379.         return $name.' '.$this->getTypeDeclaration($field).$default.$notnull;
  380.     }
  381.  
  382.     // }}}
  383.     // {{{ _getIntegerDeclaration()
  384.  
  385.     /**
  386.      * Obtain DBMS specific SQL code portion needed to declare an integer type
  387.      * field to be used in statements like CREATE TABLE.
  388.      *
  389.      * @param string $name name the field to be declared.
  390.      * @param array $field associative array with the name of the properties
  391.      *        of the field being declared as array indexes. Currently, the types
  392.      *        of supported field properties are as follows:
  393.      *
  394.      *        unsigned
  395.      *            Boolean flag that indicates whether the field should be
  396.      *            declared as unsigned integer if possible.
  397.      *
  398.      *        default
  399.      *            Integer value to be used as default for this field.
  400.      *
  401.      *        notnull
  402.      *            Boolean flag that indicates whether this field is constrained
  403.      *            to not be set to null.
  404.      * @return string DBMS specific SQL code portion that should be used to
  405.      *        declare the specified field.
  406.      * @access protected
  407.      */
  408.     function _getIntegerDeclaration($name$field)
  409.     {
  410.         if (array_key_exists('unsigned'$field&& $field['unsigned']{
  411.             $db =$this->getDBInstance();
  412.             if (PEAR::isError($db)) {
  413.                 return $db;
  414.             }
  415.  
  416.             $db->warnings[= "unsigned integer field \"$name\" is being declared as signed integer";
  417.         }
  418.         return $this->_getDeclaration($name$field);
  419.     }
  420.  
  421.     // }}}
  422.     // {{{ _getTextDeclaration()
  423.  
  424.     /**
  425.      * Obtain DBMS specific SQL code portion needed to declare an text type
  426.      * field to be used in statements like CREATE TABLE.
  427.      *
  428.      * @param string $name name the field to be declared.
  429.      * @param array $field associative array with the name of the properties
  430.      *        of the field being declared as array indexes. Currently, the types
  431.      *        of supported field properties are as follows:
  432.      *
  433.      *        length
  434.      *            Integer value that determines the maximum length of the text
  435.      *            field. If this argument is missing the field should be
  436.      *            declared to have the longest length allowed by the DBMS.
  437.      *
  438.      *        default
  439.      *            Text value to be used as default for this field.
  440.      *
  441.      *        notnull
  442.      *            Boolean flag that indicates whether this field is constrained
  443.      *            to not be set to null.
  444.      * @return string DBMS specific SQL code portion that should be used to
  445.      *        declare the specified field.
  446.      * @access protected
  447.      */
  448.     function _getTextDeclaration($name$field)
  449.     {
  450.         return $this->_getDeclaration($name$field);
  451.     }
  452.  
  453.     // }}}
  454.     // {{{ _getCLOBDeclaration()
  455.  
  456.     /**
  457.      * Obtain DBMS specific SQL code portion needed to declare an character
  458.      * large object type field to be used in statements like CREATE TABLE.
  459.      *
  460.      * @param string $name name the field to be declared.
  461.      * @param array $field associative array with the name of the properties
  462.      *         of the field being declared as array indexes. Currently, the types
  463.      *         of supported field properties are as follows:
  464.      *
  465.      *         length
  466.      *             Integer value that determines the maximum length of the large
  467.      *             object field. If this argument is missing the field should be
  468.      *             declared to have the longest length allowed by the DBMS.
  469.      *
  470.      *         notnull
  471.      *             Boolean flag that indicates whether this field is constrained
  472.      *             to not be set to null.
  473.      * @return string DBMS specific SQL code portion that should be used to
  474.      *         declare the specified field.
  475.      * @access public
  476.      */
  477.     function _getCLOBDeclaration($name$field)
  478.     {
  479.         $db =$this->getDBInstance();
  480.         if (PEAR::isError($db)) {
  481.             return $db;
  482.         }
  483.  
  484.         $notnull (array_key_exists('notnull'$field&& $field['notnull']' NOT NULL' '';
  485.         $name $db->quoteIdentifier($nametrue);
  486.         return $name.' '.$this->getTypeDeclaration($field).$notnull;
  487.     }
  488.  
  489.     // }}}
  490.     // {{{ _getBLOBDeclaration()
  491.  
  492.     /**
  493.      * Obtain DBMS specific SQL code portion needed to declare an binary large
  494.      * object type field to be used in statements like CREATE TABLE.
  495.      *
  496.      * @param string $name name the field to be declared.
  497.      * @param array $field associative array with the name of the properties
  498.      *         of the field being declared as array indexes. Currently, the types
  499.      *         of supported field properties are as follows:
  500.      *
  501.      *         length
  502.      *             Integer value that determines the maximum length of the large
  503.      *             object field. If this argument is missing the field should be
  504.      *             declared to have the longest length allowed by the DBMS.
  505.      *
  506.      *         notnull
  507.      *             Boolean flag that indicates whether this field is constrained
  508.      *             to not be set to null.
  509.      * @return string DBMS specific SQL code portion that should be used to
  510.      *         declare the specified field.
  511.      * @access protected
  512.      */
  513.     function _getBLOBDeclaration($name$field)
  514.     {
  515.         $db =$this->getDBInstance();
  516.         if (PEAR::isError($db)) {
  517.             return $db;
  518.         }
  519.  
  520.         $notnull (array_key_exists('notnull'$field&& $field['notnull']' NOT NULL' '';
  521.         $name $db->quoteIdentifier($nametrue);
  522.         return $name.' '.$this->getTypeDeclaration($field).$notnull;
  523.     }
  524.  
  525.     // }}}
  526.     // {{{ _getBooleanDeclaration()
  527.  
  528.     /**
  529.      * Obtain DBMS specific SQL code portion needed to declare a boolean type
  530.      * field to be used in statements like CREATE TABLE.
  531.      *
  532.      * @param string $name name the field to be declared.
  533.      * @param array $field associative array with the name of the properties
  534.      *        of the field being declared as array indexes. Currently, the types
  535.      *        of supported field properties are as follows:
  536.      *
  537.      *        default
  538.      *            Boolean value to be used as default for this field.
  539.      *
  540.      *        notnullL
  541.      *            Boolean flag that indicates whether this field is constrained
  542.      *            to not be set to null.
  543.      * @return string DBMS specific SQL code portion that should be used to
  544.      *        declare the specified field.
  545.      * @access protected
  546.      */
  547.     function _getBooleanDeclaration($name$field)
  548.     {
  549.         return $this->_getDeclaration($name$field);
  550.     }
  551.  
  552.     // }}}
  553.     // {{{ _getDateDeclaration()
  554.  
  555.     /**
  556.      * Obtain DBMS specific SQL code portion needed to declare a date type
  557.      * field to be used in statements like CREATE TABLE.
  558.      *
  559.      * @param string $name name the field to be declared.
  560.      * @param array $field associative array with the name of the properties
  561.      *        of the field being declared as array indexes. Currently, the types
  562.      *        of supported field properties are as follows:
  563.      *
  564.      *        default
  565.      *            Date value to be used as default for this field.
  566.      *
  567.      *        notnull
  568.      *            Boolean flag that indicates whether this field is constrained
  569.      *            to not be set to null.
  570.      * @return string DBMS specific SQL code portion that should be used to
  571.      *        declare the specified field.
  572.      * @access protected
  573.      */
  574.     function _getDateDeclaration($name$field)
  575.     {
  576.         return $this->_getDeclaration($name$field);
  577.     }
  578.  
  579.     // }}}
  580.     // {{{ _getTimestampDeclaration()
  581.  
  582.     /**
  583.      * Obtain DBMS specific SQL code portion needed to declare a timestamp
  584.      * field to be used in statements like CREATE TABLE.
  585.      *
  586.      * @param string $name name the field to be declared.
  587.      * @param array $field associative array with the name of the properties
  588.      *        of the field being declared as array indexes. Currently, the types
  589.      *        of supported field properties are as follows:
  590.      *
  591.      *        default
  592.      *            Timestamp value to be used as default for this field.
  593.      *
  594.      *        notnull
  595.      *            Boolean flag that indicates whether this field is constrained
  596.      *            to not be set to null.
  597.      * @return string DBMS specific SQL code portion that should be used to
  598.      *        declare the specified field.
  599.      * @access protected
  600.      */
  601.     function _getTimestampDeclaration($name$field)
  602.     {
  603.         return $this->_getDeclaration($name$field);
  604.     }
  605.  
  606.     // }}}
  607.     // {{{ _getTimeDeclaration()
  608.  
  609.     /**
  610.      * Obtain DBMS specific SQL code portion needed to declare a time
  611.      * field to be used in statements like CREATE TABLE.
  612.      *
  613.      * @param string $name name the field to be declared.
  614.      * @param array $field associative array with the name of the properties
  615.      *        of the field being declared as array indexes. Currently, the types
  616.      *        of supported field properties are as follows:
  617.      *
  618.      *        default
  619.      *            Time value to be used as default for this field.
  620.      *
  621.      *        notnull
  622.      *            Boolean flag that indicates whether this field is constrained
  623.      *            to not be set to null.
  624.      * @return string DBMS specific SQL code portion that should be used to
  625.      *        declare the specified field.
  626.      * @access protected
  627.      */
  628.     function _getTimeDeclaration($name$field)
  629.     {
  630.         return $this->_getDeclaration($name$field);
  631.     }
  632.  
  633.     // }}}
  634.     // {{{ _getFloatDeclaration()
  635.  
  636.     /**
  637.      * Obtain DBMS specific SQL code portion needed to declare a float type
  638.      * field to be used in statements like CREATE TABLE.
  639.      *
  640.      * @param string $name name the field to be declared.
  641.      * @param array $field associative array with the name of the properties
  642.      *        of the field being declared as array indexes. Currently, the types
  643.      *        of supported field properties are as follows:
  644.      *
  645.      *        default
  646.      *            Float value to be used as default for this field.
  647.      *
  648.      *        notnull
  649.      *            Boolean flag that indicates whether this field is constrained
  650.      *            to not be set to null.
  651.      * @return string DBMS specific SQL code portion that should be used to
  652.      *        declare the specified field.
  653.      * @access protected
  654.      */
  655.     function _getFloatDeclaration($name$field)
  656.     {
  657.         return $this->_getDeclaration($name$field);
  658.     }
  659.  
  660.     // }}}
  661.     // {{{ _getDecimalDeclaration()
  662.  
  663.     /**
  664.      * Obtain DBMS specific SQL code portion needed to declare a decimal type
  665.      * field to be used in statements like CREATE TABLE.
  666.      *
  667.      * @param string $name name the field to be declared.
  668.      * @param array $field associative array with the name of the properties
  669.      *        of the field being declared as array indexes. Currently, the types
  670.      *        of supported field properties are as follows:
  671.      *
  672.      *        default
  673.      *            Decimal value to be used as default for this field.
  674.      *
  675.      *        notnull
  676.      *            Boolean flag that indicates whether this field is constrained
  677.      *            to not be set to null.
  678.      * @return string DBMS specific SQL code portion that should be used to
  679.      *        declare the specified field.
  680.      * @access protected
  681.      */
  682.     function _getDecimalDeclaration($name$field)
  683.     {
  684.         return $this->_getDeclaration($name$field);
  685.     }
  686.  
  687.     // }}}
  688.     // {{{ compareDefinition()
  689.  
  690.     /**
  691.      * Obtain an array of changes that may need to applied
  692.      *
  693.      * @param array $current new definition
  694.      * @param array  $previous old definition
  695.      * @return array  containing all changes that will need to be applied
  696.      * @access public
  697.      */
  698.     function compareDefinition($current$previous)
  699.     {
  700.         $type array_key_exists('type'$current$current['type': null;
  701.  
  702.         if (!method_exists($this"_compare{$type}Definition")) {
  703.             $db =$this->getDBInstance();
  704.             if (PEAR::isError($db)) {
  705.                 return $db;
  706.             }
  707.  
  708.             return $db->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  709.                 'type "'.$current['type'].'" is not yet supported');
  710.         }
  711.  
  712.         if (!array_key_exists('type'$previous|| $previous['type'!= $type{
  713.             return $current;
  714.         }
  715.  
  716.         $change $this->{"_compare{$type}Definition"}($current$previous);
  717.  
  718.         if ($previous['type'!= $type{
  719.             $change['type'= true;
  720.         }
  721.  
  722.         $previous_notnull array_key_exists('notnull'$previous$previous['notnull': false;
  723.         $notnull array_key_exists('notnull'$current$current['notnull': false;
  724.         if ($previous_notnull != $notnull{
  725.             $change['notnull'= true;
  726.         }
  727.  
  728.         $previous_default array_key_exists('default'$previous$previous['default':
  729.             ($previous_notnull '' : null);
  730.         $default array_key_exists('default'$current$current['default':
  731.             ($notnull '' : null);
  732.         if ($previous_default !== $default{
  733.             $change['default'= true;
  734.         }
  735.  
  736.         return $change;
  737.     }
  738.  
  739.     // }}}
  740.     // {{{ _compareIntegerDefinition()
  741.  
  742.     /**
  743.      * Obtain an array of changes that may need to applied to an integer field
  744.      *
  745.      * @param array $current new definition
  746.      * @param array  $previous old definition
  747.      * @return array  containing all changes that will need to be applied
  748.      * @access protected
  749.      */
  750.     function _compareIntegerDefinition($current$previous)
  751.     {
  752.         $change = array();
  753.         $previous_unsigned array_key_exists('unsigned'$previous$previous['unsigned': false;
  754.         $unsigned array_key_exists('unsigned'$current$current['unsigned': false;
  755.         if ($previous_unsigned != $unsigned{
  756.             $change['unsigned'= true;
  757.         }
  758.         $previous_autoincrement array_key_exists('autoincrement'$previous$previous['autoincrement': false;
  759.         $autoincrement array_key_exists('autoincrement'$current$current['autoincrement': false;
  760.         if ($previous_autoincrement != $autoincrement{
  761.             $change['autoincrement'= true;
  762.         }
  763.         return $change;
  764.     }
  765.  
  766.     // }}}
  767.     // {{{ _compareTextDefinition()
  768.  
  769.     /**
  770.      * Obtain an array of changes that may need to applied to an text field
  771.      *
  772.      * @param array $current new definition
  773.      * @param array  $previous old definition
  774.      * @return array  containing all changes that will need to be applied
  775.      * @access protected
  776.      */
  777.     function _compareTextDefinition($current$previous)
  778.     {
  779.         $change = array();
  780.         $previous_length array_key_exists('length'$previous$previous['length': 0;
  781.         $length array_key_exists('length'$current$current['length': 0;
  782.         if ($previous_length != $length{
  783.             $change['length'= true;
  784.         }
  785.         $previous_fixed array_key_exists('fixed'$previous$previous['fixed': 0;
  786.         $fixed array_key_exists('fixed'$current$current['fixed': 0;
  787.         if ($previous_fixed != $fixed{
  788.             $change['fixed'= true;
  789.         }
  790.         return $change;
  791.     }
  792.  
  793.     // }}}
  794.     // {{{ _compareCLOBDefinition()
  795.  
  796.     /**
  797.      * Obtain an array of changes that may need to applied to an CLOB field
  798.      *
  799.      * @param array $current new definition
  800.      * @param array  $previous old definition
  801.      * @return array  containing all changes that will need to be applied
  802.      * @access protected
  803.      */
  804.     function _compareCLOBDefinition($current$previous)
  805.     {
  806.         return $this->_compareTextDefinition($current$previous);
  807.     }
  808.  
  809.     // }}}
  810.     // {{{ _compareBLOBDefinition()
  811.  
  812.     /**
  813.      * Obtain an array of changes that may need to applied to an BLOB field
  814.      *
  815.      * @param array $current new definition
  816.      * @param array  $previous old definition
  817.      * @return array  containing all changes that will need to be applied
  818.      * @access protected
  819.      */
  820.     function _compareBLOBDefinition($current$previous)
  821.     {
  822.         return $this->_compareTextDefinition($current$previous);
  823.     }
  824.  
  825.     // }}}
  826.     // {{{ _compareDateDefinition()
  827.  
  828.     /**
  829.      * Obtain an array of changes that may need to applied to an date field
  830.      *
  831.      * @param array $current new definition
  832.      * @param array  $previous old definition
  833.      * @return array  containing all changes that will need to be applied
  834.      * @access protected
  835.      */
  836.     function _compareDateDefinition($current$previous)
  837.     {
  838.         return array();
  839.     }
  840.  
  841.     // }}}
  842.     // {{{ _compareTimeDefinition()
  843.  
  844.     /**
  845.      * Obtain an array of changes that may need to applied to an time field
  846.      *
  847.      * @param array $current new definition
  848.      * @param array  $previous old definition
  849.      * @return array  containing all changes that will need to be applied
  850.      * @access protected
  851.      */
  852.     function _compareTimeDefinition($current$previous)
  853.     {
  854.         return array();
  855.     }
  856.  
  857.     // }}}
  858.     // {{{ _compareTimestampDefinition()
  859.  
  860.     /**
  861.      * Obtain an array of changes that may need to applied to an timestamp field
  862.      *
  863.      * @param array $current new definition
  864.      * @param array  $previous old definition
  865.      * @return array  containing all changes that will need to be applied
  866.      * @access protected
  867.      */
  868.     function _compareTimestampDefinition($current$previous)
  869.     {
  870.         return array();
  871.     }
  872.  
  873.     // }}}
  874.     // {{{ _compareBooleanDefinition()
  875.  
  876.     /**
  877.      * Obtain an array of changes that may need to applied to an boolean field
  878.      *
  879.      * @param array $current new definition
  880.      * @param array  $previous old definition
  881.      * @return array  containing all changes that will need to be applied
  882.      * @access protected
  883.      */
  884.     function _compareBooleanDefinition($current$previous)
  885.     {
  886.         return array();
  887.     }
  888.  
  889.     // }}}
  890.     // {{{ _compareFloatDefinition()
  891.  
  892.     /**
  893.      * Obtain an array of changes that may need to applied to an float field
  894.      *
  895.      * @param array $current new definition
  896.      * @param array  $previous old definition
  897.      * @return array  containing all changes that will need to be applied
  898.      * @access protected
  899.      */
  900.     function _compareFloatDefinition($current$previous)
  901.     {
  902.         return array();
  903.     }
  904.  
  905.     // }}}
  906.     // {{{ _compareDecimalDefinition()
  907.  
  908.     /**
  909.      * Obtain an array of changes that may need to applied to an decimal field
  910.      *
  911.      * @param array $current new definition
  912.      * @param array  $previous old definition
  913.      * @return array  containing all changes that will need to be applied
  914.      * @access protected
  915.      */
  916.     function _compareDecimalDefinition($current$previous)
  917.     {
  918.         return array();
  919.     }
  920.  
  921.     // }}}
  922.     // {{{ quote()
  923.  
  924.     /**
  925.      * Convert a text value into a DBMS specific format that is suitable to
  926.      * compose query statements.
  927.      *
  928.      * @param string $value text string value that is intended to be converted.
  929.      * @param string $type type to which the value should be converted to
  930.      * @param bool $quote determines if the value should be quoted and escaped
  931.      * @return string text string that represents the given argument value in
  932.      *        a DBMS specific format.
  933.      * @access public
  934.      */
  935.     function quote($value$type = null$quote = true)
  936.     {
  937.         $db =$this->getDBInstance();
  938.         if (PEAR::isError($db)) {
  939.             return $db;
  940.         }
  941.  
  942.         if (is_null($value)
  943.             || ($value === '' && $db->options['portability'MDB2_PORTABILITY_EMPTY_TO_NULL)
  944.         {
  945.             if (!$quote{
  946.                 return null;
  947.             }
  948.             return 'NULL';
  949.         }
  950.  
  951.         if (is_null($type)) {
  952.             switch (gettype($value)) {
  953.             case 'integer':
  954.                 $type 'integer';
  955.                 break;
  956.             case 'double':
  957.                 // todo
  958.                 $type 'decimal';
  959.                 $type 'float';
  960.                 break;
  961.             case 'boolean':
  962.                 $type 'boolean';
  963.                 break;
  964.             case 'array':
  965.             case 'object':
  966.                  $type 'text';
  967.                 break;
  968.             default:
  969.                 if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/'$value)) {
  970.                     $type 'timestamp';
  971.                 elseif (preg_match('/^\d{2}:\d{2}$/'$value)) {
  972.                     $type 'time';
  973.                 elseif (preg_match('/^\d{4}-\d{2}-\d{2}$/'$value)) {
  974.                     $type 'date';
  975.                 else {
  976.                     $type 'text';
  977.                 }
  978.                 break;
  979.             }
  980.         }
  981.  
  982.         if (!method_exists($this"_quote{$type}")) {
  983.             return $db->raiseError('type not defined: '.$type);
  984.         }
  985.         $value $this->{"_quote{$type}"}($value$quote);
  986.  
  987.         return $value;
  988.     }
  989.  
  990.     // }}}
  991.     // {{{ _quoteInteger()
  992.  
  993.     /**
  994.      * Convert a text value into a DBMS specific format that is suitable to
  995.      * compose query statements.
  996.      *
  997.      * @param string $value text string value that is intended to be converted.
  998.      * @param bool $quote determines if the value should be quoted and escaped
  999.      * @return string text string that represents the given argument value in
  1000.      *        a DBMS specific format.
  1001.      * @access protected
  1002.      */
  1003.     function _quoteInteger($value$quote)
  1004.     {
  1005.         return (int)$value;
  1006.     }
  1007.  
  1008.     // }}}
  1009.     // {{{ _quoteText()
  1010.  
  1011.     /**
  1012.      * Convert a text value into a DBMS specific format that is suitable to
  1013.      * compose query statements.
  1014.      *
  1015.      * @param string $value text string value that is intended to be converted.
  1016.      * @param bool $quote determines if the value should be quoted and escaped
  1017.      * @return string text string that already contains any DBMS specific
  1018.      *        escaped character sequences.
  1019.      * @access protected
  1020.      */
  1021.     function _quoteText($value$quote)
  1022.     {
  1023.         if (!$quote{
  1024.             return $value;
  1025.         }
  1026.         $db =$this->getDBInstance();
  1027.         if (PEAR::isError($db)) {
  1028.             return $db;
  1029.         }
  1030.  
  1031.         return "'".$db->escape($value)."'";
  1032.     }
  1033.  
  1034.     // }}}
  1035.     // {{{ _readFile()
  1036.  
  1037.     /**
  1038.      * Convert a text value into a DBMS specific format that is suitable to
  1039.      * compose query statements.
  1040.      *
  1041.      * @param string $value text string value that is intended to be converted.
  1042.      * @return string text string that represents the given argument value in
  1043.      *        a DBMS specific format.
  1044.      * @access protected
  1045.      */
  1046.     function _readFile($value)
  1047.     {
  1048.         $close = false;
  1049.         if (preg_match('/^(\w+:\/\/)(.*)$/'$value$match)) {
  1050.             $close = true;
  1051.             if ($match[1== 'file://'{
  1052.                 $value $match[2];
  1053.             }
  1054.             $value @fopen($value'r');
  1055.         }
  1056.  
  1057.         if (is_resource($value)) {
  1058.             $db =$this->getDBInstance();
  1059.             if (PEAR::isError($db)) {
  1060.                 return $db;
  1061.             }
  1062.  
  1063.             $fp $value;
  1064.             $value '';
  1065.             while (!@feof($fp)) {
  1066.                 $value.= @fread($fp$db->options['lob_buffer_length']);
  1067.             }
  1068.             if ($close{
  1069.                 @fclose($fp);
  1070.             }
  1071.         }
  1072.  
  1073.         return $value;
  1074.     }
  1075.  
  1076.     // }}}
  1077.     // {{{ _quoteLOB()
  1078.  
  1079.     /**
  1080.      * Convert a text value into a DBMS specific format that is suitable to
  1081.      * compose query statements.
  1082.      *
  1083.      * @param string $value text string value that is intended to be converted.
  1084.      * @param bool $quote determines if the value should be quoted and escaped
  1085.      * @return string text string that represents the given argument value in
  1086.      *        a DBMS specific format.
  1087.      * @access protected
  1088.      */
  1089.     function _quoteLOB($value$quote)
  1090.     {
  1091.         $value $this->_readFile($value);
  1092.         return $this->_quoteText($value$quote);
  1093.     }
  1094.  
  1095.     // }}}
  1096.     // {{{ _quoteCLOB()
  1097.  
  1098.     /**
  1099.      * Convert a text value into a DBMS specific format that is suitable to
  1100.      * compose query statements.
  1101.      *
  1102.      * @param string $value text string value that is intended to be converted.
  1103.      * @param bool $quote determines if the value should be quoted and escaped
  1104.      * @return string text string that represents the given argument value in
  1105.      *        a DBMS specific format.
  1106.      * @access protected
  1107.      */
  1108.     function _quoteCLOB($value$quote)
  1109.     {
  1110.         return $this->_quoteLOB($value$quote);
  1111.     }
  1112.  
  1113.     // }}}
  1114.     // {{{ _quoteBLOB()
  1115.  
  1116.     /**
  1117.      * Convert a text value into a DBMS specific format that is suitable to
  1118.      * compose query statements.
  1119.      *
  1120.      * @param string $value text string value that is intended to be converted.
  1121.      * @param bool $quote determines if the value should be quoted and escaped
  1122.      * @return string text string that represents the given argument value in
  1123.      *        a DBMS specific format.
  1124.      * @access protected
  1125.      */
  1126.     function _quoteBLOB($value$quote)
  1127.     {
  1128.         return $this->_quoteLOB($value$quote);
  1129.     }
  1130.  
  1131.     // }}}
  1132.     // {{{ _quoteBoolean()
  1133.  
  1134.     /**
  1135.      * Convert a text value into a DBMS specific format that is suitable to
  1136.      * compose query statements.
  1137.      *
  1138.      * @param string $value text string value that is intended to be converted.
  1139.      * @param bool $quote determines if the value should be quoted and escaped
  1140.      * @return string text string that represents the given argument value in
  1141.      *        a DBMS specific format.
  1142.      * @access protected
  1143.      */
  1144.     function _quoteBoolean($value$quote)
  1145.     {
  1146.         return ($value ? 1 : 0);
  1147.     }
  1148.  
  1149.     // }}}
  1150.     // {{{ _quoteDate()
  1151.  
  1152.     /**
  1153.      * Convert a text value into a DBMS specific format that is suitable to
  1154.      * compose query statements.
  1155.      *
  1156.      * @param string $value text string value that is intended to be converted.
  1157.      * @param bool $quote determines if the value should be quoted and escaped
  1158.      * @return string text string that represents the given argument value in
  1159.      *        a DBMS specific format.
  1160.      * @access protected
  1161.      */
  1162.     function _quoteDate($value$quote)
  1163.     {
  1164.         if ($value === 'CURRENT_DATE'{
  1165.             $db =$this->getDBInstance();
  1166.             if (PEAR::isError($db)) {
  1167.                 return $db;
  1168.             }
  1169.             if (isset($db->function&& is_a($db->function'MDB2_Driver_Function_Common')) {
  1170.                 return $db->function->now('date');
  1171.             }
  1172.             return 'CURRENT_DATE';
  1173.         }
  1174.         return $this->_quoteText($value$quote);
  1175.     }
  1176.  
  1177.     // }}}
  1178.     // {{{ _quoteTimestamp()
  1179.  
  1180.     /**
  1181.      * Convert a text value into a DBMS specific format that is suitable to
  1182.      * compose query statements.
  1183.      *
  1184.      * @param string $value text string value that is intended to be converted.
  1185.      * @param bool $quote determines if the value should be quoted and escaped
  1186.      * @return string text string that represents the given argument value in
  1187.      *        a DBMS specific format.
  1188.      * @access protected
  1189.      */
  1190.     function _quoteTimestamp($value$quote)
  1191.     {
  1192.         if ($value === 'CURRENT_TIMESTAMP'{
  1193.             $db =$this->getDBInstance();
  1194.             if (PEAR::isError($db)) {
  1195.                 return $db;
  1196.             }
  1197.             if (isset($db->function&& is_a($db->function'MDB2_Driver_Function_Common')) {
  1198.                 return $db->function->now('timestamp');
  1199.             }
  1200.             return 'CURRENT_TIMESTAMP';
  1201.         }
  1202.         return $this->_quoteText($value$quote);
  1203.     }
  1204.  
  1205.     // }}}
  1206.     // {{{ _quoteTime()
  1207.  
  1208.     /**
  1209.      * Convert a text value into a DBMS specific format that is suitable to
  1210.      *       compose query statements.
  1211.      *
  1212.      * @param string $value text string value that is intended to be converted.
  1213.      * @param bool $quote determines if the value should be quoted and escaped
  1214.      * @return string text string that represents the given argument value in
  1215.      *        a DBMS specific format.
  1216.      * @access protected
  1217.      */
  1218.     function _quoteTime($value$quote)
  1219.     {
  1220.         if ($value === 'CURRENT_TIME'{
  1221.             $db =$this->getDBInstance();
  1222.             if (PEAR::isError($db)) {
  1223.                 return $db;
  1224.             }
  1225.             if (isset($db->function&& is_a($db->function'MDB2_Driver_Function_Common')) {
  1226.                 return $db->function->now('time');
  1227.             }
  1228.             return 'CURRENT_TIME';
  1229.         }
  1230.         return $this->_quoteText($value$quote);
  1231.     }
  1232.  
  1233.     // }}}
  1234.     // {{{ _quoteFloat()
  1235.  
  1236.     /**
  1237.      * Convert a text value into a DBMS specific format that is suitable to
  1238.      * compose query statements.
  1239.      *
  1240.      * @param string $value text string value that is intended to be converted.
  1241.      * @param bool $quote determines if the value should be quoted and escaped
  1242.      * @return string text string that represents the given argument value in
  1243.      *        a DBMS specific format.
  1244.      * @access protected
  1245.      */
  1246.     function _quoteFloat($value$quote)
  1247.     {
  1248.         if (!$quote{
  1249.             return $value;
  1250.         }
  1251.         $db =$this->getDBInstance();
  1252.         if (PEAR::isError($db)) {
  1253.             return $db;
  1254.         }
  1255.  
  1256.         return $db->escape($value);
  1257.     }
  1258.  
  1259.     // }}}
  1260.     // {{{ _quoteDecimal()
  1261.  
  1262.     /**
  1263.      * Convert a text value into a DBMS specific format that is suitable to
  1264.      * compose query statements.
  1265.      *
  1266.      * @param string $value text string value that is intended to be converted.
  1267.      * @param bool $quote determines if the value should be quoted and escaped
  1268.      * @return string text string that represents the given argument value in
  1269.      *        a DBMS specific format.
  1270.      * @access protected
  1271.      */
  1272.     function _quoteDecimal($value$quote)
  1273.     {
  1274.         if (!$quote{
  1275.             return $value;
  1276.         }
  1277.         $db =$this->getDBInstance();
  1278.         if (PEAR::isError($db)) {
  1279.             return $db;
  1280.         }
  1281.  
  1282.         return $db->escape($value);
  1283.     }
  1284.  
  1285.     // }}}
  1286.     // {{{ writeLOBToFile()
  1287.  
  1288.     /**
  1289.      * retrieve LOB from the database
  1290.      *
  1291.      * @param resource $lob stream handle
  1292.      * @param string $file name of the file into which the LOb should be fetched
  1293.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  1294.      * @access protected
  1295.      */
  1296.     function writeLOBToFile($lob$file)
  1297.     {
  1298.         $db =$this->getDBInstance();
  1299.         if (PEAR::isError($db)) {
  1300.             return $db;
  1301.         }
  1302.  
  1303.         if (preg_match('/^(\w+:\/\/)(.*)$/'$file$match)) {
  1304.             if ($match[1== 'file://'{
  1305.                 $file $match[2];
  1306.             }
  1307.         }
  1308.  
  1309.         $fp @fopen($file'wb');
  1310.         while (!@feof($lob)) {
  1311.             $result @fread($lob$db->options['lob_buffer_length']);
  1312.             $read strlen($result);
  1313.             if (@fwrite($fp$result$read!= $read{
  1314.                 @fclose($fp);
  1315.                 return $db->raiseError(MDB2_ERRORnullnull,
  1316.                     'writeLOBToFile: could not write to the output file');
  1317.             }
  1318.         }
  1319.         @fclose($fp);
  1320.         return MDB2_OK;
  1321.     }
  1322.  
  1323.     // }}}
  1324.     // {{{ _retrieveLOB()
  1325.  
  1326.     /**
  1327.      * retrieve LOB from the database
  1328.      *
  1329.      * @param array $lob array
  1330.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  1331.      * @access protected
  1332.      */
  1333.     function _retrieveLOB(&$lob)
  1334.     {
  1335.         if (is_null($lob['value'])) {
  1336.             $lob['value'$lob['resource'];
  1337.         }
  1338.         $lob['loaded'= true;
  1339.         return MDB2_OK;
  1340.     }
  1341.  
  1342.     // }}}
  1343.     // {{{ readLOB()
  1344.  
  1345.     /**
  1346.      * Read data from large object input stream.
  1347.      *
  1348.      * @param resource $lob stream handle
  1349.      * @param string $data reference to a variable that will hold data
  1350.      *                           to be read from the large object input stream
  1351.      * @param integer $length    value that indicates the largest ammount ofdata
  1352.      *                           to be read from the large object input stream.
  1353.      * @return mixed the effective number of bytes read from the large object
  1354.      *                       input stream on sucess or an MDB2 error object.
  1355.      * @access public
  1356.      * @see endOfLOB()
  1357.      */
  1358.     function _readLOB($lob$length)
  1359.     {
  1360.         return substr($lob['value']$lob['position']$length);
  1361.     }
  1362.  
  1363.     // }}}
  1364.     // {{{ _endOfLOB()
  1365.  
  1366.     /**
  1367.      * Determine whether it was reached the end of the large object and
  1368.      * therefore there is no more data to be read for the its input stream.
  1369.      *
  1370.      * @param array $lob array
  1371.      * @return mixed true or false on success, a MDB2 error on failure
  1372.      * @access protected
  1373.      */
  1374.     function _endOfLOB($lob)
  1375.     {
  1376.         return $lob['endOfLOB'];
  1377.     }
  1378.  
  1379.     // }}}
  1380.     // {{{ destroyLOB()
  1381.  
  1382.     /**
  1383.      * Free any resources allocated during the lifetime of the large object
  1384.      * handler object.
  1385.      *
  1386.      * @param resource $lob stream handle
  1387.      * @access public
  1388.      */
  1389.     function destroyLOB($lob)
  1390.     {
  1391.         $lob_data stream_get_meta_data($lob);
  1392.         $lob_index $lob_data['wrapper_data']->lob_index;
  1393.         fclose($lob);
  1394.         if (isset($this->lobs[$lob_index])) {
  1395.             $this->_destroyLOB($this->lobs[$lob_index]);
  1396.             unset($this->lobs[$lob_index]);
  1397.         }
  1398.         return MDB2_OK;
  1399.     }
  1400.  
  1401.     // }}}
  1402.     // {{{ _destroyLOB()
  1403.  
  1404.     /**
  1405.      * Free any resources allocated during the lifetime of the large object
  1406.      * handler object.
  1407.      *
  1408.      * @param array $lob array
  1409.      * @access private
  1410.      */
  1411.     function _destroyLOB(&$lob)
  1412.     {
  1413.         return MDB2_OK;
  1414.     }
  1415.  
  1416.     // }}}
  1417.     // {{{ implodeArray()
  1418.  
  1419.     /**
  1420.      * apply a type to all values of an array and return as a comma seperated string
  1421.      * useful for generating IN statements
  1422.      *
  1423.      * @access public
  1424.      *
  1425.      * @param array $array data array
  1426.      * @param string $type determines type of the field
  1427.      *
  1428.      * @return string comma seperated values
  1429.      */
  1430.     function implodeArray($array$type = false)
  1431.     {
  1432.         if (!is_array($array|| empty($array)) {
  1433.             return 'NULL';
  1434.         }
  1435.         if ($type{
  1436.             foreach ($array as $value{
  1437.                 $return[$this->quote($value$type);
  1438.             }
  1439.         else {
  1440.             $return $array;
  1441.         }
  1442.         return implode(', '$return);
  1443.     }
  1444.  
  1445.     // }}}
  1446.     // {{{ mapNativeDatatype()
  1447.  
  1448.     /**
  1449.      * Maps a native array description of a field to a MDB2 datatype and length
  1450.      *
  1451.      * @param array  $field native field description
  1452.      * @return array containing the various possible types, length, sign, fixed
  1453.      * @access public
  1454.      */
  1455.     function mapNativeDatatype($field)
  1456.     {
  1457.         $db =$this->getDBInstance();
  1458.         if (PEAR::isError($db)) {
  1459.             return $db;
  1460.         }
  1461.  
  1462.         return $db->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  1463.             'mapNativeDatatype: method not implemented');
  1464.     }
  1465.  
  1466. }
  1467.  
  1468. ?>

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