1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Database\Drivers;
9:
10: use Nette;
11:
12:
13: 14: 15:
16: class OciDriver extends Nette\Object implements Nette\Database\ISupplementalDriver
17: {
18:
19: private $connection;
20:
21:
22: private $fmtDateTime;
23:
24:
25: public function __construct(Nette\Database\Connection $connection, array $options)
26: {
27: $this->connection = $connection;
28: $this->fmtDateTime = isset($options['formatDateTime']) ? $options['formatDateTime'] : 'U';
29: }
30:
31:
32: public function convertException(\PDOException $e)
33: {
34: $code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL;
35: if (in_array($code, array(1, 2299, 38911), TRUE)) {
36: return Nette\Database\UniqueConstraintViolationException::from($e);
37:
38: } elseif (in_array($code, array(1400), TRUE)) {
39: return Nette\Database\NotNullConstraintViolationException::from($e);
40:
41: } elseif (in_array($code, array(2266, 2291, 2292), TRUE)) {
42: return Nette\Database\ForeignKeyConstraintViolationException::from($e);
43:
44: } else {
45: return Nette\Database\DriverException::from($e);
46: }
47: }
48:
49:
50:
51:
52:
53: 54: 55:
56: public function delimite($name)
57: {
58:
59: return '"' . str_replace('"', '""', $name) . '"';
60: }
61:
62:
63: 64: 65:
66: public function formatBool($value)
67: {
68: return $value ? '1' : '0';
69: }
70:
71:
72: 73: 74:
75: public function formatDateTime( $value)
76: {
77: return $value->format($this->fmtDateTime);
78: }
79:
80:
81: 82: 83:
84: public function formatDateInterval(\DateInterval $value)
85: {
86: throw new Nette\NotSupportedException;
87: }
88:
89:
90: 91: 92:
93: public function formatLike($value, $pos)
94: {
95: throw new Nette\NotImplementedException;
96: }
97:
98:
99: 100: 101:
102: public function applyLimit(& $sql, $limit, $offset)
103: {
104: if ($offset > 0) {
105:
106: $sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t '
107: . ($limit >= 0 ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '')
108: . ') WHERE "__rnum" > '. (int) $offset;
109:
110: } elseif ($limit >= 0) {
111: $sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
112: }
113: }
114:
115:
116: 117: 118:
119: public function normalizeRow($row)
120: {
121: return $row;
122: }
123:
124:
125:
126:
127:
128: 129: 130:
131: public function getTables()
132: {
133: $tables = array();
134: foreach ($this->connection->query('SELECT * FROM cat') as $row) {
135: if ($row[1] === 'TABLE' || $row[1] === 'VIEW') {
136: $tables[] = array(
137: 'name' => $row[0],
138: 'view' => $row[1] === 'VIEW',
139: );
140: }
141: }
142: return $tables;
143: }
144:
145:
146: 147: 148:
149: public function getColumns($table)
150: {
151: throw new Nette\NotImplementedException;
152: }
153:
154:
155: 156: 157:
158: public function getIndexes($table)
159: {
160: throw new Nette\NotImplementedException;
161: }
162:
163:
164: 165: 166:
167: public function getForeignKeys($table)
168: {
169: throw new Nette\NotImplementedException;
170: }
171:
172:
173: 174: 175:
176: public function getColumnTypes(\PDOStatement $statement)
177: {
178: return Nette\Database\Helpers::detectTypes($statement);
179: }
180:
181:
182: 183: 184: 185:
186: public function isSupported($item)
187: {
188: return $item === self::SUPPORT_SEQUENCE || $item === self::SUPPORT_SUBSELECT;
189: }
190:
191: }
192: