-
-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathOciDriver.php
More file actions
152 lines (107 loc) · 3.37 KB
/
OciDriver.php
File metadata and controls
152 lines (107 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Database\Drivers;
use Nette;
/**
* Supplemental Oracle database driver.
*/
class OciDriver implements Nette\Database\ISupplementalDriver
{
use Nette\SmartObject;
/** @var Nette\Database\Connection */
private $connection;
/** @var string Datetime format */
private $fmtDateTime;
public function initialize(Nette\Database\Connection $connection, array $options): void
{
$this->connection = $connection;
$this->fmtDateTime = $options['formatDateTime'] ?? 'U';
}
public function convertException(\PDOException $e): Nette\Database\DriverException
{
$code = $e->errorInfo[1] ?? null;
if (in_array($code, [1, 2299, 38911], true)) {
return Nette\Database\UniqueConstraintViolationException::from($e);
} elseif (in_array($code, [1400], true)) {
return Nette\Database\NotNullConstraintViolationException::from($e);
} elseif (in_array($code, [2266, 2291, 2292], true)) {
return Nette\Database\ForeignKeyConstraintViolationException::from($e);
} else {
return Nette\Database\DriverException::from($e);
}
}
/********************* SQL ****************d*g**/
public function delimite(string $name): string
{
// @see http://download.oracle.com/docs/cd/B10500_01/server.920/a96540/sql_elements9a.htm
return '"' . str_replace('"', '""', $name) . '"';
}
public function undelimite(string $name): string
{
$name = preg_replace('#(?<!")"(?!")#', '', $name);
return str_replace('""', '"', $name);
}
public function formatDateTime(\DateTimeInterface $value): string
{
return $value->format($this->fmtDateTime);
}
public function formatDateInterval(\DateInterval $value): string
{
throw new Nette\NotSupportedException;
}
public function formatLike(string $value, int $pos): string
{
throw new Nette\NotImplementedException;
}
public function applyLimit(string &$sql, ?int $limit, ?int $offset): void
{
if ($limit < 0 || $offset < 0) {
throw new Nette\InvalidArgumentException('Negative offset or limit.');
} elseif ($offset) {
// see http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
$sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t '
. ($limit !== null ? 'WHERE ROWNUM <= ' . ($offset + $limit) : '')
. ') WHERE "__rnum" > ' . $offset;
} elseif ($limit !== null) {
$sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . $limit;
}
}
/********************* reflection ****************d*g**/
public function getTables(): array
{
$tables = [];
foreach ($this->connection->query('SELECT * FROM cat') as $row) {
if ($row[1] === 'TABLE' || $row[1] === 'VIEW') {
$tables[] = [
'name' => $row[0],
'view' => $row[1] === 'VIEW',
];
}
}
return $tables;
}
public function getColumns(string $table): array
{
throw new Nette\NotImplementedException;
}
public function getIndexes(string $table): array
{
throw new Nette\NotImplementedException;
}
public function getForeignKeys(string $table): array
{
throw new Nette\NotImplementedException;
}
public function getColumnTypes(\PDOStatement $statement): array
{
return [];
}
public function isSupported(string $item): bool
{
return $item === self::SUPPORT_SEQUENCE || $item === self::SUPPORT_SUBSELECT;
}
}