Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * OCI specific temptables store. Needed because temporary tables
  19   * in Oracle are global (to all sessions), so we need to rename them
  20   * on the fly in order to get local (different for each session) table names.
  21   * Also used to be able to retrieve temp table names included in the get_tables()
  22   * method of the DB.
  23   *
  24   * @package    core_dml
  25   * @copyright  2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  26   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   */
  28  
  29  defined('MOODLE_INTERNAL') || die();
  30  
  31  require_once (__DIR__.'/moodle_temptables.php');
  32  
  33  class oci_native_moodle_temptables extends moodle_temptables {
  34  
  35      /** @var int To store unique_session_id. Needed for temp tables unique naming (upto 24cc) */
  36      protected $unique_session_id; //
  37      /** @var int To get incrementally different temptable names on each add_temptable() request */
  38      protected $counter;
  39  
  40      /**
  41       * Creates new moodle_temptables instance
  42       * @param object moodle_database instance
  43       */
  44      public function __construct($mdb, $unique_session_id) {
  45          $this->unique_session_id = $unique_session_id;
  46          $this->counter = 1;
  47          parent::__construct($mdb);
  48      }
  49  
  50      /**
  51       * Add one temptable to the store.
  52       *
  53       * Overridden because OCI only support global temptables, so we need to change completely the name, based
  54       * in unique session identifier, to get local-like temp tables support
  55       * tables before the prefix.
  56       *
  57       * Given one moodle temptable name (without prefix), add it to the store, with the
  58       * key being the original moodle name and the value being the real db temptable name
  59       * already prefixed
  60       *
  61       * Override and use this *only* if the database requires modification in the table name.
  62       *
  63       * @param string $tablename name without prefix of the table created as temptable
  64       */
  65      public function add_temptable($tablename) {
  66          // TODO: throw exception if exists: if ($this->is_temptable...
  67          $this->temptables[$tablename] = $this->prefix . $this->unique_session_id . $this->counter;
  68          $this->counter++;
  69      }
  70  }