1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ___ _ _ |
5
|
|
|
* | _ \__ _| |_ __ _| |__ __ _ ___ ___ |
6
|
|
|
* | _/ _` | _/ _` | '_ \/ _` (_-</ -_) |
7
|
|
|
* |_| \__,_|\__\__,_|_.__/\__,_/__/\___| |
8
|
|
|
* |
9
|
|
|
* This file is part of Kristuff\Patabase. |
10
|
|
|
* (c) Kristuff <[email protected]> |
11
|
|
|
* |
12
|
|
|
* For the full copyright and license information, please view the LICENSE |
13
|
|
|
* file that was distributed with this source code. |
14
|
|
|
* |
15
|
|
|
* @version 1.0.1 |
16
|
|
|
* @copyright 2017-2022 Christophe Buliard |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Kristuff\Patabase\Driver\Sqlite; |
20
|
|
|
|
21
|
|
|
use Kristuff\Patabase; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class SqliteDatabase |
25
|
|
|
*/ |
26
|
|
|
class SqliteDatabase extends Patabase\Database |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Creates and returns an instance of SqliteDatabase using given filepath |
30
|
|
|
* |
31
|
|
|
* @access public |
32
|
|
|
* @static |
33
|
|
|
* @param string $filePath The full path to database. |
34
|
|
|
* |
35
|
|
|
* @return SqliteDatabase |
36
|
|
|
*/ |
37
|
|
|
public static function createInstance(string $filePath): SqliteDatabase |
38
|
|
|
{ |
39
|
|
|
$settings = array('driver' => 'sqlite', 'database' => $filePath); |
40
|
|
|
return new SqliteDatabase($settings); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Creates and returns an instance of 'in memory' SqliteDatabase |
45
|
|
|
* |
46
|
|
|
* @access public |
47
|
|
|
* @static |
48
|
|
|
* |
49
|
|
|
* @return SqliteDatabase |
50
|
|
|
*/ |
51
|
|
|
public static function createMemoryInstance(): SqliteDatabase |
52
|
|
|
{ |
53
|
|
|
$settings = array('driver' => 'sqlite', 'database' => ':memory:'); |
54
|
|
|
return new SqliteDatabase($settings); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get whether foreign keys are enabled or not |
59
|
|
|
* |
60
|
|
|
* https://www.sqlite.org/foreignkeys.html |
61
|
|
|
* Foreign key constraints are disabled by default (for backwards compatibility), so must be enabled separately for |
62
|
|
|
* each database connection. (Note, however, that future releases of SQLite might change so that foreign key constraints |
63
|
|
|
* enabled by default. Careful developers will not make any assumptions about whether or not foreign keys are enabled by |
64
|
|
|
* default but will instead enable or disable them as necessary.) The application can also use a PRAGMA foreign_keys statement |
65
|
|
|
* to determine if foreign keys are currently enabled. |
66
|
|
|
* |
67
|
|
|
* @access public |
68
|
|
|
* @return bool true if foreign keys are enabled, otherwise false |
69
|
|
|
*/ |
70
|
|
|
public function isForeignKeyEnabled(): bool |
71
|
|
|
{ |
72
|
|
|
return $this->driver->isForeignKeyEnabled(); |
73
|
|
|
} |
74
|
|
|
} |