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

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