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

Source for file sqlite.php

Documentation is available at sqlite.php

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP versions 4 and 5                                                 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1998-2004 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: Lukas Smith <smith@pooteeweet.org>                           |
  43. // +----------------------------------------------------------------------+
  44. //
  45. // $Id: sqlite.php,v 1.40 2005/12/15 22:52:56 lsmith Exp $
  46. //
  47.  
  48. require_once 'MDB2/Driver/Manager/Common.php';
  49.  
  50. /**
  51.  * MDB2 SQLite driver for the management modules
  52.  *
  53.  * @package MDB2
  54.  * @category Database
  55.  * @author  Lukas Smith <smith@pooteeweet.org>
  56.  */
  57. class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
  58. {
  59.     // {{{ createDatabase()
  60.  
  61.     /**
  62.      * create a new database
  63.      *
  64.      * @param string $name name of the database that should be created
  65.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  66.      * @access public
  67.      */
  68.     function createDatabase($name)
  69.     {
  70.         $db =$this->getDBInstance();
  71.         if (PEAR::isError($db)) {
  72.             return $db;
  73.         }
  74.  
  75.         $database_file $db->_getDatabaseFile($name);
  76.         if (file_exists($database_file)) {
  77.             return $db->raiseError(MDB2_ERROR_CANNOT_CREATEnullnull,
  78.                 'createDatabase: database already exists');
  79.         }
  80.         $php_errormsg '';
  81.         $handle @sqlite_open($database_file$db->dsn['mode']$php_errormsg);
  82.         if (!$handle{
  83.             return $db->raiseError(MDB2_ERROR_CANNOT_CREATEnullnull,
  84.                 'createDatabase: '.(isset($php_errormsg$php_errormsg 'could not create the database file'));
  85.         }
  86.         @sqlite_close($handle);
  87.         return MDB2_OK;
  88.     }
  89.  
  90.     // }}}
  91.     // {{{ dropDatabase()
  92.  
  93.     /**
  94.      * drop an existing database
  95.      *
  96.      * @param string $name name of the database that should be dropped
  97.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  98.      * @access public
  99.      */
  100.     function dropDatabase($name)
  101.     {
  102.         $db =$this->getDBInstance();
  103.         if (PEAR::isError($db)) {
  104.             return $db;
  105.         }
  106.  
  107.         $database_file $db->_getDatabaseFile($name);
  108.         if (!@file_exists($database_file)) {
  109.             return $db->raiseError(MDB2_ERROR_CANNOT_DROPnullnull,
  110.                 'dropDatabase: database does not exist');
  111.         }
  112.         $result @unlink($database_file);
  113.         if (!$result{
  114.             return $db->raiseError(MDB2_ERROR_CANNOT_DROPnullnull,
  115.                 'dropDatabase: '.(isset($php_errormsg$php_errormsg 'could not remove the database file'));
  116.         }
  117.         return MDB2_OK;
  118.     }
  119.  
  120.     // }}}
  121.     // {{{ alterTable()
  122.  
  123.     /**
  124.      * alter an existing table
  125.      *
  126.      * @param string $name         name of the table that is intended to be changed.
  127.      * @param array $changes     associative array that contains the details of each type
  128.      *                              of change that is intended to be performed. The types of
  129.      *                              changes that are currently supported are defined as follows:
  130.      *
  131.      *                              name
  132.      *
  133.      *                                 New name for the table.
  134.      *
  135.      *                             add
  136.      *
  137.      *                                 Associative array with the names of fields to be added as
  138.      *                                  indexes of the array. The value of each entry of the array
  139.      *                                  should be set to another associative array with the properties
  140.      *                                  of the fields to be added. The properties of the fields should
  141.      *                                  be the same as defined by the Metabase parser.
  142.      *
  143.      *
  144.      *                             remove
  145.      *
  146.      *                                 Associative array with the names of fields to be removed as indexes
  147.      *                                  of the array. Currently the values assigned to each entry are ignored.
  148.      *                                  An empty array should be used for future compatibility.
  149.      *
  150.      *                             rename
  151.      *
  152.      *                                 Associative array with the names of fields to be renamed as indexes
  153.      *                                  of the array. The value of each entry of the array should be set to
  154.      *                                  another associative array with the entry named name with the new
  155.      *                                  field name and the entry named Declaration that is expected to contain
  156.      *                                  the portion of the field declaration already in DBMS specific SQL code
  157.      *                                  as it is used in the CREATE TABLE statement.
  158.      *
  159.      *                             change
  160.      *
  161.      *                                 Associative array with the names of the fields to be changed as indexes
  162.      *                                  of the array. Keep in mind that if it is intended to change either the
  163.      *                                  name of a field and any other properties, the change array entries
  164.      *                                  should have the new names of the fields as array indexes.
  165.      *
  166.      *                                 The value of each entry of the array should be set to another associative
  167.      *                                  array with the properties of the fields to that are meant to be changed as
  168.      *                                  array entries. These entries should be assigned to the new values of the
  169.      *                                  respective properties. The properties of the fields should be the same
  170.      *                                  as defined by the Metabase parser.
  171.      *
  172.      *                             Example
  173.      *                                 array(
  174.      *                                     'name' => 'userlist',
  175.      *                                     'add' => array(
  176.      *                                         'quota' => array(
  177.      *                                             'type' => 'integer',
  178.      *                                             'unsigned' => 1
  179.      *                                         )
  180.      *                                     ),
  181.      *                                     'remove' => array(
  182.      *                                         'file_limit' => array(),
  183.      *                                         'time_limit' => array()
  184.      *                                     ),
  185.      *                                     'change' => array(
  186.      *                                         'name' => array(
  187.      *                                             'length' => '20',
  188.      *                                             'definition' => array(
  189.      *                                                 'type' => 'text',
  190.      *                                                 'length' => 20,
  191.      *                                             ),
  192.      *                                         )
  193.      *                                     ),
  194.      *                                     'rename' => array(
  195.      *                                         'sex' => array(
  196.      *                                             'name' => 'gender',
  197.      *                                             'definition' => array(
  198.      *                                                 'type' => 'text',
  199.      *                                                 'length' => 1,
  200.      *                                                 'default' => 'M',
  201.      *                                             ),
  202.      *                                         )
  203.      *                                     )
  204.      *                                 )
  205.      *
  206.      * @param boolean $check     indicates whether the function should just check if the DBMS driver
  207.      *                              can perform the requested table alterations if the value is true or
  208.      *                              actually perform them otherwise.
  209.      * @access public
  210.      *
  211.       * @return mixed MDB2_OK on success, a MDB2 error on failure
  212.      */
  213.     function alterTable($name$changes$check)
  214.     {
  215.         $db =$this->getDBInstance();
  216.         if (PEAR::isError($db)) {
  217.             return $db;
  218.         }
  219.  
  220.         foreach ($changes as $change_name => $change{
  221.             switch ($change_name{
  222.             case 'add':
  223.             case 'name':
  224.                 break;
  225.             case 'remove':
  226.             case 'change':
  227.             case 'rename':
  228.             default:
  229.                 return $db->raiseError(MDB2_ERROR_CANNOT_ALTERnullnull,
  230.                     'alterTable: change type "'.$change_name.'" not yet supported');
  231.             }
  232.         }
  233.  
  234.         if ($check{
  235.             return MDB2_OK;
  236.         }
  237.  
  238.         $query (array_key_exists('name'$changes'RENAME TO '.$changes['name''');
  239.  
  240.         if (array_key_exists('add'$changes)) {
  241.             foreach ($changes['add'as $field_name => $field{
  242.                 if ($query{
  243.                     $query.= ', ';
  244.                 }
  245.                 $query.= 'ADD COLUMN ' $db->getDeclaration($field['type']$field_name$field);
  246.             }
  247.         }
  248.  
  249.         if (!$query{
  250.             return MDB2_OK;
  251.         }
  252.  
  253.         $name $db->quoteIdentifier($nametrue);
  254.         return $db->exec("ALTER TABLE $name $query");
  255.     }
  256.  
  257.  
  258.     // }}}
  259.     // {{{ listDatabases()
  260.  
  261.     /**
  262.      * list all databases
  263.      *
  264.      * @return mixed data array on success, a MDB2 error on failure
  265.      * @access public
  266.      */
  267.     function listDatabases()
  268.     {
  269.         $db =$this->getDBInstance();
  270.         if (PEAR::isError($db)) {
  271.             return $db;
  272.         }
  273.  
  274.         return $db->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  275.             'listDatabases: list databases is not supported');
  276.     }
  277.  
  278.     // }}}
  279.     // {{{ listUsers()
  280.  
  281.     /**
  282.      * list all users
  283.      *
  284.      * @return mixed data array on success, a MDB2 error on failure
  285.      * @access public
  286.      */
  287.     function listUsers()
  288.     {
  289.         $db =$this->getDBInstance();
  290.         if (PEAR::isError($db)) {
  291.             return $db;
  292.         }
  293.  
  294.         return $db->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  295.             'listDatabases: list databases is not supported');
  296.     }
  297.  
  298.     // }}}
  299.     // {{{ listTables()
  300.  
  301.     /**
  302.      * list all tables in the current database
  303.      *
  304.      * @return mixed data array on success, a MDB2 error on failure
  305.      * @access public
  306.      */
  307.     function listTables()
  308.     {
  309.         $db =$this->getDBInstance();
  310.         if (PEAR::isError($db)) {
  311.             return $db;
  312.         }
  313.  
  314.         $query "SELECT name FROM sqlite_master WHERE type='table' AND sql NOT NULL ORDER BY name";
  315.         $table_names $db->queryCol($query);
  316.         if (PEAR::isError($table_names)) {
  317.             return $table_names;
  318.         }
  319.         $result = array();
  320.         for ($i = 0$j count($table_names)$i $j; ++$i{
  321.             if (!$this->_isSequenceName($table_names[$i])) {
  322.                 $result[$table_names[$i];
  323.             }
  324.         }
  325.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  326.             $result array_map(($db->options['field_case'== CASE_LOWER ? 'strtolower' 'strtoupper')$result);
  327.         }
  328.         return $result;
  329.     }
  330.  
  331.     // }}}
  332.     // {{{ listTableFields()
  333.  
  334.     /**
  335.      * list all fields in a tables in the current database
  336.      *
  337.      * @param string $table name of table that should be used in method
  338.      * @return mixed data array on success, a MDB2 error on failure
  339.      * @access public
  340.      */
  341.     function listTableFields($table)
  342.     {
  343.         $db =$this->getDBInstance();
  344.         if (PEAR::isError($db)) {
  345.             return $db;
  346.         }
  347.  
  348.         $table $db->quoteIdentifier($tabletrue);
  349.         $query = "SELECT * FROM $table";
  350.         $db->setLimit(1);
  351.         $result2 $db->query($query);
  352.         if (PEAR::isError($result2)) {
  353.             return $result2;
  354.         }
  355.         $result $result2->getColumnNames();
  356.         $result2->free();
  357.         if (PEAR::isError($result)) {
  358.             return $result;
  359.         }
  360.         return array_flip($result);
  361.     }
  362.  
  363.     // }}}
  364.     // {{{ createIndex()
  365.  
  366.     /**
  367.      * get the stucture of a field into an array
  368.      *
  369.      * @param string    $table         name of the table on which the index is to be created
  370.      * @param string    $name         name of the index to be created
  371.      * @param array     $definition        associative array that defines properties of the index to be created.
  372.      *                                  Currently, only one property named FIELDS is supported. This property
  373.      *                                  is also an associative with the names of the index fields as array
  374.      *                                  indexes. Each entry of this array is set to another type of associative
  375.      *                                  array that specifies properties of the index that are specific to
  376.      *                                  each field.
  377.      *
  378.      *                                 Currently, only the sorting property is supported. It should be used
  379.      *                                  to define the sorting direction of the index. It may be set to either
  380.      *                                  ascending or descending.
  381.      *
  382.      *                                 Not all DBMS support index sorting direction configuration. The DBMS
  383.      *                                  drivers of those that do not support it ignore this property. Use the
  384.      *                                  function support() to determine whether the DBMS driver can manage indexes.
  385.  
  386.      *                                  Example
  387.      *                                     array(
  388.      *                                         'fields' => array(
  389.      *                                             'user_name' => array(
  390.      *                                                 'sorting' => 'ascending'
  391.      *                                             ),
  392.      *                                             'last_login' => array()
  393.      *                                         )
  394.      *                                     )
  395.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  396.      * @access public
  397.      */
  398.     function createIndex($table$name$definition)
  399.     {
  400.         $db =$this->getDBInstance();
  401.         if (PEAR::isError($db)) {
  402.             return $db;
  403.         }
  404.  
  405.         $table $db->quoteIdentifier($tabletrue);
  406.         $name  $db->getIndexName($name);
  407.         $query = "CREATE INDEX $name ON $table";
  408.         $fields = array();
  409.         foreach ($definition['fields'as $field_name => $field{
  410.             $field_string $field_name;
  411.             if (array_key_exists('sorting'$field)) {
  412.                 switch ($field['sorting']{
  413.                 case 'ascending':
  414.                     $field_string.= ' ASC';
  415.                     break;
  416.                 case 'descending':
  417.                     $field_string.= ' DESC';
  418.                     break;
  419.                 }
  420.             }
  421.             $fields[$field_string;
  422.         }
  423.         $query .= ' ('.implode(', '$fields')';
  424.         return $db->exec($query);
  425.     }
  426.  
  427.     // }}}
  428.     // {{{ dropIndex()
  429.  
  430.     /**
  431.      * drop existing index
  432.      *
  433.      * @param string    $table         name of table that should be used in method
  434.      * @param string    $name         name of the index to be dropped
  435.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  436.      * @access public
  437.      */
  438.     function dropIndex($table$name)
  439.     {
  440.         $db =$this->getDBInstance();
  441.         if (PEAR::isError($db)) {
  442.             return $db;
  443.         }
  444.  
  445.         $name $db->getIndexName($name);
  446.         return $db->exec("DROP INDEX $name");
  447.     }
  448.  
  449.     // }}}
  450.     // {{{ listTableIndexes()
  451.  
  452.     /**
  453.      * list all indexes in a table
  454.      *
  455.      * @param string    $table      name of table that should be used in method
  456.      * @return mixed data array on success, a MDB2 error on failure
  457.      * @access public
  458.      */
  459.     function listTableIndexes($table)
  460.     {
  461.         $db =$this->getDBInstance();
  462.         if (PEAR::isError($db)) {
  463.             return $db;
  464.         }
  465.  
  466.         $query = "SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name='$table' AND sql NOT NULL ORDER BY name";
  467.         $indexes $db->queryCol($query'text');
  468.         if (PEAR::isError($indexes)) {
  469.             return $indexes;
  470.         }
  471.  
  472.         $result = array();
  473.         foreach ($indexes as $sql{
  474.             $sql strtolower($sql);
  475.             if (preg_match("/^create index ([^ ]*) on /"$sql$tmp)) {
  476.                 $index $this->_isIndexName($tmp[1]);
  477.                 $result[$index= true;
  478.             }
  479.         }
  480.  
  481.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  482.             $result array_change_key_case($result$db->options['field_case']);
  483.         }
  484.         return array_keys($result);
  485.     }
  486.  
  487.     // }}}
  488.     // {{{ createConstraint()
  489.  
  490.     /**
  491.      * create a constraint on a table
  492.      *
  493.      * @param string    $table         name of the table on which the constraint is to be created
  494.      * @param string    $name         name of the constraint to be created
  495.      * @param array     $definition        associative array that defines properties of the constraint to be created.
  496.      *                                  Currently, only one property named FIELDS is supported. This property
  497.      *                                  is also an associative with the names of the constraint fields as array
  498.      *                                  constraints. Each entry of this array is set to another type of associative
  499.      *                                  array that specifies properties of the constraint that are specific to
  500.      *                                  each field.
  501.      *
  502.      *                                  Example
  503.      *                                     array(
  504.      *                                         'fields' => array(
  505.      *                                             'user_name' => array(),
  506.      *                                             'last_login' => array()
  507.      *                                         )
  508.      *                                     )
  509.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  510.      * @access public
  511.      */
  512.     function createConstraint($table$name$definition)
  513.     {
  514.         $db =$this->getDBInstance();
  515.         if (PEAR::isError($db)) {
  516.             return $db;
  517.         }
  518.  
  519.         if (array_key_exists('primary'$definition&& $definition['primary']{
  520.             return $db->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  521.                 'createConstraint: Creating Primary Constraints is not supported');
  522.         }
  523.  
  524.         $table $db->quoteIdentifier($tabletrue);
  525.         $name  $db->getIndexName($name);
  526.         $query = "CREATE UNIQUE INDEX $name ON $table";
  527.         $fields = array();
  528.         foreach ($definition['fields'as $field_name => $field{
  529.             $field_string $field_name;
  530.             if (array_key_exists('sorting'$field)) {
  531.                 switch ($field['sorting']{
  532.                 case 'ascending':
  533.                     $field_string.= ' ASC';
  534.                     break;
  535.                 case 'descending':
  536.                     $field_string.= ' DESC';
  537.                     break;
  538.                 }
  539.             }
  540.             $fields[$field_string;
  541.         }
  542.         $query .= ' ('.implode(', '$fields')';
  543.         return $db->exec($query);
  544.     }
  545.  
  546.     // }}}
  547.     // {{{ dropConstraint()
  548.  
  549.     /**
  550.      * drop existing constraint
  551.      *
  552.      * @param string    $table         name of table that should be used in method
  553.      * @param string    $name         name of the constraint to be dropped
  554.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  555.      * @access public
  556.      */
  557.     function dropConstraint($table$name)
  558.     {
  559.         $db =$this->getDBInstance();
  560.         if (PEAR::isError($db)) {
  561.             return $db;
  562.         }
  563.  
  564.         if ($name == 'PRIMARY'{
  565.             return $db->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  566.                 'dropConstraints: Dropping Primary Constraints is not supported');
  567.         }
  568.  
  569.         $name $db->getIndexName($name);
  570.         return $db->exec("DROP INDEX $name");
  571.     }
  572.  
  573.     // }}}
  574.     // {{{ listTableConstraints()
  575.  
  576.     /**
  577.      * list all sonstraints in a table
  578.      *
  579.      * @param string    $table      name of table that should be used in method
  580.      * @return mixed data array on success, a MDB2 error on failure
  581.      * @access public
  582.      */
  583.     function listTableConstraints($table)
  584.     {
  585.         $db =$this->getDBInstance();
  586.         if (PEAR::isError($db)) {
  587.             return $db;
  588.         }
  589.  
  590.         $query = "SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name='$table' AND sql NOT NULL ORDER BY name";
  591.         $indexes $db->queryCol($query'text');
  592.         if (PEAR::isError($indexes)) {
  593.             return $indexes;
  594.         }
  595.  
  596.         $result = array();
  597.         foreach ($indexes as $sql{
  598.             $sql strtolower($sql);
  599.             if (preg_match("/^create unique index ([^ ]*) on /"$sql$tmp)) {
  600.                 $index $this->_isIndexName($tmp[1]);
  601.                 $result[$index= true;
  602.             }
  603.         }
  604.  
  605.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  606.             $result array_change_key_case($result$db->options['field_case']);
  607.         }
  608.         return array_keys($result);
  609.     }
  610.  
  611.     // }}}
  612.     // {{{ createSequence()
  613.  
  614.     /**
  615.      * create sequence
  616.      *
  617.      * @param string    $seq_name     name of the sequence to be created
  618.      * @param string    $start         start value of the sequence; default is 1
  619.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  620.      * @access public
  621.      */
  622.     function createSequence($seq_name$start = 1)
  623.     {
  624.         $db =$this->getDBInstance();
  625.         if (PEAR::isError($db)) {
  626.             return $db;
  627.         }
  628.  
  629.         $sequence_name $db->quoteIdentifier($db->getSequenceName($seq_name)true);
  630.         $seqcol_name $db->quoteIdentifier($db->options['seqcol_name']true);
  631.         $query = "CREATE TABLE $sequence_name ($seqcol_name INTEGER PRIMARY KEY DEFAULT 0 NOT NULL)";
  632.         $res $db->exec($query);
  633.         if (PEAR::isError($res)) {
  634.             return $res;
  635.         }
  636.         if ($start == 1{
  637.             return MDB2_OK;
  638.         }
  639.         $res $db->exec("INSERT INTO $sequence_name ($seqcol_name) VALUES (".($start-1).')');
  640.         if (!PEAR::isError($res)) {
  641.             return MDB2_OK;
  642.         }
  643.         // Handle error
  644.         $result $db->exec("DROP TABLE $sequence_name");
  645.         if (PEAR::isError($result)) {
  646.             return $db->raiseError(MDB2_ERRORnullnull,
  647.                 'createSequence: could not drop inconsistent sequence table ('.
  648.                 $result->getMessage().' ('.$result->getUserinfo().'))');
  649.         }
  650.         return $db->raiseError(MDB2_ERRORnullnull,
  651.             'createSequence: could not create sequence table ('.
  652.             $res->getMessage().' ('.$res->getUserinfo().'))');
  653.     }
  654.  
  655.     // }}}
  656.     // {{{ dropSequence()
  657.  
  658.     /**
  659.      * drop existing sequence
  660.      *
  661.      * @param string    $seq_name     name of the sequence to be dropped
  662.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  663.      * @access public
  664.      */
  665.     function dropSequence($seq_name)
  666.     {
  667.         $db =$this->getDBInstance();
  668.         if (PEAR::isError($db)) {
  669.             return $db;
  670.         }
  671.  
  672.         $sequence_name $db->quoteIdentifier($db->getSequenceName($seq_name)true);
  673.         return $db->exec("DROP TABLE $sequence_name");
  674.     }
  675.  
  676.     // }}}
  677.     // {{{ listSequences()
  678.  
  679.     /**
  680.      * list all sequences in the current database
  681.      *
  682.      * @return mixed data array on success, a MDB2 error on failure
  683.      * @access public
  684.      */
  685.     function listSequences()
  686.     {
  687.         $db =$this->getDBInstance();
  688.         if (PEAR::isError($db)) {
  689.             return $db;
  690.         }
  691.  
  692.         $query "SELECT name FROM sqlite_master WHERE type='table' AND sql NOT NULL ORDER BY name";
  693.         $table_names $db->queryCol($query);
  694.         if (PEAR::isError($table_names)) {
  695.             return $table_names;
  696.         }
  697.         $result = array();
  698.         for ($i = 0$j count($table_names)$i $j; ++$i{
  699.             if ($sqn $this->_isSequenceName($table_names[$i]))
  700.                 $result[$sqn;
  701.         }
  702.         if ($db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  703.             $result array_map(($db->options['field_case'== CASE_LOWER ? 'strtolower' 'strtoupper')$result);
  704.         }
  705.         return $result;
  706.     }
  707.  
  708.     // }}}
  709. }
  710. ?>

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