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