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

Source for file fbsql.php

Documentation is available at fbsql.php

  1. <?php
  2. // vim: set et ts=4 sw=4 fdm=marker:
  3. // +----------------------------------------------------------------------+
  4. // | PHP versions 4 and 5                                                 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox,                 |
  7. // | Stig. S. Bakken, Lukas Smith                                         |
  8. // | All rights reserved.                                                 |
  9. // +----------------------------------------------------------------------+
  10. // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB  |
  11. // | API as well as database abstraction for PHP applications.            |
  12. // | This LICENSE is in the BSD license style.                            |
  13. // |                                                                      |
  14. // | Redistribution and use in source and binary forms, with or without   |
  15. // | modification, are permitted provided that the following conditions   |
  16. // | are met:                                                             |
  17. // |                                                                      |
  18. // | Redistributions of source code must retain the above copyright       |
  19. // | notice, this list of conditions and the following disclaimer.        |
  20. // |                                                                      |
  21. // | Redistributions in binary form must reproduce the above copyright    |
  22. // | notice, this list of conditions and the following disclaimer in the  |
  23. // | documentation and/or other materials provided with the distribution. |
  24. // |                                                                      |
  25. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |
  26. // | Lukas Smith nor the names of his contributors may be used to endorse |
  27. // | or promote products derived from this software without specific prior|
  28. // | written permission.                                                  |
  29. // |                                                                      |
  30. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
  31. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
  32. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
  33. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
  34. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |
  35. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  36. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  37. // |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |
  38. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |
  39. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  40. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |
  41. // | POSSIBILITY OF SUCH DAMAGE.                                          |
  42. // +----------------------------------------------------------------------+
  43. // | Author: Lukas Smith <smith@backendmedia.com>                         |
  44. // +----------------------------------------------------------------------+
  45. //
  46. // $Id: fbsql.php,v 1.16 2005/04/19 12:53:40 lsmith Exp $
  47. //
  48.  
  49. require_once 'MDB2/Driver/Datatype/Common.php';
  50.  
  51. /**
  52.  * MDB2 FrontbaseSQL driver
  53.  *
  54.  * @package MDB2
  55.  * @category Database
  56.  * @author  Lukas Smith <smith@backendmedia.com>
  57.  */
  58. {
  59.     // }}}
  60.     // {{{ convertResult()
  61.  
  62.     /**
  63.      * convert a value to a RDBMS indepdenant MDB2 type
  64.      *
  65.      * @param mixed  $value   value to be converted
  66.      * @param int    $type    constant that specifies which type to convert to
  67.      * @return mixed converted value
  68.      * @access public
  69.      */
  70.     function convertResult($value$type)
  71.     {
  72.         if (is_null($value)) {
  73.             return null;
  74.         }
  75.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  76.         switch ($type{
  77.          case 'boolean':
  78.              return $value == 'T';
  79.          case 'time':
  80.             if ($value[0== '+'{
  81.                 return substr($value1);
  82.             else {
  83.                 return $value;
  84.             }
  85.         default:
  86.             return $this->_baseConvertResult($value$type);
  87.         }
  88.         return $this->_baseConvertResult($value$type);
  89.     }
  90.  
  91.     // }}}
  92.     // {{{ _getIntegerDeclaration()
  93.  
  94.     /**
  95.      * Obtain DBMS specific SQL code portion needed to declare an integer type
  96.      * field to be used in statements like CREATE TABLE.
  97.      *
  98.      * @param string  $name   name the field to be declared.
  99.      * @param string  $field  associative array with the name of the properties
  100.      *                         of the field being declared as array indexes.
  101.      *                         Currently, the types of supported field
  102.      *                         properties are as follows:
  103.      *
  104.      *                        unsigned
  105.      *                         Boolean flag that indicates whether the field
  106.      *                         should be declared as unsigned integer if
  107.      *                         possible.
  108.      *
  109.      *                        default
  110.      *                         Integer value to be used as default for this
  111.      *                         field.
  112.      *
  113.      *                        notnull
  114.      *                         Boolean flag that indicates whether this field is
  115.      *                         constrained to not be set to null.
  116.      * @return string  DBMS specific SQL code portion that should be used to
  117.      *                  declare the specified field.
  118.      * @access protected
  119.      */
  120.     function _getIntegerDeclaration($name$field)
  121.     {
  122.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  123.         if (isset($field['unsigned'])) {
  124.             $this->warnings[= "unsigned integer field \"$name\" is being
  125.                 declared as signed integer";
  126.         }
  127.         $default = isset($field['default']' DEFAULT '.
  128.             $this->quote($field['default']'integer''';
  129.         $notnull = isset($field['notnull']' NOT NULL' '';
  130.         return $name.' INT'.$default.$notnull;
  131.     }
  132.  
  133.     // }}}
  134.     // {{{ _getTextDeclaration()
  135.  
  136.     /**
  137.      * Obtain DBMS specific SQL code portion needed to declare an text type
  138.      * field to be used in statements like CREATE TABLE.
  139.      *
  140.      * @param string $name name the field to be declared.
  141.     * @param array $field associative array with the name of the properties
  142.      *        of the field being declared as array indexes. Currently, the types
  143.      *        of supported field properties are as follows:
  144.     *
  145.      *        length
  146.      *            Integer value that determines the maximum length of the text
  147.      *            field. If this argument is missing the field should be
  148.      *            declared to have the longest length allowed by the DBMS.
  149.      *
  150.      *        default
  151.      *            Text value to be used as default for this field.
  152.      *
  153.      *        notnull
  154.      *            Boolean flag that indicates whether this field is constrained
  155.      *            to not be set to NULL.
  156.      * @return string DBMS specific SQL code portion that should be used to
  157.      *        declare the specified field.
  158.      * @access protected
  159.      */
  160.     function _getTextDeclaration($name$field)
  161.     {
  162.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  163.         $default = isset($field['default']' DEFAULT '.
  164.             $this->quote($field['default']'text''';
  165.         $notnull = isset($field['notnull']' NOT NULL' '';
  166.         $length = isset($field['length']$field['length'$db->max_text_length;
  167.         return $name.' VARCHAR ('.$length.')'.$default.$notnull;
  168.     }
  169.  
  170.     // }}}
  171.     // {{{ _getCLOBDeclaration()
  172.  
  173.     /**
  174.      * Obtain DBMS specific SQL code portion needed to declare an character
  175.      * large object type field to be used in statements like CREATE TABLE.
  176.      *
  177.      * @param string  $name   name the field to be declared.
  178.      * @param string  $field  associative array with the name of the
  179.      *                         properties of the field being declared as array
  180.      *                         indexes. Currently, the types of supported field
  181.      *                         properties are as follows:
  182.      *
  183.      *                        length
  184.      *                         Integer value that determines the maximum length
  185.      *                         of the large object field. If this argument is
  186.      *                         missing the field should be declared to have the
  187.      *                         longest length allowed by the DBMS.
  188.      *
  189.      *                        notnull
  190.      *                         Boolean flag that indicates whether this field
  191.      *                         is constrained to not be set to null.
  192.      * @return string  DBMS specific SQL code portion that should be used to
  193.      *                  declare the specified field.
  194.      * @access protected
  195.      */
  196.     function _getCLOBDeclaration($name$field)
  197.     {
  198.         return "$name CLOB".(isset($field['notnull']' NOT NULL' '');
  199.     }
  200.  
  201.     // }}}
  202.     // {{{ _getBLOBDeclaration()
  203.  
  204.     /**
  205.      * Obtain DBMS specific SQL code portion needed to declare an binary large
  206.      * object type field to be used in statements like CREATE TABLE.
  207.      *
  208.      * @param string  $name   name the field to be declared.
  209.      * @param string  $field  associative array with the name of the properties
  210.      *                         of the field being declared as array indexes.
  211.      *                         Currently, the types of supported field
  212.      *                         properties are as follows:
  213.      *
  214.      *                        length
  215.      *                         Integer value that determines the maximum length
  216.      *                         of the large object field. If this argument is
  217.      *                         missing the field should be declared to have the
  218.      *                         longest length allowed by the DBMS.
  219.      *
  220.      *                        notnull
  221.      *                         Boolean flag that indicates whether this field is
  222.      *                         constrained to not be set to null.
  223.      * @return string  DBMS specific SQL code portion that should be used to
  224.      *                  declare the specified field.
  225.      * @access protected
  226.      */
  227.     function _getBLOBDeclaration($name$field)
  228.     {
  229.         return "$name BLOB".(isset($field['notnull']' NOT NULL' '');
  230.     }
  231.  
  232.     // }}}
  233.     // {{{ _getBooleanDeclaration()
  234.  
  235.     /**
  236.      * Obtain DBMS specific SQL code portion needed to declare a boolean type
  237.      * field to be used in statements like CREATE TABLE.
  238.      *
  239.      * @param string $name name the field to be declared.
  240.      * @param array $field associative array with the name of the properties
  241.      *        of the field being declared as array indexes. Currently, the types
  242.      *        of supported field properties are as follows:
  243.      *
  244.      *        default
  245.      *            Boolean value to be used as default for this field.
  246.      *
  247.      *        notnullL
  248.      *            Boolean flag that indicates whether this field is constrained
  249.      *            to not be set to NULL.
  250.      * @return string DBMS specific SQL code portion that should be used to
  251.      *        declare the specified field.
  252.      * @access protected
  253.      */
  254.     function _getBooleanDeclaration($name$field)
  255.     {
  256.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  257.         $default = isset($field['default']' DEFAULT '.
  258.             $this->quote($field['default']'boolean''';
  259.         $notnull = isset($field['notnull']' NOT NULL' '';
  260.         return $name.' BOOLEAN)'.$default.$notnull;
  261.     }
  262.  
  263.     // }}}
  264.     // {{{ _getDateDeclaration()
  265.  
  266.     /**
  267.      * Obtain DBMS specific SQL code portion needed to declare an date type
  268.      * field to be used in statements like CREATE TABLE.
  269.      *
  270.      * @param string  $name   name the field to be declared.
  271.      * @param string  $field  associative array with the name of the properties
  272.      *                         of the field being declared as array indexes.
  273.      *                         Currently, the types of supported field properties
  274.      *                         are as follows:
  275.      *
  276.      *                        default
  277.      *                         Date value to be used as default for this field.
  278.      *
  279.      *                        notnull
  280.      *                         Boolean flag that indicates whether this field is
  281.      *                         constrained to not be set to null.
  282.      * @return string  DBMS specific SQL code portion that should be used to
  283.      *                  declare the specified field.
  284.      * @access protected
  285.      */
  286.     function _getDateDeclaration($name$field)
  287.     {
  288.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  289.         $default = isset($field['default']' DEFAULT DATE '.
  290.             $this->quote($field['default']'date''';
  291.         $notnull = isset($field['notnull']' NOT NULL' '';
  292.         return $name.' DATE'.$default.$notnull;
  293.     }
  294.  
  295.     // }}}
  296.     // {{{ _getTimestampDeclaration()
  297.  
  298.     /**
  299.      * Obtain DBMS specific SQL code portion needed to declare an timestamp
  300.      * type field to be used in statements like CREATE TABLE.
  301.      *
  302.      * @param string  $name   name the field to be declared.
  303.      * @param string  $field  associative array with the name of the properties
  304.      *                         of the field being declared as array indexes.
  305.      *                         Currently, the types of supported field
  306.      *                         properties are as follows:
  307.      *
  308.      *                        default
  309.      *                         Time stamp value to be used as default for this
  310.      *                         field.
  311.      *
  312.      *                        notnull
  313.      *                         Boolean flag that indicates whether this field is
  314.      *                         constrained to not be set to null.
  315.      * @return string  DBMS specific SQL code portion that should be used to
  316.      *                  declare the specified field.
  317.      * @access protected
  318.      */
  319.     function _getTimestampDeclaration($name$field)
  320.     {
  321.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  322.         $default = isset($field['default']' DEFAULT TIMESTAMP '.
  323.             $this->quote($field['default']'timestamp''';
  324.         $notnull = isset($field['notnull']' NOT NULL' '';
  325.         return $name.' TIMESTAMP'.$default.$notnull;
  326.     }
  327.  
  328.     // }}}
  329.     // {{{ _getTimeDeclaration()
  330.  
  331.     /**
  332.      * Obtain DBMS specific SQL code portion needed to declare an time type
  333.      * field to be used in statements like CREATE TABLE.
  334.      *
  335.      * @param string  $name   name the field to be declared.
  336.      * @param string  $field  associative array with the name of the properties
  337.      *                         of the field being declared as array indexes.
  338.      *                         Currently, the types of supported field
  339.      *                         properties are as follows:
  340.      *
  341.      *                        default
  342.      *                         Time value to be used as default for this field.
  343.      *
  344.      *                        notnull
  345.      *                         Boolean flag that indicates whether this field is
  346.      *                         constrained to not be set to null.
  347.      * @return string  DBMS specific SQL code portion that should be used to
  348.      *                  declare the specified field.
  349.      * @access protected
  350.      */
  351.     function _getTimeDeclaration($name$field)
  352.     {
  353.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  354.         $default = isset($field['default']' DEFAULT TIME '.
  355.             $this->quote($field['default']'time''';
  356.         $notnull = isset($field['notnull']' NOT NULL' '';
  357.         return $name.' TIME'.$default.$notnull;
  358.     }
  359.  
  360.     // }}}
  361.     // {{{ _getFloatDeclaration()
  362.  
  363.     /**
  364.      * Obtain DBMS specific SQL code portion needed to declare an float type
  365.      * field to be used in statements like CREATE TABLE.
  366.      *
  367.      * @param string  $name   name the field to be declared.
  368.      * @param string  $field  associative array with the name of the properties
  369.      *                         of the field being declared as array indexes.
  370.      *                         Currently, the types of supported field
  371.      *                         properties are as follows:
  372.      *
  373.      *                        default
  374.      *                         Integer value to be used as default for this
  375.      *                         field.
  376.      *
  377.      *                        notnull
  378.      *                         Boolean flag that indicates whether this field is
  379.      *                         constrained to not be set to null.
  380.      * @return string  DBMS specific SQL code portion that should be used to
  381.      *                  declare the specified field.
  382.      * @access protected
  383.      */
  384.     function _getFloatDeclaration($name$field)
  385.     {
  386.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  387.         $default = isset($field['default']' DEFAULT '.
  388.             $this->quote($field['default']'float''';
  389.         $notnull = isset($field['notnull']' NOT NULL' '';
  390.         return $name.' FLOAT'.$default.$notnull;
  391.     }
  392.  
  393.     // }}}
  394.     // {{{ _getDecimalDeclaration()
  395.  
  396.     /**
  397.      * Obtain DBMS specific SQL code portion needed to declare an decimal type
  398.      * field to be used in statements like CREATE TABLE.
  399.      *
  400.      * @param string  $name   name the field to be declared.
  401.      * @param string  $field  associative array with the name of the properties
  402.      *                         of the field being declared as array indexes.
  403.      *                         Currently, the types of supported field
  404.      *                         properties are as follows:
  405.      *
  406.      *                        default
  407.      *                         Integer value to be used as default for this
  408.      *                         field.
  409.      *
  410.      *                        notnull
  411.      *                         Boolean flag that indicates whether this field is
  412.      *                         constrained to not be set to null.
  413.      * @return string  DBMS specific SQL code portion that should be used to
  414.      *                  declare the specified field.
  415.      * @access protected
  416.      */
  417.     function _getDecimalDeclaration($name$field)
  418.     {
  419.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  420.         $type 'DECIMAL(18,'.$db->options['decimal_places'].')';
  421.         $default = isset($field['default']' DEFAULT '.
  422.             $this->quote($field['default']'decimal''';
  423.         $notnull = isset($field['notnull']' NOT NULL' '';
  424.         return $name.' '.$type.$default.$notnull;
  425.     }
  426.  
  427.     // }}}
  428.     // {{{ _quoteBLOB()
  429.  
  430.     /**
  431.      * Convert a text value into a DBMS specific format that is suitable to
  432.      * compose query statements.
  433.      *
  434.      * @param           $value 
  435.      * @return string  text string that represents the given argument value in
  436.      *                  a DBMS specific format.
  437.      * @access protected
  438.      */
  439.     function _quoteBLOB($value)
  440.     {
  441.         $value $this->_readFile($value);
  442.         return "'".addslashes($value)."'";
  443.     }
  444.  
  445.     // }}}
  446.     // {{{ _quoteBoolean()
  447.  
  448.     /**
  449.      * Convert a text value into a DBMS specific format that is suitable to
  450.      * compose query statements.
  451.      *
  452.      * @param string $value text string value that is intended to be converted.
  453.      * @return string text string that represents the given argument value in
  454.      *        a DBMS specific format.
  455.      * @access protected
  456.      */
  457.     function _quoteBoolean($value)
  458.     {
  459.         return ($value 'True' 'False');
  460.     }
  461.  
  462.     // }}}
  463.     // {{{ _quoteDate()
  464.  
  465.     /**
  466.      * Convert a text value into a DBMS specific format that is suitable to
  467.      * compose query statements.
  468.      *
  469.      * @param string $value text string value that is intended to be converted.
  470.      * @return string text string that represents the given argument value in
  471.      *         a DBMS specific format.
  472.      * @access protected
  473.      */
  474.     function _quoteDate($value)
  475.     {
  476.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  477.         return "DATE'$value'";
  478.     }
  479.  
  480.     // }}}
  481.     // {{{ _quoteTimestamp()
  482.  
  483.     /**
  484.      * Convert a text value into a DBMS specific format that is suitable to
  485.      * compose query statements.
  486.      *
  487.      * @param string $value text string value that is intended to be converted.
  488.      * @return string text string that represents the given argument value in
  489.      *         a DBMS specific format.
  490.      * @access protected
  491.      */
  492.     function _quoteTimestamp($value)
  493.     {
  494.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  495.         return "TIMESTAMP'$value'";
  496.     }
  497.  
  498.     // }}}
  499.     // {{{ _quoteTime()
  500.  
  501.     /**
  502.      * Convert a text value into a DBMS specific format that is suitable to
  503.      *        compose query statements.
  504.      *
  505.      * @param string $value text string value that is intended to be converted.
  506.      * @return string text string that represents the given argument value in
  507.      *         a DBMS specific format.
  508.      * @access protected
  509.      */
  510.     function _quoteTime($value)
  511.     {
  512.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  513.         return "TIME'$value'";
  514.     }
  515.  
  516.     // }}}
  517.     // {{{ _quoteFloat()
  518.  
  519.     /**
  520.      * Convert a text value into a DBMS specific format that is suitable to
  521.      * compose query statements.
  522.      *
  523.      * @param string  $value text string value that is intended to be converted.
  524.      * @return string  text string that represents the given argument value in
  525.      *                  a DBMS specific format.
  526.      * @access protected
  527.      */
  528.     function _quoteFloat($value)
  529.     {
  530.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  531.         return (float)$value;
  532.     }
  533.  
  534.     // }}}
  535.     // {{{ _quoteDecimal()
  536.  
  537.     /**
  538.      * Convert a text value into a DBMS specific format that is suitable to
  539.      * compose query statements.
  540.      *
  541.      * @param string  $value text string value that is intended to be converted.
  542.      * @return string  text string that represents the given argument value in
  543.      *                  a DBMS specific format.
  544.      * @access protected
  545.      */
  546.     function _quoteDecimal($value)
  547.     {
  548.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  549.         return $value;
  550.     }
  551. }
  552.  
  553. ?>

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