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