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

Source for file pgsql.php

Documentation is available at pgsql.php

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP versions 4 and 5                                                 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox,                 |
  6. // | Stig. S. Bakken, Lukas Smith                                         |
  7. // | All rights reserved.                                                 |
  8. // +----------------------------------------------------------------------+
  9. // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB  |
  10. // | API as well as database abstraction for PHP applications.            |
  11. // | This LICENSE is in the BSD license style.                            |
  12. // |                                                                      |
  13. // | Redistribution and use in source and binary forms, with or without   |
  14. // | modification, are permitted provided that the following conditions   |
  15. // | are met:                                                             |
  16. // |                                                                      |
  17. // | Redistributions of source code must retain the above copyright       |
  18. // | notice, this list of conditions and the following disclaimer.        |
  19. // |                                                                      |
  20. // | Redistributions in binary form must reproduce the above copyright    |
  21. // | notice, this list of conditions and the following disclaimer in the  |
  22. // | documentation and/or other materials provided with the distribution. |
  23. // |                                                                      |
  24. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |
  25. // | Lukas Smith nor the names of his contributors may be used to endorse |
  26. // | or promote products derived from this software without specific prior|
  27. // | written permission.                                                  |
  28. // |                                                                      |
  29. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
  30. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
  31. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
  32. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
  33. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |
  34. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  35. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  36. // |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |
  37. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |
  38. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  39. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |
  40. // | POSSIBILITY OF SUCH DAMAGE.                                          |
  41. // +----------------------------------------------------------------------+
  42. // | Author: Paul Cooper <pgc@ucecom.com>                                 |
  43. // +----------------------------------------------------------------------+
  44. //
  45. // $Id: pgsql.php,v 1.23 2005/04/19 12:53:41 lsmith Exp $
  46.  
  47. require_once 'MDB2/Driver/Datatype/Common.php';
  48.  
  49. /**
  50.  * MDB2 PostGreSQL driver
  51.  *
  52.  * @package MDB2
  53.  * @category Database
  54.  * @author  Paul Cooper <pgc@ucecom.com>
  55.  */
  56. {
  57.     // {{{ convertResult()
  58.  
  59.     /**
  60.      * convert a value to a RDBMS independent MDB2 type
  61.      *
  62.      * @param mixed $value value to be converted
  63.      * @param int $type constant that specifies which type to convert to
  64.      * @return mixed converted value or a MDB2 error on failure
  65.      * @access public
  66.      */
  67.     function convertResult($value$type)
  68.     {
  69.         if (is_null($value)) {
  70.             return null;
  71.         }
  72.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  73.         switch ($type{
  74.         case 'boolean':
  75.             return $value == 't';
  76.         case 'float':
  77.             return doubleval($value);
  78.         case 'date':
  79.             return $value;
  80.         case 'time':
  81.             return $value;
  82.         case 'timestamp':
  83.             return substr($value0strlen('YYYY-MM-DD HH:MM:SS'));
  84.         default:
  85.             return $this->_baseConvertResult($value$type);
  86.         }
  87.     }
  88.  
  89.     // }}}
  90.     // {{{ _getTextDeclaration()
  91.  
  92.     /**
  93.      * Obtain DBMS specific SQL code portion needed to declare a text type
  94.      * field to be used in statements like CREATE TABLE.
  95.      *
  96.      * @param string $name   name the field to be declared.
  97.      * @param array $field  associative array with the name of the properties
  98.      *       of the field being declared as array indexes. Currently, the types
  99.      *       of supported field properties are as follows:
  100.      *
  101.      *       length
  102.      *           Integer value that determines the maximum length of the text
  103.      *           field. If this argument is missing the field should be
  104.      *           declared to have the longest length allowed by the DBMS.
  105.      *
  106.      *       default
  107.      *           Text value to be used as default for this field.
  108.      *
  109.      *       notnull
  110.      *           Boolean flag that indicates whether this field is constrained
  111.      *           to not be set to null.
  112.      * @return string  DBMS specific SQL code portion that should be used to
  113.      *       declare the specified field.
  114.      * @access protected
  115.      */
  116.     function _getTextDeclaration($name$field)
  117.     {
  118.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  119.         $type = isset($field['length']'VARCHAR ('.$field['length'].')' 'TEXT';
  120.         $default = isset($field['default']' DEFAULT'.
  121.             $this->quote($field['default']'text''';
  122.         $notnull = isset($field['notnull']' NOT NULL' '';
  123.         return $name.' '.$type.$default.$notnull;
  124.     }
  125.  
  126.     // }}}
  127.     // {{{ _getCLOBDeclaration()
  128.  
  129.     /**
  130.      * Obtain DBMS specific SQL code portion needed to declare a character
  131.      * large object type field to be used in statements like CREATE TABLE.
  132.      *
  133.      * @param string $name   name the field to be declared.
  134.      * @param array $field  associative array with the name of the properties
  135.      *       of the field being declared as array indexes. Currently, the types
  136.      *       of supported field properties are as follows:
  137.      *
  138.      *       length
  139.      *           Integer value that determines the maximum length of the large
  140.      *           object field. If this argument is missing the field should be
  141.      *           declared to have the longest length allowed by the DBMS.
  142.      *
  143.      *       notnull
  144.      *           Boolean flag that indicates whether this field is constrained
  145.      *           to not be set to null.
  146.      * @return string  DBMS specific SQL code portion that should be used to
  147.      *       declare the specified field.
  148.      * @access protected
  149.      */
  150.     function _getCLOBDeclaration($name$field)
  151.     {
  152.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  153.         $notnull = isset($field['notnull']' NOT NULL' '';
  154.         return $name.' OID'.$notnull;
  155.     }
  156.  
  157.     // }}}
  158.     // {{{ _getBLOBDeclaration()
  159.  
  160.     /**
  161.      * Obtain DBMS specific SQL code portion needed to declare a binary large
  162.      * object type field to be used in statements like CREATE TABLE.
  163.      *
  164.      * @param string $name   name the field to be declared.
  165.      * @param array $field  associative array with the name of the properties
  166.      *       of the field being declared as array indexes. Currently, the types
  167.      *       of supported field properties are as follows:
  168.      *
  169.      *       length
  170.      *           Integer value that determines the maximum length of the large
  171.      *           object field. If this argument is missing the field should be
  172.      *           declared to have the longest length allowed by the DBMS.
  173.      *
  174.      *       notnull
  175.      *           Boolean flag that indicates whether this field is constrained
  176.      *           to not be set to null.
  177.      * @return string  DBMS specific SQL code portion that should be used to
  178.      *       declare the specified field.
  179.      * @access protected
  180.      */
  181.     function _getBLOBDeclaration($name$field)
  182.     {
  183.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  184.         $notnull = isset($field['notnull']' NOT NULL' '';
  185.         return $name.' OID'.$notnull;
  186.     }
  187.  
  188.     // }}}
  189.     // {{{ _getBooleanDeclaration()
  190.  
  191.     /**
  192.      * Obtain DBMS specific SQL code portion needed to declare a boolean type
  193.      * field to be used in statements like CREATE TABLE.
  194.      *
  195.      * @param string $name name the field to be declared.
  196.      * @param array $field associative array with the name of the properties
  197.      *        of the field being declared as array indexes. Currently, the types
  198.      *        of supported field properties are as follows:
  199.      *
  200.      *        default
  201.      *            Boolean value to be used as default for this field.
  202.      *
  203.      *        notnullL
  204.      *            Boolean flag that indicates whether this field is constrained
  205.      *            to not be set to null.
  206.      * @return string DBMS specific SQL code portion that should be used to
  207.      *        declare the specified field.
  208.      * @access protected
  209.      */
  210.     function _getBooleanDeclaration($name$field)
  211.     {
  212.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  213.         $default = isset($field['default']' DEFAULT '.
  214.             $this->quote($field['default']'boolean''';
  215.         $notnull = isset($field['notnull']' NOT NULL' '';
  216.         return $name.' BOOLEAN'.$default.$notnull;
  217.     }
  218.  
  219.     // }}}
  220.     // {{{ _getDateDeclaration()
  221.  
  222.     /**
  223.      * Obtain DBMS specific SQL code portion needed to declare a date type
  224.      * field to be used in statements like CREATE TABLE.
  225.      *
  226.      * @param string $name   name the field to be declared.
  227.      * @param array $field  associative array with the name of the properties
  228.      *       of the field being declared as array indexes. Currently, the types
  229.      *       of supported field properties are as follows:
  230.      *
  231.      *       default
  232.      *           Date value to be used as default for this field.
  233.      *
  234.      *       notnull
  235.      *           Boolean flag that indicates whether this field is constrained
  236.      *           to not be set to null.
  237.      * @return string  DBMS specific SQL code portion that should be used to
  238.      *       declare the specified field.
  239.      * @access protected
  240.      */
  241.     function _getDateDeclaration($name$field)
  242.     {
  243.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  244.         $default = isset($field['default']' DEFAULT '.
  245.             $this->quote($field['default']'date''';
  246.         $notnull = isset($field['notnull']' NOT NULL' '';
  247.         return $name.' DATE'.$default.$notnull;
  248.     }
  249.  
  250.     // }}}
  251.     // {{{ _getTimeDeclaration()
  252.  
  253.     /**
  254.      * Obtain DBMS specific SQL code portion needed to declare a time
  255.      * field to be used in statements like CREATE TABLE.
  256.      *
  257.      * @param string $name   name the field to be declared.
  258.      * @param array $field  associative array with the name of the properties
  259.      *       of the field being declared as array indexes. Currently, the types
  260.      *       of supported field properties are as follows:
  261.      *
  262.      *       default
  263.      *           Time value to be used as default for this field.
  264.      *
  265.      *       notnull
  266.      *           Boolean flag that indicates whether this field is constrained
  267.      *           to not be set to null.
  268.      * @return string  DBMS specific SQL code portion that should be used to
  269.      *       declare the specified field.
  270.      * @access protected
  271.      */
  272.     function _getTimeDeclaration($name$field)
  273.     {
  274.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  275.         $default = isset($field['default']' DEFAULT '.
  276.             $this->quote($field['default']'time''';
  277.         $notnull = isset($field['notnull']' NOT NULL' '';
  278.         return $name.' TIME without time zone'.$default.$notnull;
  279.     }
  280.  
  281.     // }}}
  282.     // {{{ _getTimestampDeclaration()
  283.  
  284.     /**
  285.      * Obtain DBMS specific SQL code portion needed to declare a timestamp
  286.      * field to be used in statements like CREATE TABLE.
  287.      *
  288.      * @param string $name name the field to be declared.
  289.      * @param array $field associative array with the name of the properties
  290.      *        of the field being declared as array indexes. Currently, the types
  291.      *        of supported field properties are as follows:
  292.      *
  293.      *        default
  294.      *            Timestamp value to be used as default for this field.
  295.      *
  296.      *        notnull
  297.      *            Boolean flag that indicates whether this field is constrained
  298.      *            to not be set to null.
  299.      * @return string DBMS specific SQL code portion that should be used to
  300.      *        declare the specified field.
  301.      * @access protected
  302.      */
  303.     function _getTimestampDeclaration($name$field)
  304.     {
  305.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  306.         $default = isset($field['default']' DEFAULT '.
  307.             $this->quote($field['default']'timestamp''';
  308.         $notnull = isset($field['notnull']' NOT NULL' '';
  309.         return $name.' TIMESTAMP without time zone'.$default.$notnull;
  310.     }
  311.  
  312.     // }}}
  313.     // {{{ _getFloatDeclaration()
  314.  
  315.     /**
  316.      * Obtain DBMS specific SQL code portion needed to declare a float type
  317.      * field to be used in statements like CREATE TABLE.
  318.      *
  319.      * @param string $name   name the field to be declared.
  320.      * @param array $field  associative array with the name of the properties
  321.      *       of the field being declared as array indexes. Currently, the types
  322.      *       of supported field properties are as follows:
  323.      *
  324.      *       default
  325.      *           Float value to be used as default for this field.
  326.      *
  327.      *       notnull
  328.      *           Boolean flag that indicates whether this field is constrained
  329.      *           to not be set to null.
  330.      * @return string  DBMS specific SQL code portion that should be used to
  331.      *       declare the specified field.
  332.      * @access protected
  333.      */
  334.     function _getFloatDeclaration($name$field)
  335.     {
  336.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  337.         $default = isset($field['default']' DEFAULT '.
  338.             $this->quote($field['default']'float''';
  339.         $notnull = isset($field['notnull']' NOT NULL' '';
  340.         return $name.' FLOAT8'.$default.$notnull;
  341.     }
  342.  
  343.     // }}}
  344.     // {{{ _getDecimalDeclaration()
  345.  
  346.     /**
  347.      * Obtain DBMS specific SQL code portion needed to declare a decimal type
  348.      * field to be used in statements like CREATE TABLE.
  349.      *
  350.      * @param string $name   name the field to be declared.
  351.      * @param array $field  associative array with the name of the properties
  352.      *       of the field being declared as array indexes. Currently, the types
  353.      *       of supported field properties are as follows:
  354.      *
  355.      *       default
  356.      *           Decimal value to be used as default for this field.
  357.      *
  358.      *       notnull
  359.      *           Boolean flag that indicates whether this field is constrained
  360.      *           to not be set to null.
  361.      * @return string  DBMS specific SQL code portion that should be used to
  362.      *       declare the specified field.
  363.      * @access protected
  364.      */
  365.     function _getDecimalDeclaration($name$field)
  366.     {
  367.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  368.         $default = isset($field['default']' DEFAULT '.
  369.             $this->quote($field['default']'float''';
  370.         $notnull = isset($field['notnull']' NOT NULL' '';
  371.         return $name.' NUMERIC(18, '.$db->options['decimal_places'].')'.$default.$notnull;
  372.     }
  373.  
  374.     // }}}
  375.     // {{{ _quoteLOB()
  376.  
  377.     /**
  378.      * Convert a text value into a DBMS specific format that is suitable to
  379.      * compose query statements.
  380.      *
  381.      * @param           $value 
  382.      * @return string text string that represents the given argument value in
  383.      *       a DBMS specific format.
  384.      * @access protected
  385.      */
  386.     function _quoteLOB($value)
  387.     {
  388.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  389.         $connect $db->connect();
  390.         if (PEAR::isError($connect)) {
  391.             return $connect;
  392.         }
  393.         if (!$db->in_transaction && !@pg_query($db->connection'BEGIN')) {
  394.             return $db->raiseError(MDB2_ERRORnullnull,
  395.                 'error starting transaction');
  396.         }
  397.         if (is_resource($value)) {
  398.             $close = false;
  399.         elseif (preg_match('/^(\w+:\/\/)(.*)$/'$value$match)) {
  400.             $close = true;
  401.             if ($match[1== 'file://'{
  402.                 $value $match[2];
  403.             }
  404.             // disabled use of pg_lo_import() for now with the following line
  405.             $value @fopen($value'r');
  406.         else {
  407.             $close = true;
  408.             $fp @tmpfile();
  409.             @fwrite($fp$value);
  410.             @rewind($fp);
  411.             $value $fp;
  412.         }
  413.         $result = false;
  414.         if (is_resource($value)) {
  415.             if (($lo @pg_lo_create($db->connection))) {
  416.                 if (($handle @pg_lo_open($db->connection$lo'w'))) {
  417.                     while (!@feof($value)) {
  418.                         $data @fread($value$db->options['lob_buffer_length']);
  419.                         if ($data === ''{
  420.                             break;
  421.                         }
  422.                         if (!@pg_lo_write($handle$data)) {
  423.                             $result $db->raiseError();
  424.                             break;
  425.                         }
  426.                     }
  427.                     if (!PEAR::isError($result)) {
  428.                         $result strval($lo);
  429.                     }
  430.                     @pg_lo_close($handle);
  431.                 else {
  432.                     $result $db->raiseError();
  433.                     @pg_lo_unlink($db->connection$lo);
  434.                 }
  435.             }
  436.             if ($close{
  437.                 @fclose($value);
  438.             }
  439.         else {
  440.             if (!@pg_lo_import($db->connection$value)) {
  441.                 $result $db->raiseError();
  442.             }
  443.         }
  444.         if (!$db->in_transaction{
  445.             if (PEAR::isError($result)) {
  446.                 @pg_query($db->connection'ROLLBACK');
  447.             else {
  448.                 @pg_query($db->connection'COMMIT');
  449.             }
  450.         }
  451.         return $result;
  452.     }
  453.  
  454.     // }}}
  455.     // {{{ _quoteCLOB()
  456.  
  457.     /**
  458.      * Convert a text value into a DBMS specific format that is suitable to
  459.      * compose query statements.
  460.      *
  461.      * @param           $value 
  462.      * @return string text string that represents the given argument value in
  463.      *       a DBMS specific format.
  464.      * @access protected
  465.      */
  466.     function _quoteCLOB($value)
  467.     {
  468.         return $this->_quoteLOB($value);
  469.     }
  470.  
  471.     // }}}
  472.     // {{{ _quoteBLOB()
  473.  
  474.     /**
  475.      * Convert a text value into a DBMS specific format that is suitable to
  476.      * compose query statements.
  477.      *
  478.      * @param           $value 
  479.      * @return string text string that represents the given argument value in
  480.      *       a DBMS specific format.
  481.      * @access protected
  482.      */
  483.     function _quoteBLOB($value)
  484.     {
  485.         return $this->_quoteLOB($value);
  486.     }
  487.  
  488.     // }}}
  489.     // {{{ _quoteBoolean()
  490.  
  491.     /**
  492.      * Convert a text value into a DBMS specific format that is suitable to
  493.      * compose query statements.
  494.      *
  495.      * @param string $value text string value that is intended to be converted.
  496.      * @return string text string that represents the given argument value in
  497.      *        a DBMS specific format.
  498.      * @access protected
  499.      */
  500.     function _quoteBoolean($value)
  501.     {
  502.         return ($value "'t'" "'f'");
  503.     }
  504.  
  505.     // }}}
  506.     // {{{ _quoteFloat()
  507.  
  508.     /**
  509.      * Convert a text value into a DBMS specific format that is suitable to
  510.      * compose query statements.
  511.      *
  512.      * @param string $value text string value that is intended to be converted.
  513.      * @return string text string that represents the given argument value in
  514.      *       a DBMS specific format.
  515.      * @access protected
  516.      */
  517.     function _quoteFloat($value)
  518.     {
  519.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  520.         return $value;
  521.     }
  522.  
  523.     // }}}
  524.     // {{{ _quoteDecimal()
  525.  
  526.     /**
  527.      * Convert a text value into a DBMS specific format that is suitable to
  528.      * compose query statements.
  529.      *
  530.      * @param string $value text string value that is intended to be converted.
  531.      * @return string text string that represents the given argument value in
  532.      *       a DBMS specific format.
  533.      * @access protected
  534.      */
  535.     function _quoteDecimal($value)
  536.     {
  537.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  538.         return $value;
  539.     }
  540.  
  541.     // }}}
  542.     // {{{ _retrieveLOB()
  543.  
  544.     /**
  545.      * retrieve LOB from the database
  546.      *
  547.      * @param int $lob handle to a lob created by the createLOB() function
  548.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  549.      * @access protected
  550.      */
  551.     function _retrieveLOB($lob)
  552.     {
  553.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  554.         if (!isset($db->lobs[$lob])) {
  555.             return $db->raiseError(MDB2_ERROR_INVALIDnullnull,
  556.                 'did not specify a valid lob');
  557.         }
  558.         if (!isset($db->lobs[$lob]['handle'])) {
  559.             if (!$db->in_transaction{
  560.                 if (!pg_query($db->connection'BEGIN')) {
  561.                     return $db->raiseError();
  562.                 }
  563.                 $db->lobs[$lob]['in_transaction'= true;
  564.             }
  565.             $db->lobs[$lob]['handle'=
  566.                 @pg_lo_open($db->connection$db->lobs[$lob]['value']'r');
  567.             if (!$db->lobs[$lob]['handle']{
  568.                 if (isset($db->lobs[$lob]['in_transaction'])) {
  569.                     @pg_query($db->connection'END');
  570.                     unset($db->lobs[$lob]['in_transaction']);
  571.                 }
  572.                 unset($db->lobs[$lob]['value']);
  573.                 return $db->raiseError();
  574.             }
  575.         }
  576.         return MDB2_OK;
  577.     }
  578.  
  579.     // }}}
  580.     // {{{ _endOfResultLOB()
  581.  
  582.     /**
  583.      * Determine whether it was reached the end of the large object and
  584.      * therefore there is no more data to be read for the its input stream.
  585.      *
  586.      * @param int    $lob handle to a lob created by the createLOB() function
  587.      * @return mixed true or false on success, a MDB2 error on failure
  588.      * @access protected
  589.      */
  590.     function _endOfResultLOB($lob)
  591.     {
  592.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  593.         $lobresult $this->_retrieveLOB($lob);
  594.         if (PEAR::isError($lobresult)) {
  595.             return $lobresult;
  596.         }
  597.         return isset($db->lobs[$lob]['end_of_LOB']);
  598.     }
  599.  
  600.     // }}}
  601.     // {{{ _readResultLOB()
  602.  
  603.     /**
  604.      * Read data from large object input stream.
  605.      *
  606.      * @param int $lob handle to a lob created by the createLOB() function
  607.      * @param blob $data reference to a variable that will hold data to be
  608.      *       read from the large object input stream
  609.      * @param int $length integer value that indicates the largest ammount of
  610.      *       data to be read from the large object input stream.
  611.      * @return mixed length on success, a MDB2 error on failure
  612.      * @access protected
  613.      */
  614.     function _readResultLOB($lob&$data$length)
  615.     {
  616.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  617.         $lobresult $this->_retrieveLOB($lob);
  618.         if (PEAR::isError($lobresult)) {
  619.             return $lobresult;
  620.         }
  621.         $data @pg_lo_read($db->lobs[$lob]['handle']$length);
  622.         if (!is_string($data)) {
  623.              return $db->raiseError();
  624.         }
  625.         if (($length strlen($data)) == 0{
  626.             $db->lobs[$lob]['end_of_LOB'= true;
  627.         }
  628.         return $length;
  629.     }
  630.  
  631.     // }}}
  632.     // {{{ _destroyResultLOB()
  633.  
  634.     /**
  635.      * Free any resources allocated during the lifetime of the large object
  636.      * handler object.
  637.      *
  638.      * @param int $lob handle to a lob created by the createLOB() function
  639.      * @access protected
  640.      */
  641.     function _destroyResultLOB($lob)
  642.     {
  643.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  644.         if (isset($db->lobs[$lob])) {
  645.             if (isset($db->lobs[$lob]['value'])) {
  646.                 @pg_lo_close($db->lobs[$lob]['handle']);
  647.                 if (isset($db->lobs[$lob]['in_transaction'])) {
  648.                     @pg_query($db->connection'END');
  649.                 }
  650.             }
  651.             $db->lobs[$lob'';
  652.         }
  653.     }
  654.  
  655.     // }}}
  656.     // {{{ mapNativeDatatype()
  657.  
  658.     /**
  659.      * Maps a native array description of a field to a MDB2 datatype and length
  660.      *
  661.      * @param array  $field native field description
  662.      * @return array containing the various possible types and the length
  663.      * @access public
  664.      */
  665.     function mapNativeDatatype($field)
  666.     {
  667.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  668.         $db_type preg_replace('/\d/',''strtolower($field['typname']) );
  669.         $length $field['attlen'];
  670.         if ($length == '-1'{
  671.             $length $field['atttypmod']-4;
  672.         }
  673.         if ((int)$length <= 0{
  674.             $length = null;
  675.         }
  676.         $type = array();
  677.         switch ($db_type{
  678.         case 'int':
  679.             $type['integer';
  680.             if ($length == '1'{
  681.                 $type['boolean';
  682.             }
  683.             break;
  684.         case 'bool':
  685.             $type['boolean';
  686.             $length = null;
  687.             break;
  688.         case 'text':
  689.         case 'char':
  690.         case 'varchar':
  691.         case 'bpchar':
  692.             $type['text';
  693.             if ($length == '1'{
  694.                 $type['boolean';
  695.             elseif (strstr($db_type'text'))
  696.                 $type['clob';
  697.             break;
  698.         case 'date':
  699.             $type['date';
  700.             $length = null;
  701.             break;
  702.         case 'datetime':
  703.         case 'timestamp':
  704.             $type['timestamp';
  705.             $length = null;
  706.             break;
  707.         case 'time':
  708.             $type['time';
  709.             $length = null;
  710.             break;
  711.         case 'float':
  712.         case 'double':
  713.         case 'real':
  714.             $type['float';
  715.             break;
  716.         case 'decimal':
  717.         case 'money':
  718.         case 'numeric':
  719.             $type['decimal';
  720.             break;
  721.         case 'tinyblob':
  722.         case 'mediumblob':
  723.         case 'longblob':
  724.         case 'blob':
  725.             $type['blob';
  726.             $length = null;
  727.             break;
  728.         case 'oid':
  729.             $type['blob';
  730.             $type['clob';
  731.             $length = null;
  732.             break;
  733.         case 'year':
  734.             $type['integer';
  735.             $type['date';
  736.             $length = null;
  737.             break;
  738.         default:
  739.             return $db->raiseError(MDB2_ERRORnullnull,
  740.                 'getTableFieldDefinition: unknown database attribute type');
  741.         }
  742.  
  743.         return array($type$length);
  744.     }
  745.     
  746.     // }}}
  747. }
  748. ?>

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