propel-adapter
[ class tree: propel-adapter ] [ index: propel-adapter ] [ all elements ]

Source for file DBAdapter.php

Documentation is available at DBAdapter.php

  1. <?php
  2. /*
  3.  *  $Id: DBAdapter.php 563 2007-02-01 09:45:55Z heltem $
  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 please see
  19.  * <http://propel.phpdb.org>.
  20.  */
  21.  
  22. /**
  23.  * DBAdapter</code> defines the interface for a Propel database adapter.
  24.  *
  25.  * <p>Support for new databases is added by subclassing
  26.  * <code>DBAdapter</code> and implementing its abstract interface, and by
  27.  * registering the new database adapter and corresponding Creole
  28.  * driver in the private adapters map (array) in this class.</p>
  29.  *
  30.  * <p>The Propel database adapters exist to present a uniform
  31.  * interface to database access across all available databases.  Once
  32.  * the necessary adapters have been written and configured,
  33.  * transparent swapping of databases is theoretically supported with
  34.  * <i>zero code change</i> and minimal configuration file
  35.  * modifications.</p>
  36.  *
  37.  * @author     Hans Lellelid <hans@xmpl.org> (Propel)
  38.  * @author     Jon S. Stevens <jon@latchkey.com> (Torque)
  39.  * @author     Brett McLaughlin <bmclaugh@algx.net> (Torque)
  40.  * @author     Daniel Rall <dlr@finemaltcoding.com> (Torque)
  41.  * @version    $Revision: 563 $
  42.  * @package    propel.adapter
  43.  */
  44. abstract class DBAdapter {
  45.  
  46.     const ID_METHOD_NONE 0;
  47.     const ID_METHOD_AUTOINCREMENT 1;
  48.     const ID_METHOD_SEQUENCE 2;
  49.  
  50.     /**
  51.      * Creole driver to Propel adapter map.
  52.      * @var        array 
  53.      */
  54.     private static $adapters array(
  55.         'mysql' => 'DBMySQL',
  56.         'mysqli' => 'DBMySQLi',
  57.         'mssql' => 'DBMSSQL',
  58.         'sybase' => 'DBSybase',
  59.         'oracle' => 'DBOracle',
  60.         'pgsql' => 'DBPostgres',
  61.         'sqlite' => 'DBSQLite',
  62.         '' => 'DBNone',
  63.     );
  64.  
  65.     /**
  66.      * Creates a new instance of the database adapter associated
  67.      * with the specified Creole driver.
  68.      *
  69.      * @param      string $driver The name of the Propel/Creole driver to
  70.      *  create a new adapter instance for or a shorter form adapter key.
  71.      * @return     DBAdapter An instance of a Propel database adapter.
  72.      * @throws     PropelException if the adapter could not be instantiated.
  73.      */
  74.     public static function factory($driver{
  75.         $adapterClass = isset(self::$adapters[$driver]self::$adapters[$drivernull;
  76.         if ($adapterClass !== null{
  77.             $a new $adapterClass();
  78.             return $a;
  79.         else {
  80.             throw new PropelException("Unsupported Propel driver: " $driver ": Check your configuration file");
  81.         }
  82.     }
  83.  
  84.     /**
  85.      * This method is called after a connection was created to run necessary
  86.      * post-initialization queries or code.
  87.      *
  88.      * This base method runs queries specified using the "query" setting.
  89.      *
  90.      * @param      PDO   A PDO connection instance.
  91.      * @param      array An array of settings.
  92.      */
  93.     public function initConnection(PDO $conarray $settings)
  94.     {
  95.         if (isset($settings['queries']&& is_array($settings['queries'])) {
  96.             foreach ($settings['queries'as $queries{
  97.                 foreach ((array)$queries as $query{
  98.                     $con->query($query);
  99.                 }
  100.             }
  101.         }
  102.     }
  103.  
  104.     /**
  105.      * This method is used to ignore case.
  106.      *
  107.      * @param      string The string to transform to upper case.
  108.      * @return     string The upper case string.
  109.      */
  110.     public abstract function toUpperCase($in);
  111.  
  112.     /**
  113. /**
  114.      * Returns the character used to indicate the beginning and end of
  115.      * a piece of text used in a SQL statement (generally a single
  116.      * quote).
  117.      *
  118.      * @return     string The text delimeter.
  119.      */
  120.     public function getStringDelimiter()
  121.     {
  122.         return '\'';
  123.     }
  124.  
  125.     /**
  126.      * This method is used to ignore case.
  127.      *
  128.      * @param      string $in The string whose case to ignore.
  129.      * @return     string The string in a case that can be ignored.
  130.      */
  131.     public abstract function ignoreCase($in);
  132.  
  133.     /**
  134. /**
  135.      * This method is used to ignore case in an ORDER BY clause.
  136.      * Usually it is the same as ignoreCase, but some databases
  137.      * (Interbase for example) does not use the same SQL in ORDER BY
  138.      * and other clauses.
  139.      *
  140.      * @param      string $in The string whose case to ignore.
  141.      * @return     string The string in a case that can be ignored.
  142.      */
  143.     public function ignoreCaseInOrderBy($in)
  144.     {
  145.         return $this->ignoreCase($in);
  146.     }
  147.  
  148.     /**
  149.      * Returns SQL which concatenates the second string to the first.
  150.      *
  151.      * @param      string String to concatenate.
  152.      * @param      string String to append.
  153.      * @return     string 
  154.      */
  155.     public abstract function concatString($s1$s2);
  156.  
  157.     /**
  158. /**
  159.      * Returns SQL which extracts a substring.
  160.      *
  161.      * @param      string String to extract from.
  162.      * @param      int Offset to start from.
  163.      * @param      int Number of characters to extract.
  164.      * @return     string 
  165.      */
  166.     public abstract function subString($s$pos$len);
  167.  
  168.     /**
  169. /**
  170.      * Returns SQL which calculates the length (in chars) of a string.
  171.      *
  172.      * @param      string String to calculate length of.
  173.      * @return     string 
  174.      */
  175.     public abstract function strLength($s);
  176.  
  177.  
  178.     /**
  179. /**
  180.      * Quotes database objec identifiers (table names, col names, sequences, etc.).
  181.      * @param      string $text The identifier to quote.
  182.      * @return     string The quoted identifier.
  183.      */
  184.     public function quoteIdentifier($text)
  185.     {
  186.         return '"' $text '"';
  187.     }
  188.  
  189.     /**
  190.      * Returns the native ID method for this RDBMS.
  191.      * @return     int one of DBAdapter:ID_METHOD_SEQUENCE, DBAdapter::ID_METHOD_AUTOINCREMENT.
  192.      */
  193.     protected function getIdMethod()
  194.     {
  195.         return DBAdapter::ID_METHOD_AUTOINCREMENT;
  196.     }
  197.  
  198.     /**
  199.      * Whether this adapter uses an ID generation system that requires getting ID _before_ performing INSERT.
  200.      * @return     boolean 
  201.      */
  202.     public function isGetIdBeforeInsert()
  203.     {
  204.         return ($this->getIdMethod(=== DBAdapter::ID_METHOD_SEQUENCE);
  205.     }
  206.  
  207.     /**
  208.      * Whether this adapter uses an ID generation system that requires getting ID _before_ performing INSERT.
  209.      * @return     boolean 
  210.      */
  211.     public function isGetIdAfterInsert()
  212.     {
  213.         return ($this->getIdMethod(=== DBAdapter::ID_METHOD_AUTOINCREMENT);
  214.     }
  215.  
  216.     /**
  217.      * Gets the generated ID (either last ID for autoincrement or next sequence ID).
  218.      * @return     mixed 
  219.      */
  220.     public function getId(PDO $con$name null)
  221.     {
  222.         return $con->lastInsertId($name);
  223.     }
  224.  
  225.     /**
  226.      * Returns timestamp formatter string for use in date() function.
  227.      * @return     string 
  228.      */
  229.     public function getTimestampFormatter()
  230.     {
  231.         return "Y-m-d H:i:s";
  232.     }
  233.  
  234.     /**
  235.      * Returns date formatter string for use in date() function.
  236.      * @return     string 
  237.      */
  238.     public function getDateFormatter()
  239.     {
  240.         return "Y-m-d";
  241.     }
  242.  
  243.     /**
  244.      * Returns time formatter string for use in date() function.
  245.      * @return     string 
  246.      */
  247.     public function getTimeFormatter()
  248.     {
  249.         return "H:i:s";
  250.     }
  251.  
  252.     /**
  253.      * Should Column-Names get identifiers for inserts or updates.
  254.      * By default false is returned -> backwards compability.
  255.      *
  256.      * it`s a workaround...!!!
  257.      *
  258.      * @todo       should be abstract
  259.      * @return     boolean 
  260.      * @deprecated
  261.      */
  262.     public function useQuoteIdentifier({
  263.         return false;
  264.     }
  265.  
  266.     /**
  267.      * Modifies the passed-in SQL to add LIMIT and/or OFFSET.
  268.      */
  269.     public abstract function applyLimit(&$sql$offset$limit);
  270.  
  271.     public abstract function random($seed=NULL);
  272.  

Documentation generated on Thu, 22 Nov 2007 03:33:40 +0000 by phpDocumentor 1.4.0