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

Source for file DBMySQL.php

Documentation is available at DBMySQL.php

  1. <?php
  2.  
  3. /*
  4.  *  $Id: DBMySQL.php 784 2007-11-08 10:15:50Z 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 in order to connect to a MySQL database.
  25.  *
  26.  * @author     Hans Lellelid <hans@xmpl.org> (Propel)
  27.  * @author     Jon S. Stevens <jon@clearink.com> (Torque)
  28.  * @author     Brett McLaughlin <bmclaugh@algx.net> (Torque)
  29.  * @author     Daniel Rall <dlr@finemaltcoding.com> (Torque)
  30.  * @version    $Revision: 784 $
  31.  * @package    propel.adapter
  32.  */
  33. class DBMySQL extends DBAdapter {
  34.  
  35.     /**
  36.      * This method is called after a connection was created to run necessary
  37.      * post-initialization queries or code.
  38.      *
  39.      * @param      PDO   A PDO connection instance.
  40.      * @param      array An array of settings.
  41.      */
  42.     public function initConnection(PDO $conarray $settings)
  43.     {
  44.         if (isset($settings['charset']['value'])) {
  45.             $con->query('SET NAMES "' $settings['charset']['value''"');
  46.         }
  47.         parent::initConnection($con$settings);
  48.     }
  49.  
  50.     /**
  51.      * This method is used to ignore case.
  52.      *
  53.      * @param      in The string to transform to upper case.
  54.      * @return     The upper case string.
  55.      */
  56.     public function toUpperCase($in)
  57.     {
  58.         return "UPPER(" $in ")";
  59.     }
  60.  
  61.     /**
  62.      * This method is used to ignore case.
  63.      *
  64.      * @param      in The string whose case to ignore.
  65.      * @return     The string in a case that can be ignored.
  66.      */
  67.     public function ignoreCase($in)
  68.     {
  69.         return "UPPER(" $in ")";
  70.     }
  71.  
  72.     /**
  73.      * Returns SQL which concatenates the second string to the first.
  74.      *
  75.      * @param      string String to concatenate.
  76.      * @param      string String to append.
  77.      * @return     string 
  78.      */
  79.     public function concatString($s1$s2)
  80.     {
  81.         return "CONCAT($s1$s2)";
  82.     }
  83.  
  84.     /**
  85.      * Returns SQL which extracts a substring.
  86.      *
  87.      * @param      string String to extract from.
  88.      * @param      int Offset to start from.
  89.      * @param      int Number of characters to extract.
  90.      * @return     string 
  91.      */
  92.     public function subString($s$pos$len)
  93.     {
  94.         return "SUBSTRING($s$pos$len)";
  95.     }
  96.  
  97.     /**
  98.      * Returns SQL which calculates the length (in chars) of a string.
  99.      *
  100.      * @param      string String to calculate length of.
  101.      * @return     string 
  102.      */
  103.     public function strLength($s)
  104.     {
  105.         return "CHAR_LENGTH($s)";
  106.     }
  107.  
  108.  
  109.     /**
  110.      * Locks the specified table.
  111.      *
  112.      * @param      Connection $con The Creole connection to use.
  113.      * @param      string $table The name of the table to lock.
  114.      * @throws     PDOException No Statement could be created or
  115.      *  executed.
  116.      */
  117.     public function lockTable(PDO $con$table)
  118.     {
  119.         $con->exec("LOCK TABLE " $table " WRITE");
  120.     }
  121.  
  122.     /**
  123.      * Unlocks the specified table.
  124.      *
  125.      * @param      PDO $con The PDO connection to use.
  126.      * @param      string $table The name of the table to unlock.
  127.      * @throws     PDOException No Statement could be created or
  128.      *  executed.
  129.      */
  130.     public function unlockTable(PDO $con$table)
  131.     {
  132.         $statement $con->exec("UNLOCK TABLES");
  133.     }
  134.  
  135.     /**
  136.      * @see        DBAdapter::quoteIdentifier()
  137.      */
  138.     public function quoteIdentifier($text)
  139.     {
  140.         return '`' $text '`';
  141.     }
  142.  
  143.     /**
  144.      * @see        DBAdapter::useQuoteIdentifier()
  145.      */
  146.     public function useQuoteIdentifier()
  147.     {
  148.         return true;
  149.     }
  150.  
  151.     /**
  152.      * @see        DBAdapter::applyLimit()
  153.      */
  154.     public function applyLimit(&$sql$offset$limit)
  155.     {
  156.         if $limit {
  157.             $sql .= " LIMIT " ($offset $offset ", " ""$limit;
  158.         else if $offset {
  159.             $sql .= " LIMIT " $offset ", 18446744073709551615";
  160.         }
  161.     }
  162.  
  163.     /**
  164.      * @see        DBAdapter::random()
  165.      */
  166.     public function random($seed null)
  167.     {
  168.         return 'rand('.((int) $seed).')';
  169.     }
  170.  
  171. }

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