| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* $Id: DBSQLite.php 1262 2009-10-26 20:54:39Z francois $
|
|
|
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 SQLite database.
|
|
|
25 |
*
|
|
|
26 |
* @author Hans Lellelid <hans@xmpl.org>
|
|
|
27 |
* @version $Revision: 1262 $
|
|
|
28 |
* @package propel.adapter
|
|
|
29 |
*/
|
|
|
30 |
class DBSQLite extends DBAdapter {
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* For SQLite this method has no effect, since SQLite doesn't support specifying a character
|
|
|
34 |
* set (or, another way to look at it, it doesn't require a single character set per DB).
|
|
|
35 |
*
|
|
|
36 |
* @param PDO A PDO connection instance.
|
|
|
37 |
* @param string The charset encoding.
|
|
|
38 |
* @throws PropelException If the specified charset doesn't match sqlite_libencoding()
|
|
|
39 |
*/
|
|
|
40 |
public function setCharset(PDO $con, $charset)
|
|
|
41 |
{
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* This method is used to ignore case.
|
|
|
46 |
*
|
|
|
47 |
* @param in The string to transform to upper case.
|
|
|
48 |
* @return The upper case string.
|
|
|
49 |
*/
|
|
|
50 |
public function toUpperCase($in)
|
|
|
51 |
{
|
|
|
52 |
return 'UPPER(' . $in . ')';
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
* This method is used to ignore case.
|
|
|
57 |
*
|
|
|
58 |
* @param in The string whose case to ignore.
|
|
|
59 |
* @return The string in a case that can be ignored.
|
|
|
60 |
*/
|
|
|
61 |
public function ignoreCase($in)
|
|
|
62 |
{
|
|
|
63 |
return 'UPPER(' . $in . ')';
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* Returns SQL which concatenates the second string to the first.
|
|
|
68 |
*
|
|
|
69 |
* @param string String to concatenate.
|
|
|
70 |
* @param string String to append.
|
|
|
71 |
* @return string
|
|
|
72 |
*/
|
|
|
73 |
public function concatString($s1, $s2)
|
|
|
74 |
{
|
|
|
75 |
return "($s1 || $s2)";
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Returns SQL which extracts a substring.
|
|
|
80 |
*
|
|
|
81 |
* @param string String to extract from.
|
|
|
82 |
* @param int Offset to start from.
|
|
|
83 |
* @param int Number of characters to extract.
|
|
|
84 |
* @return string
|
|
|
85 |
*/
|
|
|
86 |
public function subString($s, $pos, $len)
|
|
|
87 |
{
|
|
|
88 |
return "substr($s, $pos, $len)";
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Returns SQL which calculates the length (in chars) of a string.
|
|
|
93 |
*
|
|
|
94 |
* @param string String to calculate length of.
|
|
|
95 |
* @return string
|
|
|
96 |
*/
|
|
|
97 |
public function strLength($s)
|
|
|
98 |
{
|
|
|
99 |
return "length($s)";
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
/**
|
|
|
103 |
* @see DBAdapter::quoteIdentifier()
|
|
|
104 |
*/
|
|
|
105 |
public function quoteIdentifier($text)
|
|
|
106 |
{
|
|
|
107 |
return '[' . $text . ']';
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* @see DBAdapter::applyLimit()
|
|
|
112 |
*/
|
|
|
113 |
public function applyLimit(&$sql, $offset, $limit)
|
|
|
114 |
{
|
|
|
115 |
if ( $limit > 0 ) {
|
|
|
116 |
$sql .= " LIMIT " . $limit . ($offset > 0 ? " OFFSET " . $offset : "");
|
|
|
117 |
} elseif ( $offset > 0 ) {
|
|
|
118 |
$sql .= " LIMIT -1 OFFSET " . $offset;
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
public function random($seed=NULL)
|
|
|
123 |
{
|
|
|
124 |
return 'random()';
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
}
|