Source for file Mssql.php
Documentation is available at Mssql.php
* Copyright (c) 2008 - 2009 PHPLinq
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* @package PHPLinq_Adapter
* @copyright Copyright (c) 2008 - 2009 PHPLinq (http://www.codeplex.com/PHPLinq)
* @license http://www.gnu.org/licenses/lgpl.txt LGPL
* @version 0.4.0, 2009-01-27
/** PHPLinq_Adapter_Abstract */
require_once 'PHPLinq/Adapter/Abstract.php';
* PHPLinq_Adapter_Pdo_Mssql
* @package PHPLinq_Adapter
* @copyright Copyright (c) 2008 - 2009 PHPLinq (http://www.codeplex.com/PHPLinq)
* @param Zend_Db_Adapter_Abstract $adapter
public function __construct(Zend_Db_Adapter_Abstract $adapter = null) {
* @param string $operator
* Return ASCII value of character
* @param string $string A character
public function ord($string) {
return 'ASCII(' . $string . ')';
* Return a specific character
* @param int $string The ascii code
public function chr($ascii) {
return 'CHR(' . $string . ')';
* Return part of a string
public function substr($string, $start, $length = '') {
return 'SUBSTR(' . $string . ', ' . $start . $this->strlen($string) . ' - ' . $start . ')';
return 'SUBSTR(' . $string . ', ' . $start . ', ' . $length . ')';
public function strlen($string) {
return 'LEN(' . $string . ')';
* Count elements in an array, or properties in an object
public function count($var) {
return 'COUNT(' . $var . ')';
public function max($values) {
return 'MAX(' . $values . ')';
public function min($values) {
return 'MIN(' . $values . ')';
public function abs($number) {
return 'ABS(' . $number . ')';
* Make a string lowercase
return 'LOWER(' . $str . ')';
* Make a string uppercase
return 'UPPER(' . $str . ')';
* Strip whitespace (or other characters) from the beginning of a string
public function ltrim($str) {
return 'LTRIM(' . $str . ')';
* Generate a random integer
* Replace all occurrences of the search string with the replacement string
public function str_replace($search, $replace, $subject) {
return 'REPLACE(' . $subject . ', ' . $search . ', ' . $replace . ')';
public function round($val, $precision = 0) {
return 'ROUND(' . $val . ', ' . $precision . ')';
* Strip whitespace (or other characters) from the end of a string
public function rtrim($str) {
return 'RTRIM(' . $str . ')';
* Strip whitespace (or other characters) from the beginning and end of a string
public function trim($str) {
return 'LTRIM(RTRIM(' . $str . '))';
* Find position of first occurrence of a string
* @param string $haystack
public function strpos($haystack, $needle, $offset = 0) {
return 'CHARINDEX(' . $needle . ', ' . $haystack . ', ' . $offset . ')';
* Find position of first occurrence of a case-insensitive string
* @param string $haystack
public function stripos($haystack, $needle, $offset = 0) {
* Make a string's first character lowercase
* Make a string's first character uppercase
* Calculate the md5 hash of a string
* @param boolean $raw_output
public function md5($str, $raw_output = false) {
return 'HASHBYTES(\'MD5\', ' . $str . ')';
* Calculate the sha1 hash of a string
* @param boolean $raw_output
public function sha1($str, $raw_output = false) {
return 'HASHBYTES(\'SHA1\', ' . $str . ')';
* Calculate the soundex key of a string
return 'SOUNDEX(' . $str . ')';
* Quote string with slashes
return 'QUOTENAME(' . $str . ', \'"\')';
return 'REPLICATE(' . $input . ', ' . $multiplier . ')';
|