1 | <?php |
||
11 | class Sqlite extends AbstractType |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * (non-PHPdoc) |
||
16 | * |
||
17 | * @see \Nkey\Caribu\Type\IType::getDsn() |
||
18 | */ |
||
19 | 23 | public function getDsn(): string |
|
20 | { |
||
21 | 23 | return "sqlite:{file}"; |
|
22 | } |
||
23 | |||
24 | /** |
||
25 | * (non-PHPdoc) |
||
26 | * |
||
27 | * @see \Nkey\Caribu\Type\IType::getPrimaryKeyColumn() |
||
28 | */ |
||
29 | 3 | public function getPrimaryKeyColumn(string $table, \Nkey\Caribu\Orm\Orm $orm): string |
|
30 | { |
||
31 | 3 | $query = "PRAGMA TABLE_INFO({table})"; |
|
32 | |||
33 | 3 | $sql = $this->interp($query, array( |
|
34 | 3 | 'table' => $table |
|
35 | )); |
||
36 | |||
37 | try { |
||
38 | 3 | $stmt = $orm->getConnection()->query($sql); |
|
39 | 3 | $stmt->setFetchMode(\PDO::FETCH_ASSOC); |
|
40 | 3 | while ($result = $stmt->fetch()) { |
|
41 | 2 | $name = ''; |
|
42 | 2 | foreach ($result as $identifier => $value) { |
|
43 | 2 | if ($identifier == 'name') { |
|
44 | 2 | $name = $value; |
|
45 | } |
||
46 | 2 | if ($identifier == 'pk' && $name) { |
|
47 | 2 | return $name; |
|
48 | } |
||
49 | } |
||
50 | } |
||
51 | 1 | $stmt->closeCursor(); |
|
52 | } catch (\PDOException $exception) { |
||
53 | throw \Nkey\Caribu\Orm\OrmException::fromPrevious($exception); |
||
54 | } |
||
55 | |||
56 | 1 | return ""; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * (non-PHPdoc) |
||
61 | * |
||
62 | * @see \Nkey\Caribu\Type\IType::getDefaultPort() |
||
63 | */ |
||
64 | 23 | public function getDefaultPort(): int |
|
68 | |||
69 | /** |
||
70 | * (non-PHPdoc) |
||
71 | * |
||
72 | * @see \Nkey\Caribu\Type\IType::lock() |
||
73 | */ |
||
74 | 6 | public function lock(string $table, int $lockType, \Nkey\Caribu\Orm\Orm $orm) |
|
78 | |||
79 | /** |
||
80 | * (non-PHPdoc) |
||
81 | * |
||
82 | * @see \Nkey\Caribu\Type\IType::unlock() |
||
83 | */ |
||
84 | 7 | public function unlock(string $table, \Nkey\Caribu\Orm\Orm $orm) |
|
88 | |||
89 | /** |
||
90 | * (non-PHPdoc) |
||
91 | * |
||
92 | * @see \Nkey\Caribu\Type\IType::getEscapeSign() |
||
93 | */ |
||
94 | 22 | public function getEscapeSign(): string |
|
98 | |||
99 | /** |
||
100 | * (non-PHPdoc) |
||
101 | * |
||
102 | * @see \Nkey\Caribu\Type\AbstractType::getTypeQuery() |
||
103 | */ |
||
104 | 5 | protected function getTypeQuery(): string |
|
110 | |||
111 | /** |
||
112 | * (non-PHPdoc) |
||
113 | * |
||
114 | * @see \Nkey\Caribu\Type\AbstractType::mapType() |
||
115 | */ |
||
116 | 5 | protected function mapType(array $result): int |
|
133 | |||
134 | /** |
||
135 | * (non-PHPdoc) |
||
136 | * |
||
137 | * @see \Nkey\Caribu\Type\IType::getColumnType() |
||
138 | */ |
||
139 | 5 | public function getColumnType(string $table, string $columnName, \Nkey\Caribu\Orm\Orm $orm): int |
|
161 | |||
162 | /** |
||
163 | * (non-PHPdoc) |
||
164 | * |
||
165 | * @see \Nkey\Caribu\Type\IType::getSequenceNameForColumn() |
||
166 | */ |
||
167 | 4 | public function getSequenceNameForColumn(string $table, string $columnName, \Nkey\Caribu\Orm\Orm $orm): string |
|
171 | } |
||
172 |