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-2006 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.64 2006/08/21 16:39:37 lsmith Exp $
  46.  
  47. require_once 'MDB2/Driver/Manager/Common.php';
  48.  
  49. /**
  50.  * MDB2 MySQL driver for the management modules
  51.  *
  52.  * @package MDB2
  53.  * @category Database
  54.  * @author  Paul Cooper <pgc@ucecom.com>
  55.  */
  56. class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
  57. {
  58.     // {{{ createDatabase()
  59.  
  60.     /**
  61.      * create a new database
  62.      *
  63.      * @param string $name name of the database that should be created
  64.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  65.      * @access public
  66.      ***/
  67.     function createDatabase($name)
  68.     {
  69.         $db =$this->getDBInstance();
  70.         if (PEAR::isError($db)) {
  71.             return $db;
  72.         }
  73.  
  74.         $name $db->quoteIdentifier($nametrue);
  75.         return $db->standaloneQuery("CREATE DATABASE $name"nulltrue);
  76.     }
  77.  
  78.     // }}}
  79.     // {{{ dropDatabase()
  80.  
  81.     /**
  82.      * drop an existing database
  83.      *
  84.      * @param string $name name of the database that should be dropped
  85.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  86.      * @access public
  87.      ***/
  88.     function dropDatabase($name)
  89.     {
  90.         $db =$this->getDBInstance();
  91.         if (PEAR::isError($db)) {
  92.             return $db;
  93.         }
  94.  
  95.         $name $db->quoteIdentifier($nametrue);
  96.         return $db->standaloneQuery("DROP DATABASE $name"nulltrue);
  97.     }
  98.  
  99.     // }}}
  100.     // {{{ alterTable()
  101.  
  102.     /**
  103.      * alter an existing table
  104.      *
  105.      * @param string $name         name of the table that is intended to be changed.
  106.      * @param array $changes     associative array that contains the details of each type
  107.      *                              of change that is intended to be performed. The types of
  108.      *                              changes that are currently supported are defined as follows:
  109.      *
  110.      *                              name
  111.      *
  112.      *                                 New name for the table.
  113.      *
  114.      *                             add
  115.      *
  116.      *                                 Associative array with the names of fields to be added as
  117.      *                                  indexes of the array. The value of each entry of the array
  118.      *                                  should be set to another associative array with the properties
  119.      *                                  of the fields to be added. The properties of the fields should
  120.      *                                  be the same as defined by the Metabase parser.
  121.      *
  122.      *
  123.      *                             remove
  124.      *
  125.      *                                 Associative array with the names of fields to be removed as indexes
  126.      *                                  of the array. Currently the values assigned to each entry are ignored.
  127.      *                                  An empty array should be used for future compatibility.
  128.      *
  129.      *                             rename
  130.      *
  131.      *                                 Associative array with the names of fields to be renamed as indexes
  132.      *                                  of the array. The value of each entry of the array should be set to
  133.      *                                  another associative array with the entry named name with the new
  134.      *                                  field name and the entry named Declaration that is expected to contain
  135.      *                                  the portion of the field declaration already in DBMS specific SQL code
  136.      *                                  as it is used in the CREATE TABLE statement.
  137.      *
  138.      *                             change
  139.      *
  140.      *                                 Associative array with the names of the fields to be changed as indexes
  141.      *                                  of the array. Keep in mind that if it is intended to change either the
  142.      *                                  name of a field and any other properties, the change array entries
  143.      *                                  should have the new names of the fields as array indexes.
  144.      *
  145.      *                                 The value of each entry of the array should be set to another associative
  146.      *                                  array with the properties of the fields to that are meant to be changed as
  147.      *                                  array entries. These entries should be assigned to the new values of the
  148.      *                                  respective properties. The properties of the fields should be the same
  149.      *                                  as defined by the Metabase parser.
  150.      *
  151.      *                             Example
  152.      *                                 array(
  153.      *                                     'name' => 'userlist',
  154.      *                                     'add' => array(
  155.      *                                         'quota' => array(
  156.      *                                             'type' => 'integer',
  157.      *                                             'unsigned' => 1
  158.      *                                         )
  159.      *                                     ),
  160.      *                                     'remove' => array(
  161.      *                                         'file_limit' => array(),
  162.      *                                         'time_limit' => array()
  163.      *                                     ),
  164.      *                                     'change' => array(
  165.      *                                         'name' => array(
  166.      *                                             'length' => '20',
  167.      *                                             'definition' => array(
  168.      *                                                 'type' => 'text',
  169.      *                                                 'length' => 20,
  170.      *                                             ),
  171.      *                                         )
  172.      *                                     ),
  173.      *                                     'rename' => array(
  174.      *                                         'sex' => array(
  175.      *                                             'name' => 'gender',
  176.      *                                             'definition' => array(
  177.      *                                                 'type' => 'text',
  178.      *                                                 'length' => 1,
  179.      *                                                 'default' => 'M',
  180.      *                                             ),
  181.      *                                         )
  182.      *                                     )
  183.      *                                 )
  184.      *
  185.      * @param boolean $check     indicates whether the function should just check if the DBMS driver
  186.      *                              can perform the requested table alterations if the value is true or
  187.      *                              actually perform them otherwise.
  188.      * @access public
  189.      *
  190.       * @return mixed MDB2_OK on success, a MDB2 error on failure
  191.      */
  192.     function alterTable($name$changes$check)
  193.     {
  194.         $db =$this->getDBInstance();
  195.         if (PEAR::isError($db)) {
  196.             return $db;
  197.         }
  198.  
  199.         foreach ($changes as $change_name => $change{
  200.             switch ($change_name{
  201.             case 'add':
  202.             case 'remove':
  203.             case 'change':
  204.             case 'name':
  205.             case 'rename':
  206.                 break;
  207.             default:
  208.                 return $db->raiseError(MDB2_ERROR_CANNOT_ALTERnullnull,
  209.                     'change type "'.$change_name.'\" not yet supported'__FUNCTION__);
  210.             }
  211.         }
  212.  
  213.         if ($check{
  214.             return MDB2_OK;
  215.         }
  216.  
  217.         if (!empty($changes['add']&& is_array($changes['add'])) {
  218.             foreach ($changes['add'as $field_name => $field{
  219.                 $query 'ADD ' $db->getDeclaration($field['type']$field_name$field);
  220.                 $result $db->exec("ALTER TABLE $name $query");
  221.                 if (PEAR::isError($result)) {
  222.                     return $result;
  223.                 }
  224.             }
  225.         }
  226.  
  227.         if (!empty($changes['remove']&& is_array($changes['remove'])) {
  228.             foreach ($changes['remove'as $field_name => $field{
  229.                 $field_name $db->quoteIdentifier($field_nametrue);
  230.                 $query 'DROP ' $field_name;
  231.                 $result $db->exec("ALTER TABLE $name $query");
  232.                 if (PEAR::isError($result)) {
  233.                     return $result;
  234.                 }
  235.             }
  236.         }
  237.  
  238.         if (!empty($changes['change']&& is_array($changes['change'])) {
  239.             foreach ($changes['change'as $field_name => $field{
  240.                 $field_name $db->quoteIdentifier($field_nametrue);
  241.                 if (!empty($field['type'])) {
  242.                     $server_info $db->getServerVersion();
  243.                     if (PEAR::isError($server_info)) {
  244.                         return $server_info;
  245.                     }
  246.                     if (is_array($server_info&& $server_info['major'< 8{
  247.                         return $db->raiseError(MDB2_ERROR_CANNOT_ALTERnullnull,
  248.                             'changing column type for "'.$change_name.'\" requires PostgreSQL 8.0 or above'__FUNCTION__);
  249.                     }
  250.                     $db->loadModule('Datatype'nulltrue);
  251.                     $query = "ALTER $field_name TYPE ".$db->datatype->getTypeDeclaration($field['definition']);
  252.                     $result $db->exec("ALTER TABLE $name $query");
  253.                     if (PEAR::isError($result)) {
  254.                         return $result;
  255.                     }
  256.                 }
  257.                 if (array_key_exists('default'$field)) {
  258.                     $query = "ALTER $field_name SET DEFAULT ".$db->quote($field['definition']['default']$field['definition']['type']);
  259.                     $result $db->exec("ALTER TABLE $name $query");
  260.                     if (PEAR::isError($result)) {
  261.                         return $result;
  262.                     }
  263.                 }
  264.                 if (!empty($field['notnull'])) {
  265.                     $query = "ALTER $field_name ".($field['definition']['notnull'"SET" "DROP").' NOT NULL';
  266.                     $result $db->exec("ALTER TABLE $name $query");
  267.                     if (PEAR::isError($result)) {
  268.                         return $result;
  269.                     }
  270.                 }
  271.             }
  272.         }
  273.  
  274.         if (!empty($changes['rename']&& is_array($changes['rename'])) {
  275.             foreach ($changes['rename'as $field_name => $field{
  276.                 $field_name $db->quoteIdentifier($field_nametrue);
  277.                 $result $db->exec("ALTER TABLE $name RENAME COLUMN $field_name TO ".$db->quoteIdentifier($field['name']true));
  278.                 if (PEAR::isError($result)) {
  279.                     return $result;
  280.                 }
  281.             }
  282.         }
  283.  
  284.         $name $db->quoteIdentifier($nametrue);
  285.         if (!empty($changes['name'])) {
  286.             $change_name $db->quoteIdentifier($changes['name']true);
  287.             $result $db->exec("ALTER TABLE $name RENAME TO ".$change_name);
  288.             if (PEAR::isError($result)) {
  289.                 return $result;
  290.             }
  291.         }
  292.  
  293.         return MDB2_OK;
  294.     }
  295.  
  296.     // }}}
  297.     // {{{ listDatabases()
  298.  
  299.     /**
  300.      * list all databases
  301.      *
  302.      * @return mixed data array on success, a MDB2 error on failure
  303.      * @access public
  304.      ***/
  305.     function listDatabases()
  306.     {
  307.         $db =$this->getDBInstance();
  308.         if (PEAR::isError($db)) {
  309.             return $db;
  310.         }
  311.  
  312.         $query 'SELECT datname FROM pg_database';
  313.         $result2 $db->standaloneQuery($queryarray('text')false);
  314.         if (!MDB2::isResultCommon($result2)) {
  315.             return $result2;
  316.         }
  317.  
  318.         $result $result2->fetchCol();
  319.         $result2->free();
  320.         if (PEAR::isError($result)) {
  321.             return $result;
  322.         }
  323.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  324.             $result array_map(($db->options['field_case'== CASE_LOWER ? 'strtolower' 'strtoupper')$result);
  325.         }
  326.         return $result;
  327.     }
  328.  
  329.     // }}}
  330.     // {{{ listUsers()
  331.  
  332.     /**
  333.      * list all users
  334.      *
  335.      * @return mixed data array on success, a MDB2 error on failure
  336.      * @access public
  337.      ***/
  338.     function listUsers()
  339.     {
  340.         $db =$this->getDBInstance();
  341.         if (PEAR::isError($db)) {
  342.             return $db;
  343.         }
  344.  
  345.         $query 'SELECT usename FROM pg_user';
  346.         $result2 $db->standaloneQuery($queryarray('text')false);
  347.         if (!MDB2::isResultCommon($result2)) {
  348.             return $result2;
  349.         }
  350.  
  351.         $result $result2->fetchCol();
  352.         $result2->free();
  353.         return $result;
  354.     }
  355.  
  356.     // }}}
  357.     // {{{ listViews()
  358.  
  359.     /**
  360.      * list the views in the database
  361.      *
  362.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  363.      * @access public
  364.      ***/
  365.     function listViews()
  366.     {
  367.         $db =$this->getDBInstance();
  368.         if (PEAR::isError($db)) {
  369.             return $db;
  370.         }
  371.  
  372.         $query 'SELECT viewname FROM pg_views';
  373.         $result $db->queryCol($query);
  374.         if (PEAR::isError($result)) {
  375.             return $result;
  376.         }
  377.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  378.             $result array_map(($db->options['field_case'== CASE_LOWER ? 'strtolower' 'strtoupper')$result);
  379.         }
  380.         return $result;
  381.     }
  382.  
  383.     // }}}
  384.     // {{{ listTableViews()
  385.  
  386.     /**
  387.      * list the views in the database that reference a given table
  388.      *
  389.      * @param string table for which all references views should be found
  390.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  391.      * @access public
  392.      ***/
  393.     function listTableViews($table)
  394.     {
  395.         $db =$this->getDBInstance();
  396.         if (PEAR::isError($db)) {
  397.             return $db;
  398.         }
  399.  
  400.         $query 'SELECT viewname FROM pg_views NATURAL JOIN pg_tables';
  401.         $query.= ' WHERE tablename ='.$db->quote($table'text');
  402.         $result $db->queryCol($query);
  403.         if (PEAR::isError($result)) {
  404.             return $result;
  405.         }
  406.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  407.             $result array_map(($db->options['field_case'== CASE_LOWER ? 'strtolower' 'strtoupper')$result);
  408.         }
  409.         return $result;
  410.     }
  411.  
  412.     // }}}
  413.     // {{{ listFunctions()
  414.  
  415.     /**
  416.      * list all functions in the current database
  417.      *
  418.      * @return mixed data array on success, a MDB2 error on failure
  419.      * @access public
  420.      */
  421.     function listFunctions()
  422.     {
  423.         $db =$this->getDBInstance();
  424.         if (PEAR::isError($db)) {
  425.             return $db;
  426.         }
  427.  
  428.         $query "
  429.             SELECT
  430.                 proname
  431.             FROM
  432.                 pg_proc pr,
  433.                 pg_type tp
  434.             WHERE
  435.                 tp.oid = pr.prorettype
  436.                 AND pr.proisagg = FALSE
  437.                 AND tp.typname <> 'trigger'
  438.                 AND pr.pronamespace IN
  439.                     (SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
  440.         $result $db->queryCol($query);
  441.         if (PEAR::isError($result)) {
  442.             return $result;
  443.         }
  444.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  445.             $result array_map(($db->options['field_case'== CASE_LOWER ? 'strtolower' 'strtoupper')$result);
  446.         }
  447.         return $result;
  448.     }
  449.  
  450.     // }}}
  451.     // {{{ listTables()
  452.  
  453.     /**
  454.      * list all tables in the current database
  455.      *
  456.      * @return mixed data array on success, a MDB2 error on failure
  457.      * @access public
  458.      ***/
  459.     function listTables()
  460.     {
  461.         $db =$this->getDBInstance();
  462.         if (PEAR::isError($db)) {
  463.             return $db;
  464.         }
  465.  
  466.         // gratuitously stolen from PEAR DB _getSpecialQuery in pgsql.php
  467.         $query 'SELECT c.relname AS "Name"'
  468.             . ' FROM pg_class c, pg_user u'
  469.             . ' WHERE c.relowner = u.usesysid'
  470.             . " AND c.relkind = 'r'"
  471.             . ' AND NOT EXISTS'
  472.             . ' (SELECT 1 FROM pg_views'
  473.             . '  WHERE viewname = c.relname)'
  474.             . " AND c.relname !~ '^(pg_|sql_)'"
  475.             . ' UNION'
  476.             . ' SELECT c.relname AS "Name"'
  477.             . ' FROM pg_class c'
  478.             . " WHERE c.relkind = 'r'"
  479.             . ' AND NOT EXISTS'
  480.             . ' (SELECT 1 FROM pg_views'
  481.             . '  WHERE viewname = c.relname)'
  482.             . ' AND NOT EXISTS'
  483.             . ' (SELECT 1 FROM pg_user'
  484.             . '  WHERE usesysid = c.relowner)'
  485.             . " AND c.relname !~ '^pg_'";
  486.         $result $db->queryCol($query);
  487.         if (PEAR::isError($result)) {
  488.             return $result;
  489.         }
  490.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  491.             $result array_map(($db->options['field_case'== CASE_LOWER ? 'strtolower' 'strtoupper')$result);
  492.         }
  493.         return $result;
  494.     }
  495.  
  496.     // }}}
  497.     // {{{ listTableFields()
  498.  
  499.     /**
  500.      * list all fields in a tables in the current database
  501.      *
  502.      * @param string $table name of table that should be used in method
  503.      * @return mixed data array on success, a MDB2 error on failure
  504.      * @access public
  505.      */
  506.     function listTableFields($table)
  507.     {
  508.         $db =$this->getDBInstance();
  509.         if (PEAR::isError($db)) {
  510.             return $db;
  511.         }
  512.  
  513.         $table $db->quoteIdentifier($tabletrue);
  514.         $db->setLimit(1);
  515.         $result2 $db->query("SELECT * FROM $table");
  516.         if (PEAR::isError($result2)) {
  517.             return $result2;
  518.         }
  519.         $result $result2->getColumnNames();
  520.         $result2->free();
  521.         if (PEAR::isError($result)) {
  522.             return $result;
  523.         }
  524.         return array_flip($result);
  525.     }
  526.  
  527.     // }}}
  528.     // {{{ listTableIndexes()
  529.  
  530.     /**
  531.      * list all indexes in a table
  532.      *
  533.      * @param string    $table      name of table that should be used in method
  534.      * @return mixed data array on success, a MDB2 error on failure
  535.      * @access public
  536.      */
  537.     function listTableIndexes($table)
  538.     {
  539.         $db =$this->getDBInstance();
  540.         if (PEAR::isError($db)) {
  541.             return $db;
  542.         }
  543.  
  544.         $table $db->quote($table'text');
  545.         $subquery "SELECT indexrelid FROM pg_index, pg_class";
  546.         $subquery.= " WHERE pg_class.relname=$table AND pg_class.oid=pg_index.indrelid AND indisunique != 't' AND indisprimary != 't'";
  547.         $query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
  548.         $indexes $db->queryCol($query'text');
  549.         if (PEAR::isError($indexes)) {
  550.             return $indexes;
  551.         }
  552.  
  553.         $result = array();
  554.         foreach ($indexes as $index{
  555.             $index $this->_fixIndexName($index);
  556.             if (!empty($index)) {
  557.                 $result[$index= true;
  558.             }
  559.         }
  560.  
  561.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  562.             $result array_change_key_case($result$db->options['field_case']);
  563.         }
  564.         return array_keys($result);
  565.     }
  566.  
  567.     // }}}
  568.     // {{{ listTableConstraints()
  569.  
  570.     /**
  571.      * list all constraints in a table
  572.      *
  573.      * @param string    $table      name of table that should be used in method
  574.      * @return mixed data array on success, a MDB2 error on failure
  575.      * @access public
  576.      */
  577.     function listTableConstraints($table)
  578.     {
  579.         $db =$this->getDBInstance();
  580.         if (PEAR::isError($db)) {
  581.             return $db;
  582.         }
  583.  
  584.         $table $db->quote($table'text');
  585.         $subquery "SELECT indexrelid FROM pg_index, pg_class";
  586.         $subquery.= " WHERE pg_class.relname=$table AND pg_class.oid=pg_index.indrelid AND (indisunique = 't' OR indisprimary = 't')";
  587.         $query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
  588.         $constraints $db->queryCol($query);
  589.         if (PEAR::isError($constraints)) {
  590.             return $constraints;
  591.         }
  592.  
  593.         $result = array();
  594.         foreach ($constraints as $constraint{
  595.             $constraint $this->_fixIndexName($constraint);
  596.             if (!empty($constraint)) {
  597.                 $result[$constraint= true;
  598.             }
  599.         }
  600.  
  601.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE
  602.             && $db->options['field_case'== CASE_LOWER
  603.         {
  604.             $result array_change_key_case($result$db->options['field_case']);
  605.         }
  606.         return array_keys($result);
  607.     }
  608.  
  609.     // }}}
  610.     // {{{ createSequence()
  611.  
  612.     /**
  613.      * create sequence
  614.      *
  615.      * @param string $seq_name name of the sequence to be created
  616.      * @param string $start start value of the sequence; default is 1
  617.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  618.      * @access public
  619.      ***/
  620.     function createSequence($seq_name$start = 1)
  621.     {
  622.         $db =$this->getDBInstance();
  623.         if (PEAR::isError($db)) {
  624.             return $db;
  625.         }
  626.  
  627.         $sequence_name $db->quoteIdentifier($db->getSequenceName($seq_name)true);
  628.         return $db->exec("CREATE SEQUENCE $sequence_name INCREMENT 1".
  629.             ($start < 1 ? " MINVALUE $start" : '')." START $start");
  630.     }
  631.  
  632.     // }}}
  633.     // {{{ dropSequence()
  634.  
  635.     /**
  636.      * drop existing sequence
  637.      *
  638.      * @param string $seq_name name of the sequence to be dropped
  639.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  640.      * @access public
  641.      ***/
  642.     function dropSequence($seq_name)
  643.     {
  644.         $db =$this->getDBInstance();
  645.         if (PEAR::isError($db)) {
  646.             return $db;
  647.         }
  648.  
  649.         $sequence_name $db->quoteIdentifier($db->getSequenceName($seq_name)true);
  650.         return $db->exec("DROP SEQUENCE $sequence_name");
  651.     }
  652.  
  653.     // }}}
  654.     // {{{ listSequences()
  655.  
  656.     /**
  657.      * list all sequences in the current database
  658.      *
  659.      * @return mixed data array on success, a MDB2 error on failure
  660.      * @access public
  661.      ***/
  662.     function listSequences()
  663.     {
  664.         $db =$this->getDBInstance();
  665.         if (PEAR::isError($db)) {
  666.             return $db;
  667.         }
  668.  
  669.         $query "SELECT relname FROM pg_class WHERE relkind = 'S' AND relnamespace IN";
  670.         $query.= "(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
  671.         $table_names $db->queryCol($query);
  672.         if (PEAR::isError($table_names)) {
  673.             return $table_names;
  674.         }
  675.         $result = array();
  676.         foreach ($table_names as $table_name{
  677.             $result[$this->_fixSequenceName($table_name);
  678.         }
  679.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  680.             $result array_map(($db->options['field_case'== CASE_LOWER ? 'strtolower' 'strtoupper')$result);
  681.         }
  682.         return $result;
  683.     }
  684. }
  685. ?>

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