Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 *  $Id: Mssql.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_Mssql
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_Mssql extends Doctrine_Expression_Driver
34
{
35
    /**
36
     * Return string to call a variable with the current timestamp inside an SQL statement
37
     * There are three special variables for current date and time:
38
     * - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
39
     * - CURRENT_DATE (date, DATE type)
40
     * - CURRENT_TIME (time, TIME type)
41
     *
42
     * @return string to call a variable with the current timestamp
43
     * @access public
44
     */
45
    public function now($type = 'timestamp')
46
    {
47
        switch ($type) {
48
            case 'time':
49
            case 'date':
50
            case 'timestamp':
51
            default:
52
                return 'GETDATE()';
53
        }
54
    }
55
 
56
    /**
57
     * return string to call a function to get a substring inside an SQL statement
58
     *
59
     * @return string to call a function to get a substring
60
     */
61
    public function substring($value, $position, $length = null)
62
    {
63
        if ( ! is_null($length)) {
64
            return 'SUBSTRING(' . $value . ', ' . $position . ', ' . $length . ')';
65
        }
66
        return 'SUBSTRING(' . $value . ', ' . $position . ', LEN(' . $value . ') - ' . $position . ' + 1)';
67
    }
68
 
69
    /**
70
     * Returns string to concatenate two or more string parameters
71
     *
72
     * @param string $arg1
73
     * @param string $arg2
74
     * @param string $values...
75
     * @return string to concatenate two strings
76
     */
77
    public function concat()
78
    {
79
        $args = func_get_args();
80
        return '(' . implode(' + ', $args) . ')';
81
    }
82
 
83
    /**
84
     * Returns global unique identifier
85
     *
86
     * @return string to get global unique identifier
87
     */
88
    public function guid()
89
    {
90
        return 'NEWID()';
91
    }
92
 
93
    /**
94
     * Returns the length of a text field
95
     *
96
     * @param string $column
97
     *
98
     * @return string
99
     */
100
    public function length($column)
101
    {
102
        return 'LEN (' . $column . ')';
103
    }
104
}