Source for file Oracle.php

Documentation is available at Oracle.php

  1. <?php
  2. /*
  3.  *  $Id: Oracle.php 1889 2007-06-28 12:11:55Z zYne $
  4.  *
  5.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16.  *
  17.  * This software consists of voluntary contributions made by many individuals
  18.  * and is licensed under the LGPL. For more information, see
  19.  * <http://www.phpdoctrine.com>.
  20.  */
  21. Doctrine::autoload('Doctrine_Import');
  22. /**
  23.  * @package     Doctrine
  24.  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
  25.  * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
  26.  * @version     $Revision: 1889 $
  27.  * @category    Object Relational Mapping
  28.  * @link        www.phpdoctrine.com
  29.  * @since       1.0
  30.  */
  31. {
  32.     /**
  33.      * lists all databases
  34.      *
  35.      * @return array 
  36.      */
  37.     public function listDatabases()
  38.     {
  39.         if $this->conn->getAttribute(Doctrine::ATTR_EMULATE_DATABASE)) {
  40.             throw new Doctrine_Import_Exception('database listing is only supported if the "emulate_database" option is enabled');
  41.         }
  42.         /**
  43.         if ($this->conn->options['database_name_prefix']) {
  44.             $query = 'SELECT SUBSTR(username, ';
  45.             $query.= (strlen($this->conn->getAttribute(['database_name_prefix'])+1);
  46.             $query.= ") FROM sys.dba_users WHERE username LIKE '";
  47.             $query.= $this->conn->options['database_name_prefix']."%'";
  48.         } else {
  49.         */
  50.         $query   'SELECT username FROM sys.dba_users';
  51.  
  52.         $result2 $this->conn->standaloneQuery($query);
  53.         $result  $result2->fetchColumn();
  54.  
  55.         return $result;
  56.     }
  57.     /**
  58.      * lists all availible database functions
  59.      *
  60.      * @return array 
  61.      */
  62.     public function listFunctions()
  63.     {
  64.         $query "SELECT name FROM sys.user_source WHERE line = 1 AND type = 'FUNCTION'";
  65.  
  66.         return $this->conn->fetchColumn($query);
  67.     }
  68.     /**
  69.      * lists all database triggers
  70.      *
  71.      * @param string|null$database 
  72.      * @return array 
  73.      */
  74.     public function listTriggers($database null)
  75.     {
  76.  
  77.     }
  78.     /**
  79.      * lists all database sequences
  80.      *
  81.      * @param string|null$database 
  82.      * @return array 
  83.      */
  84.     public function listSequences($database null)
  85.     {
  86.         $query "SELECT sequence_name FROM sys.user_sequences";
  87.  
  88.         $tableNames $this->conn->fetchColumn($query);
  89.  
  90.         return array_map(array($this->conn->formatter'fixSequenceName')$tableNames);
  91.     }
  92.     /**
  93.      * lists table constraints
  94.      *
  95.      * @param string $table     database table name
  96.      * @return array 
  97.      */
  98.     public function listTableConstraints($table)
  99.     {
  100.         $table $this->conn->quote($table'text');
  101.  
  102.         $query 'SELECT index_name name FROM user_constraints'
  103.                . ' WHERE table_name = ' $table ' OR table_name = ' strtoupper($table);
  104.  
  105.         $constraints $this->conn->fetchColumn($query);
  106.  
  107.         return array_map(array($this->conn->formatter'fixIndexName')$constraints);
  108.     }
  109.     /**
  110.      * lists table constraints
  111.      *
  112.      * @param string $table     database table name
  113.      * @return array 
  114.      */
  115.     public function listTableColumns($table)
  116.     {
  117.         $table  strtoupper($table);
  118.         $sql    "SELECT column_name, data_type, data_length, nullable, data_default, data_scale, data_precision FROM all_tab_columns"
  119.                 . " WHERE table_name = '" $table "' ORDER BY column_name";
  120.  
  121.         $result $this->conn->fetchAssoc($sql);
  122.  
  123.         foreach($result as $val{
  124.             $val array_change_key_case($valCASE_LOWER);
  125.             $decl $this->conn->dataDict->getPortableDeclaration($val);
  126.  
  127.  
  128.             $descr[$val['column_name']] array(
  129.                'name'       => $val['column_name'],
  130.                'notnull'    => (bool) ($val['nullable'=== 'N'),
  131.                'ntype'      => $val['data_type'],
  132.                'type'       => $decl['type'][0],
  133.                'alltypes'   => $decl['type'],
  134.                'fixed'      => $decl['fixed'],
  135.                'unsigned'   => $decl['unsigned'],
  136.                'default'    => $val['data_default'],
  137.                'length'     => $val['data_length'],
  138.                'precision'  => $val['data_precision'],
  139.                'scale'      => $val['scale'],
  140.             );
  141.         }
  142.         return $result;
  143.     }
  144.     /**
  145.      * lists table constraints
  146.      *
  147.      * @param string $table     database table name
  148.      * @return array 
  149.      */
  150.     public function listTableIndexes($table)
  151.     {
  152.         $table $this->conn->quote($table'text');
  153.         $query 'SELECT index_name name FROM user_indexes'
  154.                . ' WHERE table_name = ' $table ' OR table_name = ' strtoupper($table)
  155.                . ' AND generated = ' $this->conn->quote('N''text');
  156.  
  157.         $indexes $this->conn->fetchColumn($query);
  158.  
  159.         return array_map(array($this->conn->formatter'fixIndexName')$indexes);
  160.     }
  161.     /**
  162.      * lists tables
  163.      *
  164.      * @param string|null$database 
  165.      * @return array 
  166.      */
  167.     public function listTables($database null)
  168.     {
  169.         $query 'SELECT table_name FROM sys.user_tables';
  170.         return $this->conn->fetchColumn($query);
  171.     }
  172.     /**
  173.      * lists table triggers
  174.      *
  175.      * @param string $table     database table name
  176.      * @return array 
  177.      */
  178.     public function listTableTriggers($table)
  179.     {
  180.  
  181.     }
  182.     /**
  183.      * lists table views
  184.      *
  185.      * @param string $table     database table name
  186.      * @return array 
  187.      */
  188.     public function listTableViews($table)
  189.     {
  190.  
  191.     }
  192.     /**
  193.      * lists database users
  194.      *
  195.      * @return array 
  196.      */
  197.     public function listUsers()
  198.     {
  199.         /**
  200.         if ($this->conn->options['emulate_database'] && $this->conn->options['database_name_prefix']) {
  201.             $query = 'SELECT SUBSTR(username, ';
  202.             $query.= (strlen($this->conn->options['database_name_prefix'])+1);
  203.             $query.= ") FROM sys.dba_users WHERE username NOT LIKE '";
  204.             $query.= $this->conn->options['database_name_prefix']."%'";
  205.         } else {
  206.         */
  207.  
  208.         $query 'SELECT username FROM sys.dba_users';
  209.         //}
  210.  
  211.         return $this->conn->fetchColumn($query);
  212.     }
  213.     /**
  214.      * lists database views
  215.      *
  216.      * @param string|null$database 
  217.      * @return array 
  218.      */
  219.     public function listViews($database null)
  220.     {
  221.         $query 'SELECT view_name FROM sys.user_views';
  222.         return $this->conn->fetchColumn($query);
  223.     }
  224. }