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