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 implements Nette\Database\ISupplementalDriver
17: {
18: use Nette\SmartObject;
19:
20: public function convertException(\PDOException $e)
21: {
22: return Nette\Database\DriverException::from($e);
23: }
24:
25:
26:
27:
28:
29: public function delimite($name)
30: {
31:
32: return '[' . str_replace(['[', ']'], ['[[', ']]'], $name) . ']';
33: }
34:
35:
36: public function formatBool($value)
37: {
38: return $value ? '1' : '0';
39: }
40:
41:
42: public function formatDateTime( $value)
43: {
44: return $value->format("'Y-m-d H:i:s'");
45: }
46:
47:
48: public function formatDateInterval(\DateInterval $value)
49: {
50: throw new Nette\NotSupportedException;
51: }
52:
53:
54: public function formatLike($value, $pos)
55: {
56: $value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']);
57: return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
58: }
59:
60:
61: public function applyLimit(&$sql, $limit, $offset)
62: {
63: if ($offset) {
64: throw new Nette\NotSupportedException('Offset is not supported by this database.');
65:
66: } elseif ($limit < 0) {
67: throw new Nette\InvalidArgumentException('Negative offset or limit.');
68:
69: } elseif ($limit !== null) {
70: $sql = preg_replace('#^\s*(SELECT(\s+DISTINCT|\s+ALL)?|UPDATE|DELETE)#i', '$0 TOP ' . (int) $limit, $sql, 1, $count);
71: if (!$count) {
72: throw new Nette\InvalidArgumentException('SQL query must begin with SELECT, UPDATE or DELETE command.');
73: }
74: }
75: }
76:
77:
78: public function normalizeRow($row)
79: {
80: return $row;
81: }
82:
83:
84:
85:
86:
87: public function getTables()
88: {
89: throw new Nette\NotImplementedException;
90: }
91:
92:
93: public function getColumns($table)
94: {
95: throw new Nette\NotImplementedException;
96: }
97:
98:
99: public function getIndexes($table)
100: {
101: throw new Nette\NotImplementedException;
102: }
103:
104:
105: public function getForeignKeys($table)
106: {
107: throw new Nette\NotImplementedException;
108: }
109:
110:
111: public function getColumnTypes(\PDOStatement $statement)
112: {
113: return Nette\Database\Helpers::detectTypes($statement);
114: }
115:
116:
117: public function isSupported($item)
118: {
119: return $item === self::SUPPORT_SUBSELECT;
120: }
121: }
122: