|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace eZ\Publish\Core\Persistence\Doctrine\ConnectionHandler; |
|
8
|
|
|
|
|
9
|
|
|
use eZ\Publish\Core\Persistence\Doctrine\ConnectionHandler; |
|
10
|
|
|
|
|
11
|
|
|
class SqliteConnectionHandler extends ConnectionHandler |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
protected $lastInsertedIds = []; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Retrieve the last auto incremet or sequence id. |
|
17
|
|
|
* |
|
18
|
|
|
* @param string $sequenceName |
|
19
|
|
|
* |
|
20
|
|
|
* @return string |
|
21
|
|
|
*/ |
|
22
|
|
|
public function lastInsertId($sequenceName = null) |
|
23
|
|
|
{ |
|
24
|
|
|
if (isset($this->lastInsertedIds[$sequenceName])) { |
|
25
|
|
|
$lastInsertId = $this->lastInsertedIds[$sequenceName]; |
|
26
|
|
|
unset($this->lastInsertedIds[$sequenceName]); |
|
27
|
|
|
|
|
28
|
|
|
return $lastInsertId; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
return $this->connection->lastInsertId($sequenceName); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Get auto increment value. |
|
36
|
|
|
* |
|
37
|
|
|
* Returns the value used for autoincrement tables. Usually this will just |
|
38
|
|
|
* be null. In case for sequence based RDBMS this method can return a |
|
39
|
|
|
* proper value for the given column. |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $table |
|
42
|
|
|
* @param string $column |
|
43
|
|
|
* |
|
44
|
|
|
* @return mixed |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getAutoIncrementValue($table, $column) |
|
47
|
|
|
{ |
|
48
|
|
View Code Duplication |
if (($table === 'ezcontentobject_attribute') && ($column === 'id')) { |
|
|
|
|
|
|
49
|
|
|
// This is a @HACK -- since this table has a multi-column key with |
|
50
|
|
|
// auto-increment, which is not easy to simulate in SQLite. This |
|
51
|
|
|
// solves it for now. |
|
52
|
|
|
$q = $this->createSelectQuery(); |
|
53
|
|
|
$q->select($q->expr->max('id'))->from('ezcontentobject_attribute'); |
|
54
|
|
|
$statement = $q->prepare(); |
|
55
|
|
|
$statement->execute(); |
|
56
|
|
|
|
|
57
|
|
|
$this->lastInsertedIds['ezcontentobject_attribute.id'] = (int)$statement->fetchColumn() + 1; |
|
58
|
|
|
|
|
59
|
|
|
return $this->lastInsertedIds['ezcontentobject_attribute.id']; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
View Code Duplication |
if (($table === 'ezcontentclass') && ($column === 'id')) { |
|
|
|
|
|
|
63
|
|
|
// This is a @HACK -- since this table has a multi-column key with |
|
64
|
|
|
// auto-increment, which is not easy to simulate in SQLite. This |
|
65
|
|
|
// solves it for now. |
|
66
|
|
|
$q = $this->createSelectQuery(); |
|
67
|
|
|
$q->select($q->expr->max('id'))->from('ezcontentclass'); |
|
68
|
|
|
$statement = $q->prepare(); |
|
69
|
|
|
$statement->execute(); |
|
70
|
|
|
|
|
71
|
|
|
$this->lastInsertedIds['ezcontentclass.id'] = (int)$statement->fetchColumn() + 1; |
|
72
|
|
|
|
|
73
|
|
|
return $this->lastInsertedIds['ezcontentclass.id']; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
View Code Duplication |
if (($table === 'ezcontentclass_attribute') && ($column === 'id')) { |
|
|
|
|
|
|
77
|
|
|
// This is a @HACK -- since this table has a multi-column key with |
|
78
|
|
|
// auto-increment, which is not easy to simulate in SQLite. This |
|
79
|
|
|
// solves it for now. |
|
80
|
|
|
$q = $this->createSelectQuery(); |
|
81
|
|
|
$q->select($q->expr->max('id'))->from('ezcontentclass_attribute'); |
|
82
|
|
|
$statement = $q->prepare(); |
|
83
|
|
|
$statement->execute(); |
|
84
|
|
|
|
|
85
|
|
|
$this->lastInsertedIds['ezcontentclass_attribute.id'] = (int)$statement->fetchColumn() + 1; |
|
86
|
|
|
|
|
87
|
|
|
return $this->lastInsertedIds['ezcontentclass_attribute.id']; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return 'NULL'; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Returns the name of the affected sequence. |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $table |
|
97
|
|
|
* @param string $column |
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getSequenceName($table, $column) |
|
102
|
|
|
{ |
|
103
|
|
|
if (($table === 'ezcontentobject_attribute') && ($column === 'id')) { |
|
104
|
|
|
return "{$table}.{$column}"; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
if (($table === 'ezcontentclass') && ($column === 'id')) { |
|
108
|
|
|
return "{$table}.{$column}"; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
if (($table === 'ezcontentclass_attribute') && ($column === 'id')) { |
|
112
|
|
|
return "{$table}.{$column}"; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
return null; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.