| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id: Oracle.php 7490 2010-03-29 19:53:27Z jwage $
|
|
|
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, see
|
|
|
19 |
* <http://www.doctrine-project.org>.
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* Doctrine_Expression_Sqlite
|
|
|
24 |
*
|
|
|
25 |
* @package Doctrine
|
|
|
26 |
* @subpackage Expression
|
|
|
27 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
28 |
* @link www.doctrine-project.org
|
|
|
29 |
* @since 1.0
|
|
|
30 |
* @version $Revision: 7490 $
|
|
|
31 |
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
|
32 |
*/
|
|
|
33 |
class Doctrine_Expression_Oracle extends Doctrine_Expression_Driver
|
|
|
34 |
{
|
|
|
35 |
/**
|
|
|
36 |
* Returns a series of strings concatinated
|
|
|
37 |
*
|
|
|
38 |
* concat() accepts an arbitrary number of parameters. Each parameter
|
|
|
39 |
* must contain an expression
|
|
|
40 |
*
|
|
|
41 |
* @param string $arg1, $arg2 ... $argN strings that will be concatinated.
|
|
|
42 |
* @return string
|
|
|
43 |
*/
|
|
|
44 |
public function concat()
|
|
|
45 |
{
|
|
|
46 |
$args = func_get_args();
|
|
|
47 |
|
|
|
48 |
return join(' || ' , $args);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* return string to call a function to get a substring inside an SQL statement
|
|
|
53 |
*
|
|
|
54 |
* Note: Not SQL92, but common functionality.
|
|
|
55 |
*
|
|
|
56 |
* @param string $value an sql string literal or column name/alias
|
|
|
57 |
* @param integer $position where to start the substring portion
|
|
|
58 |
* @param integer $length the substring portion length
|
|
|
59 |
* @return string SQL substring function with given parameters
|
|
|
60 |
*/
|
|
|
61 |
public function substring($value, $position, $length = null)
|
|
|
62 |
{
|
|
|
63 |
if ($length !== null)
|
|
|
64 |
return "SUBSTR($value, $position, $length)";
|
|
|
65 |
|
|
|
66 |
return "SUBSTR($value, $position)";
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Return string to call a variable with the current timestamp inside an SQL statement
|
|
|
71 |
* There are three special variables for current date and time:
|
|
|
72 |
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
|
|
|
73 |
* - CURRENT_DATE (date, DATE type)
|
|
|
74 |
* - CURRENT_TIME (time, TIME type)
|
|
|
75 |
*
|
|
|
76 |
* @return string to call a variable with the current timestamp
|
|
|
77 |
*/
|
|
|
78 |
public function now($type = 'timestamp')
|
|
|
79 |
{
|
|
|
80 |
switch ($type) {
|
|
|
81 |
case 'date':
|
|
|
82 |
case 'time':
|
|
|
83 |
case 'timestamp':
|
|
|
84 |
default:
|
|
|
85 |
return 'TO_CHAR(CURRENT_TIMESTAMP, \'YYYY-MM-DD HH24:MI:SS\')';
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* random
|
|
|
91 |
*
|
|
|
92 |
* @return string an oracle SQL string that generates a float between 0 and 1
|
|
|
93 |
*/
|
|
|
94 |
public function random()
|
|
|
95 |
{
|
|
|
96 |
return 'dbms_random.value';
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
/**
|
|
|
100 |
* Returns global unique identifier
|
|
|
101 |
*
|
|
|
102 |
* @return string to get global unique identifier
|
|
|
103 |
*/
|
|
|
104 |
public function guid()
|
|
|
105 |
{
|
|
|
106 |
return 'SYS_GUID()';
|
|
|
107 |
}
|
|
|
108 |
}
|