1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Database\Drivers;
9:
10: use Nette;
11:
12:
13: 14: 15:
16: class MsSqlDriver extends Nette\Object implements Nette\Database\ISupplementalDriver
17: {
18:
19: public function convertException(\PDOException $e)
20: {
21: return Nette\Database\DriverException::from($e);
22: }
23:
24:
25:
26:
27:
28: 29: 30:
31: public function delimite($name)
32: {
33:
34: return '[' . str_replace(array('[', ']'), array('[[', ']]'), $name) . ']';
35: }
36:
37:
38: 39: 40:
41: public function formatBool($value)
42: {
43: return $value ? '1' : '0';
44: }
45:
46:
47: 48: 49:
50: public function formatDateTime( $value)
51: {
52: return $value->format("'Y-m-d H:i:s'");
53: }
54:
55:
56: 57: 58:
59: public function formatDateInterval(\DateInterval $value)
60: {
61: throw new Nette\NotSupportedException;
62: }
63:
64:
65: 66: 67:
68: public function formatLike($value, $pos)
69: {
70: $value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]'));
71: return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
72: }
73:
74:
75: 76: 77:
78: public function applyLimit(& $sql, $limit, $offset)
79: {
80: if ($offset) {
81: throw new Nette\NotSupportedException('Offset is not supported by this database.');
82:
83: } elseif ($limit < 0) {
84: throw new Nette\InvalidArgumentException('Negative offset or limit.');
85:
86: } elseif ($limit !== NULL) {
87: $sql = preg_replace('#^\s*(SELECT(\s+DISTINCT|\s+ALL)?|UPDATE|DELETE)#i', '$0 TOP ' . (int) $limit, $sql, 1, $count);
88: if (!$count) {
89: throw new Nette\InvalidArgumentException('SQL query must begin with SELECT, UPDATE or DELETE command.');
90: }
91: }
92: }
93:
94:
95: 96: 97:
98: public function normalizeRow($row)
99: {
100: return $row;
101: }
102:
103:
104:
105:
106:
107: 108: 109:
110: public function getTables()
111: {
112: throw new Nette\NotImplementedException;
113: }
114:
115:
116: 117: 118:
119: public function getColumns($table)
120: {
121: throw new Nette\NotImplementedException;
122: }
123:
124:
125: 126: 127:
128: public function getIndexes($table)
129: {
130: throw new Nette\NotImplementedException;
131: }
132:
133:
134: 135: 136:
137: public function getForeignKeys($table)
138: {
139: throw new Nette\NotImplementedException;
140: }
141:
142:
143: 144: 145:
146: public function getColumnTypes(\PDOStatement $statement)
147: {
148: return Nette\Database\Helpers::detectTypes($statement);
149: }
150:
151:
152: 153: 154: 155:
156: public function isSupported($item)
157: {
158: return $item === self::SUPPORT_SUBSELECT;
159: }
160:
161: }
162: