Source for file oracle.php

Documentation is available at oracle.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Database
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Oracle Query Building Class.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Database
  17.  * @since       12.1
  18.  */
  19. {
  20.     /**
  21.      * @var    integer  The offset for the result set.
  22.      * @since  12.1
  23.      */
  24.     protected $offset;
  25.  
  26.     /**
  27.      * @var    integer  The limit for the result set.
  28.      * @since  12.1
  29.      */
  30.     protected $limit;
  31.  
  32.     /**
  33.      * @var    array  Bounded object array
  34.      * @since  12.1
  35.      */
  36.     protected $bounded = array();
  37.  
  38.     /**
  39.      * Method to add a variable to an internal array that will be bound to a prepared SQL statement before query execution. Also
  40.      * removes a variable that has been bounded from the internal bounded array when the passed in value is null.
  41.      *
  42.      * @param   string|integer $key            The key that will be used in your SQL query to reference the value. Usually of
  43.      *                                           the form ':key', but can also be an integer.
  44.      * @param   mixed           &$value         The value that will be bound. The value is passed by reference to support output
  45.      *                                           parameters such as those possible with stored procedures.
  46.      * @param   integer         $dataType       Constant corresponding to a SQL datatype.
  47.      * @param   integer         $length         The length of the variable. Usually required for OUTPUT parameters.
  48.      * @param   array           $driverOptions  Optional driver options to be used.
  49.      *
  50.      * @return  JDatabaseQueryOracle 
  51.      *
  52.      * @since   12.1
  53.      */
  54.     public function bind($key null&$value null$dataType PDO::PARAM_STR$length 0$driverOptions array())
  55.     {
  56.         // Case 1: Empty Key (reset $bounded array)
  57.         if (empty($key))
  58.         {
  59.             $this->bounded = array();
  60.  
  61.             return $this;
  62.         }
  63.  
  64.         // Case 2: Key Provided, null value (unset key from $bounded array)
  65.         if (is_null($value))
  66.         {
  67.             if (isset($this->bounded[$key]))
  68.             {
  69.                 unset($this->bounded[$key]);
  70.             }
  71.  
  72.             return $this;
  73.         }
  74.  
  75.         $obj new stdClass;
  76.  
  77.         $obj->value &$value;
  78.         $obj->dataType $dataType;
  79.         $obj->length $length;
  80.         $obj->driverOptions $driverOptions;
  81.  
  82.         // Case 3: Simply add the Key/Value into the bounded array
  83.         $this->bounded[$key$obj;
  84.  
  85.         return $this;
  86.     }
  87.  
  88.     /**
  89.      * Retrieves the bound parameters array when key is null and returns it by reference. If a key is provided then that item is
  90.      * returned.
  91.      *
  92.      * @param   mixed  $key  The bounded variable key to retrieve.
  93.      *
  94.      * @return  mixed 
  95.      *
  96.      * @since   12.1
  97.      */
  98.     public function &getBounded($key null)
  99.     {
  100.         if (empty($key))
  101.         {
  102.             return $this->bounded;
  103.         }
  104.         else
  105.         {
  106.             if (isset($this->bounded[$key]))
  107.             {
  108.                 return $this->bounded[$key];
  109.             }
  110.         }
  111.     }
  112.  
  113.     /**
  114.      * Clear data from the query or a specific clause of the query.
  115.      *
  116.      * @param   string  $clause  Optionally, the name of the clause to clear, or nothing to clear the whole query.
  117.      *
  118.      * @return  JDatabaseQueryOracle  Returns this object to allow chaining.
  119.      *
  120.      * @since   12.1
  121.      */
  122.     public function clear($clause null)
  123.     {
  124.         switch ($clause)
  125.         {
  126.             case null:
  127.                 $this->bounded = array();
  128.                 break;
  129.         }
  130.  
  131.         parent::clear($clause);
  132.  
  133.         return $this;
  134.     }
  135.  
  136.     /**
  137.      * Method to modify a query already in string format with the needed
  138.      * additions to make the query limited to a particular number of
  139.      * results, or start at a particular offset. This method is used
  140.      * automatically by the __toString() method if it detects that the
  141.      * query implements the JDatabaseQueryLimitable interface.
  142.      *
  143.      * @param   string   $query   The query in string format
  144.      * @param   integer  $limit   The limit for the result set
  145.      * @param   integer  $offset  The offset for the result set
  146.      *
  147.      * @return  string 
  148.      *
  149.      * @since   12.1
  150.      */
  151.     public function processLimit($query$limit$offset 0)
  152.     {
  153.         // Check if we need to mangle the query.
  154.         if ($limit || $offset)
  155.         {
  156.             $query "SELECT joomla2.*
  157.                       FROM (
  158.                           SELECT joomla1.*, ROWNUM AS joomla_db_rownum
  159.                           FROM (
  160.                               " $query "
  161.                           ) joomla1
  162.                       ) joomla2";
  163.  
  164.             // Check if the limit value is greater than zero.
  165.             if ($limit 0)
  166.             {
  167.                 $query .= ' WHERE joomla2.joomla_db_rownum BETWEEN ' ($offset 1' AND ' ($offset $limit);
  168.             }
  169.             else
  170.             {
  171.                 // Check if there is an offset and then use this.
  172.                 if ($offset)
  173.                 {
  174.                     $query .= ' WHERE joomla2.joomla_db_rownum > ' ($offset 1);
  175.                 }
  176.             }
  177.         }
  178.  
  179.         return $query;
  180.     }
  181.  
  182.     /**
  183.      * Sets the offset and limit for the result set, if the database driver supports it.
  184.      *
  185.      * Usage:
  186.      * $query->setLimit(100, 0); (retrieve 100 rows, starting at first record)
  187.      * $query->setLimit(50, 50); (retrieve 50 rows, starting at 50th record)
  188.      *
  189.      * @param   integer  $limit   The limit for the result set
  190.      * @param   integer  $offset  The offset for the result set
  191.      *
  192.      * @return  JDatabaseQueryOracle  Returns this object to allow chaining.
  193.      *
  194.      * @since   12.1
  195.      */
  196.     public function setLimit($limit 0$offset 0)
  197.     {
  198.         $this->limit = (int) $limit;
  199.         $this->offset = (int) $offset;
  200.  
  201.         return $this;
  202.     }
  203. }

Documentation generated on Tue, 19 Nov 2013 15:09:49 +0100 by phpDocumentor 1.4.3