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: public function delimite($name)
56: {
57:
58: return '"' . str_replace('"', '""', $name) . '"';
59: }
60:
61:
62: public function formatBool($value)
63: {
64: return $value ? '1' : '0';
65: }
66:
67:
68: public function formatDateTime( $value)
69: {
70: return $value->format($this->fmtDateTime);
71: }
72:
73:
74: public function formatDateInterval(\DateInterval $value)
75: {
76: throw new Nette\NotSupportedException;
77: }
78:
79:
80: public function formatLike($value, $pos)
81: {
82: throw new Nette\NotImplementedException;
83: }
84:
85:
86: public function applyLimit(&$sql, $limit, $offset)
87: {
88: if ($limit < 0 || $offset < 0) {
89: throw new Nette\InvalidArgumentException('Negative offset or limit.');
90:
91: } elseif ($offset) {
92:
93: $sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t '
94: . ($limit !== null ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '')
95: . ') WHERE "__rnum" > ' . (int) $offset;
96:
97: } elseif ($limit !== null) {
98: $sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
99: }
100: }
101:
102:
103: public function normalizeRow($row)
104: {
105: return $row;
106: }
107:
108:
109:
110:
111:
112: public function getTables()
113: {
114: $tables = [];
115: foreach ($this->connection->query('SELECT * FROM cat') as $row) {
116: if ($row[1] === 'TABLE' || $row[1] === 'VIEW') {
117: $tables[] = [
118: 'name' => $row[0],
119: 'view' => $row[1] === 'VIEW',
120: ];
121: }
122: }
123: return $tables;
124: }
125:
126:
127: public function getColumns($table)
128: {
129: throw new Nette\NotImplementedException;
130: }
131:
132:
133: public function getIndexes($table)
134: {
135: throw new Nette\NotImplementedException;
136: }
137:
138:
139: public function getForeignKeys($table)
140: {
141: throw new Nette\NotImplementedException;
142: }
143:
144:
145: public function getColumnTypes(\PDOStatement $statement)
146: {
147: return [];
148: }
149:
150:
151: public function isSupported($item)
152: {
153: return $item === self::SUPPORT_SEQUENCE || $item === self::SUPPORT_SUBSELECT;
154: }
155: }
156: