<?php

/**
 * SQL Dialect for Microsoft SQL Server and Access databases
 *
 * @version DR1.4
 */
class MicrosoftSQLDialect extends SQLDialect {



	public function getTrue() {
		return 'true';
	}



	public function getFalse() {
		return 'false';
	}



	public function getQuotes() {
		return '"';
	}



	public function getSQL($sql, $order, $descending, $offset, $limit) {
		if ($order) {
			$asc = $descending ? 'DESC' : 'ASC';
			$sql .= stristr($sql, 'ORDER')
				? ", $order $asc"
				: " ORDER BY $order $asc";
		}
		if ($offset) {
			if (stristr($sql, 'OFFSET')) {
				$sql = preg_replace('/OFFSET.*/', " OFFSET $offset", $sql);
			} else {
				$sql .= " OFFSET $offset";
			}
		}
		if ($limit) {
			if (stristr($sql, 'SELECT TOP')) {
				$sql = preg_replace('/SELECT TOP \d/', "SELECT TOP $limit ", $sql);
			} else {
				$sql = str_ireplace('SELECT ', "SELECT TOP $limit ", $sql);
			}
		}
		return $sql;
	}



} // class MicrosoftSQLDialect

?>