|
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; |
|
8
|
|
|
|
|
9
|
|
|
use eZ\Publish\Core\Persistence\Database\InsertQuery; |
|
10
|
|
|
use eZ\Publish\Core\Persistence\Database\QueryException; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class InsertDoctrineQuery. |
|
14
|
|
|
* |
|
15
|
|
|
* @deprecated Since 6.13, please use Doctrine DBAL instead (@ezpublish.persistence.connection) |
|
16
|
|
|
* it provides richer and more powerful DB abstraction which is also easier to use. |
|
17
|
|
|
*/ |
|
18
|
|
|
class InsertDoctrineQuery extends AbstractDoctrineQuery implements InsertQuery |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
/** @var string */ |
|
21
|
|
|
private $table; |
|
22
|
|
|
|
|
23
|
|
|
/** @var array */ |
|
24
|
|
|
private $values = []; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Opens the query and sets the target table to $table. |
|
28
|
|
|
* |
|
29
|
|
|
* insertInto() returns a pointer to $this. |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $table |
|
32
|
|
|
* |
|
33
|
|
|
* @return \eZ\Publish\Core\Persistence\Database\InsertQuery |
|
34
|
|
|
*/ |
|
35
|
|
|
public function insertInto($table) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->table = $table; |
|
38
|
|
|
|
|
39
|
|
|
return $this; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The insert query will set the column $column to the value $expression. |
|
44
|
|
|
* |
|
45
|
|
|
* set() returns a pointer to $this. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $column |
|
48
|
|
|
* @param string $expression |
|
49
|
|
|
* |
|
50
|
|
|
* @return \eZ\Publish\Core\Persistence\Database\InsertQuery |
|
51
|
|
|
*/ |
|
52
|
|
|
public function set($column, $expression) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->values[$column] = $expression; |
|
55
|
|
|
|
|
56
|
|
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getQuery() |
|
63
|
|
|
{ |
|
64
|
|
|
if (strlen($this->table) === 0) { |
|
65
|
|
|
throw new QueryException('Missing table name'); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if (count($this->values) === 0) { |
|
69
|
|
|
throw new QueryException('Missing values'); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return 'INSERT INTO ' . $this->table |
|
73
|
|
|
. ' (' . implode(', ', array_keys($this->values)) . ')' |
|
74
|
|
|
. ' VALUES (' . implode(', ', $this->values) . ')'; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
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.