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

Source for file DBPostgres.php

Documentation is available at DBPostgres.php

  1. <?php
  2.  
  3. /*
  4.  *  $Id: DBPostgres.php 563 2007-02-01 09:45:55Z heltem $
  5.  *
  6.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  7.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  8.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  9.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  10.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  12.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  13.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  14.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  16.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17.  *
  18.  * This software consists of voluntary contributions made by many individuals
  19.  * and is licensed under the LGPL. For more information please see
  20.  * <http://propel.phpdb.org>.
  21.  */
  22.  
  23. /**
  24.  * This is used to connect to PostgresQL databases.
  25.  *
  26.  * <a href="http://www.pgsql.org">http://www.pgsql.org</a>
  27.  *
  28.  * @author     Hans Lellelid <hans@xmpl.org> (Propel)
  29.  * @author     Hakan Tandogan <hakan42@gmx.de> (Torque)
  30.  * @version    $Revision: 563 $
  31.  * @package    propel.adapter
  32.  */
  33. class DBPostgres extends DBAdapter {
  34.  
  35.     /**
  36.      * This method is used to ignore case.
  37.      *
  38.      * @param      string $in The string to transform to upper case.
  39.      * @return     string The upper case string.
  40.      */
  41.     public function toUpperCase($in)
  42.     {
  43.         return "UPPER(" $in ")";
  44.     }
  45.  
  46.     /**
  47.      * This method is used to ignore case.
  48.      *
  49.      * @param      in The string whose case to ignore.
  50.      * @return     The string in a case that can be ignored.
  51.      */
  52.     public function ignoreCase($in)
  53.     {
  54.         return "UPPER(" $in ")";
  55.     }
  56.  
  57.     /**
  58.      * Returns SQL which concatenates the second string to the first.
  59.      *
  60.      * @param      string String to concatenate.
  61.      * @param      string String to append.
  62.      * @return     string 
  63.      */
  64.     public function concatString($s1$s2)
  65.     {
  66.         return "($s1 || $s2)";
  67.     }
  68.  
  69.     /**
  70.      * Returns SQL which extracts a substring.
  71.      *
  72.      * @param      string String to extract from.
  73.      * @param      int Offset to start from.
  74.      * @param      int Number of characters to extract.
  75.      * @return     string 
  76.      */
  77.     public function subString($s$pos$len)
  78.     {
  79.         return "substring($s from $pos($len > -"for $len""")";
  80.     }
  81.  
  82.     /**
  83.      * Returns SQL which calculates the length (in chars) of a string.
  84.      *
  85.      * @param      string String to calculate length of.
  86.      * @return     string 
  87.      */
  88.     public function strLength($s)
  89.     {
  90.         return "char_length($s)";
  91.     }
  92.  
  93.     /**
  94.      * @see        DBAdapter::getIdMethod()
  95.      */
  96.     protected function getIdMethod()
  97.     {
  98.         return DBAdapter::ID_METHOD_SEQUENCE;
  99.     }
  100.  
  101.     /**
  102.      * Gets ID for specified sequence name.
  103.      */
  104.     public function getId(PDO $con$name null)
  105.     {
  106.         if ($name === null{
  107.             throw new PropelException("Unable to fetch next sequence ID without sequence name.");
  108.         }
  109.         $stmt $con->query("SELECT nextval(".$con->quote($name).")");
  110.         $row $stmt->fetch(PDO::FETCH_NUM);
  111.         return $row[0];
  112.     }
  113.  
  114.     /**
  115.      * Returns timestamp formatter string for use in date() function.
  116.      * @return     string 
  117.      */
  118.     public function getTimestampFormatter()
  119.     {
  120.         return "Y-m-d H:i:s O";
  121.     }
  122.  
  123.     /**
  124.      * Returns timestamp formatter string for use in date() function.
  125.      * @return     string 
  126.      */
  127.     public function getTimeFormatter()
  128.     {
  129.         return "H:i:s O";
  130.     }
  131.  
  132.     /**
  133.      * @see        DBAdapter::applyLimit()
  134.      */
  135.     public function applyLimit(&$sql$offset$limit)
  136.     {
  137.         if $limit {
  138.             $sql .= " LIMIT ".$limit;
  139.         }
  140.         if $offset {
  141.             $sql .= " OFFSET ".$offset;
  142.         }
  143.     }
  144.  
  145.     public function random($seed=NULL)
  146.     {
  147.         return 'random()';
  148.     }
  149. }

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