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