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