/
connect.inc.php
55 lines (41 loc) 路 1.47 KB
/
connect.inc.php
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
<?php
/**
* Test: Nette\Database test bootstrap.
*/
declare(strict_types=1);
require __DIR__ . '/../bootstrap.php';
$options = Tester\Environment::loadData() + ['user' => null, 'password' => null];
try {
$connection = new Nette\Database\Connection($options['dsn'], $options['user'], $options['password']);
} catch (Nette\Database\ConnectionException $e) {
Tester\Environment::skip("Connection to '$options[dsn]' failed. Reason: " . $e->getMessage());
}
if (!str_contains($options['dsn'], 'sqlite::memory:')) {
Tester\Environment::lock($options['dsn'], TEMP_DIR);
}
$driverName = $connection->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
$cacheMemoryStorage = new Nette\Caching\Storages\MemoryStorage;
$structure = new Nette\Database\Structure($connection, $cacheMemoryStorage);
$conventions = new Nette\Database\Conventions\DiscoveredConventions($structure);
$explorer = new Nette\Database\Explorer($connection, $structure, $conventions, $cacheMemoryStorage);
echo "Driver: $driverName\n";
/** Replaces [] with driver-specific quotes */
function reformat($s): string
{
global $driverName;
if (is_array($s)) {
if (isset($s[$driverName])) {
return $s[$driverName];
}
$s = $s[0];
}
if ($driverName === 'mysql') {
return strtr($s, '[]', '``');
} elseif ($driverName === 'pgsql') {
return strtr($s, '[]', '""');
} elseif ($driverName === 'sqlsrv' || $driverName === 'sqlite') {
return $s;
} else {
trigger_error("Unsupported driver $driverName", E_USER_WARNING);
}
}