| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Illuminate\Database;
|
|
|
4 |
|
|
|
5 |
use Illuminate\Database\PDO\SQLiteDriver;
|
|
|
6 |
use Illuminate\Database\Query\Grammars\SQLiteGrammar as QueryGrammar;
|
|
|
7 |
use Illuminate\Database\Query\Processors\SQLiteProcessor;
|
|
|
8 |
use Illuminate\Database\Schema\Grammars\SQLiteGrammar as SchemaGrammar;
|
|
|
9 |
use Illuminate\Database\Schema\SQLiteBuilder;
|
|
|
10 |
use Illuminate\Database\Schema\SqliteSchemaState;
|
|
|
11 |
use Illuminate\Filesystem\Filesystem;
|
|
|
12 |
|
|
|
13 |
class SQLiteConnection extends Connection
|
|
|
14 |
{
|
|
|
15 |
/**
|
|
|
16 |
* Create a new database connection instance.
|
|
|
17 |
*
|
|
|
18 |
* @param \PDO|\Closure $pdo
|
|
|
19 |
* @param string $database
|
|
|
20 |
* @param string $tablePrefix
|
|
|
21 |
* @param array $config
|
|
|
22 |
* @return void
|
|
|
23 |
*/
|
|
|
24 |
public function __construct($pdo, $database = '', $tablePrefix = '', array $config = [])
|
|
|
25 |
{
|
|
|
26 |
parent::__construct($pdo, $database, $tablePrefix, $config);
|
|
|
27 |
|
|
|
28 |
$enableForeignKeyConstraints = $this->getForeignKeyConstraintsConfigurationValue();
|
|
|
29 |
|
|
|
30 |
if ($enableForeignKeyConstraints === null) {
|
|
|
31 |
return;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
$enableForeignKeyConstraints
|
|
|
35 |
? $this->getSchemaBuilder()->enableForeignKeyConstraints()
|
|
|
36 |
: $this->getSchemaBuilder()->disableForeignKeyConstraints();
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Get the default query grammar instance.
|
|
|
41 |
*
|
|
|
42 |
* @return \Illuminate\Database\Query\Grammars\SQLiteGrammar
|
|
|
43 |
*/
|
|
|
44 |
protected function getDefaultQueryGrammar()
|
|
|
45 |
{
|
|
|
46 |
return $this->withTablePrefix(new QueryGrammar);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Get a schema builder instance for the connection.
|
|
|
51 |
*
|
|
|
52 |
* @return \Illuminate\Database\Schema\SQLiteBuilder
|
|
|
53 |
*/
|
|
|
54 |
public function getSchemaBuilder()
|
|
|
55 |
{
|
|
|
56 |
if (is_null($this->schemaGrammar)) {
|
|
|
57 |
$this->useDefaultSchemaGrammar();
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
return new SQLiteBuilder($this);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
* Get the default schema grammar instance.
|
|
|
65 |
*
|
|
|
66 |
* @return \Illuminate\Database\Schema\Grammars\SQLiteGrammar
|
|
|
67 |
*/
|
|
|
68 |
protected function getDefaultSchemaGrammar()
|
|
|
69 |
{
|
|
|
70 |
return $this->withTablePrefix(new SchemaGrammar);
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
* Get the schema state for the connection.
|
|
|
75 |
*
|
|
|
76 |
* @param \Illuminate\Filesystem\Filesystem|null $files
|
|
|
77 |
* @param callable|null $processFactory
|
|
|
78 |
*
|
|
|
79 |
* @throws \RuntimeException
|
|
|
80 |
*/
|
|
|
81 |
public function getSchemaState(Filesystem $files = null, callable $processFactory = null)
|
|
|
82 |
{
|
|
|
83 |
return new SqliteSchemaState($this, $files, $processFactory);
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
/**
|
|
|
87 |
* Get the default post processor instance.
|
|
|
88 |
*
|
|
|
89 |
* @return \Illuminate\Database\Query\Processors\SQLiteProcessor
|
|
|
90 |
*/
|
|
|
91 |
protected function getDefaultPostProcessor()
|
|
|
92 |
{
|
|
|
93 |
return new SQLiteProcessor;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
* Get the Doctrine DBAL driver.
|
|
|
98 |
*
|
|
|
99 |
* @return \Illuminate\Database\PDO\SQLiteDriver
|
|
|
100 |
*/
|
|
|
101 |
protected function getDoctrineDriver()
|
|
|
102 |
{
|
|
|
103 |
return new SQLiteDriver;
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
/**
|
|
|
107 |
* Get the database connection foreign key constraints configuration option.
|
|
|
108 |
*
|
|
|
109 |
* @return bool|null
|
|
|
110 |
*/
|
|
|
111 |
protected function getForeignKeyConstraintsConfigurationValue()
|
|
|
112 |
{
|
|
|
113 |
return $this->getConfig('foreign_key_constraints');
|
|
|
114 |
}
|
|
|
115 |
}
|