source: pro-violet-viettel/sourcecode/api.violet.vn/www/plugins/sfPropel13Plugin/lib/vendor/propel/adapter/DBMySQL.php

Last change on this file was 289, checked in by dungnv, 11 years ago
File size: 4.0 KB
Line 
1<?php
2
3/*
4 *  $Id: DBMySQL.php 989 2008-03-11 14:29:30Z 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: 989 $
31 * @package    propel.adapter
32 */
33class DBMySQL extends DBAdapter {
34
35        /**
36         * This method is used to ignore case.
37         *
38         * @param      in The string to transform to upper case.
39         * @return     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 "CONCAT($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, $pos, $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        /**
95         * Locks the specified table.
96         *
97         * @param      Connection $con The Creole connection to use.
98         * @param      string $table The name of the table to lock.
99         * @throws     PDOException No Statement could be created or
100         * executed.
101         */
102        public function lockTable(PDO $con, $table)
103        {
104                $con->exec("LOCK TABLE " . $table . " WRITE");
105        }
106
107        /**
108         * Unlocks the specified table.
109         *
110         * @param      PDO $con The PDO connection to use.
111         * @param      string $table The name of the table to unlock.
112         * @throws     PDOException No Statement could be created or
113         * executed.
114         */
115        public function unlockTable(PDO $con, $table)
116        {
117                $statement = $con->exec("UNLOCK TABLES");
118        }
119
120        /**
121         * @see        DBAdapter::quoteIdentifier()
122         */
123        public function quoteIdentifier($text)
124        {
125                return '`' . $text . '`';
126        }
127
128        /**
129         * @see        DBAdapter::useQuoteIdentifier()
130         */
131        public function useQuoteIdentifier()
132        {
133                return true;
134        }
135
136        /**
137         * @see        DBAdapter::applyLimit()
138         */
139        public function applyLimit(&$sql, $offset, $limit)
140        {
141                if ( $limit > 0 ) {
142                        $sql .= " LIMIT " . ($offset > 0 ? $offset . ", " : "") . $limit;
143                } else if ( $offset > 0 ) {
144                        $sql .= " LIMIT " . $offset . ", 18446744073709551615";
145                }
146        }
147
148        /**
149         * @see        DBAdapter::random()
150         */
151        public function random($seed = null)
152        {
153                return 'rand('.((int) $seed).')';
154        }
155
156}
Note: See TracBrowser for help on using the repository browser.