# Source for file Mssql.php

Documentation is available at Mssql.php

1. <?php
2. /*
3. * $Id: Mssql.php 1917 2007-07-01 11:27:45Z zYne $
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.phpdoctrine.com>.
20. */
21. Doctrine::autoload('Doctrine_Expression_Driver');
22. /**
23. * Doctrine_Expression_Mssql
24. *
25. * @package Doctrine
26. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
27. * @category Object Relational Mapping
28. * @link www.phpdoctrine.com
29. * @since 1.0
30. * @version $Revision: 1917 $
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. * return string to call a function to get a substring inside an SQL statement
57. *
58. * @return string to call a function to get a substring
59. */
60. public function substring($value, $position, $length = null)
61. {
62. if ( ! is_null($length)) {
63. return 'SUBSTRING(' . $value . ', ' . $position . ', ' . $length . ')';
64. }
65. return 'SUBSTRING(' . $value . ', ' . $position . ', LEN(' . $value . ') - ' . $position . ' + 1)';
66. }
67. /**
68. * Returns string to concatenate two or more string parameters
69. *
70. * @param string $arg1
71. * @param string $arg2
72. * @param string $values...
73. * @return string to concatenate two strings
74. */
75. public function concat()
76. {
77. $args = func_get_args();
78. return '(' . implode(' + ', $args) . ')';
79. }
80. /**
81. * Returns global unique identifier
82. *
83. * @return string to get global unique identifier
84. */
85. public function guid()
86. {
87. return 'NEWID()';
88. }
89. }