-
-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathOdbcDriver.php
More file actions
122 lines (83 loc) · 2.58 KB
/
OdbcDriver.php
File metadata and controls
122 lines (83 loc) · 2.58 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
<?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 ODBC database driver.
*/
class OdbcDriver implements Nette\Database\ISupplementalDriver
{
use Nette\SmartObject;
public function initialize(Nette\Database\Connection $connection, array $options): void
{
}
public function convertException(\PDOException $e): Nette\Database\DriverException
{
return Nette\Database\DriverException::from($e);
}
/********************* SQL ****************d*g**/
public function delimite(string $name): string
{
return '[' . str_replace(['[', ']'], ['[[', ']]'], $name) . ']';
}
public function undelimite(string $name): string
{
$name = preg_replace('#(?<!\])\](?!\])#', '', preg_replace('#(?<!\[)\[(?!\[)#', '', $name));
return str_replace(['[[', ']]'], ['[', ']'], $name);
}
public function formatDateTime(\DateTimeInterface $value): string
{
return $value->format('#m/d/Y H:i:s#');
}
public function formatDateInterval(\DateInterval $value): string
{
throw new Nette\NotSupportedException;
}
public function formatLike(string $value, int $pos): string
{
$value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']);
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
}
public function applyLimit(string &$sql, ?int $limit, ?int $offset): void
{
if ($offset) {
throw new Nette\NotSupportedException('Offset is not supported by this database.');
} elseif ($limit < 0) {
throw new Nette\InvalidArgumentException('Negative offset or limit.');
} elseif ($limit !== null) {
$sql = preg_replace('#^\s*(SELECT(\s+DISTINCT|\s+ALL)?|UPDATE|DELETE)#i', '$0 TOP ' . $limit, $sql, 1, $count);
if (!$count) {
throw new Nette\InvalidArgumentException('SQL query must begin with SELECT, UPDATE or DELETE command.');
}
}
}
/********************* reflection ****************d*g**/
public function getTables(): array
{
throw new Nette\NotImplementedException;
}
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_SUBSELECT;
}
}