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