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 ($limit < 0 || $offset < 0) {
105: throw new Nette\InvalidArgumentException('Negative offset or limit.');
106:
107: } elseif ($offset) {
108:
109: $sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t '
110: . ($limit !== NULL ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '')
111: . ') WHERE "__rnum" > '. (int) $offset;
112:
113: } elseif ($limit !== NULL) {
114: $sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
115: }
116: }
117:
118:
119: 120: 121:
122: public function normalizeRow($row)
123: {
124: return $row;
125: }
126:
127:
128:
129:
130:
131: 132: 133:
134: public function getTables()
135: {
136: $tables = array();
137: foreach ($this->connection->query('SELECT * FROM cat') as $row) {
138: if ($row[1] === 'TABLE' || $row[1] === 'VIEW') {
139: $tables[] = array(
140: 'name' => $row[0],
141: 'view' => $row[1] === 'VIEW',
142: );
143: }
144: }
145: return $tables;
146: }
147:
148:
149: 150: 151:
152: public function getColumns($table)
153: {
154: throw new Nette\NotImplementedException;
155: }
156:
157:
158: 159: 160:
161: public function getIndexes($table)
162: {
163: throw new Nette\NotImplementedException;
164: }
165:
166:
167: 168: 169:
170: public function getForeignKeys($table)
171: {
172: throw new Nette\NotImplementedException;
173: }
174:
175:
176: 177: 178:
179: public function getColumnTypes(\PDOStatement $statement)
180: {
181: return Nette\Database\Helpers::detectTypes($statement);
182: }
183:
184:
185: 186: 187: 188:
189: public function isSupported($item)
190: {
191: return $item === self::SUPPORT_SEQUENCE || $item === self::SUPPORT_SUBSELECT;
192: }
193:
194: }
195: