1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Adrian Dumitru |
5
|
|
|
* Date: 6/27/2017 |
6
|
|
|
* Time: 1:51 PM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Qpdb\QueryBuilder\Statements; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use Qpdb\PdoWrapper\PdoWrapperService; |
13
|
|
|
use Qpdb\QueryBuilder\Dependencies\QueryStructure; |
14
|
|
|
use Qpdb\QueryBuilder\QueryBuild; |
15
|
|
|
use Qpdb\QueryBuilder\Traits\DefaultPriority; |
16
|
|
|
use Qpdb\QueryBuilder\Traits\HighPriority; |
17
|
|
|
use Qpdb\QueryBuilder\Traits\Ignore; |
18
|
|
|
use Qpdb\QueryBuilder\Traits\LowPriority; |
19
|
|
|
use Qpdb\QueryBuilder\Traits\Replacement; |
20
|
|
|
use Qpdb\QueryBuilder\Traits\SetFields; |
21
|
|
|
use Qpdb\QueryBuilder\Traits\Utilities; |
22
|
|
|
|
23
|
|
|
class QueryInsert extends QueryStatement implements QueryStatementInterface |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
use Replacement, SetFields, Ignore, DefaultPriority, LowPriority, HighPriority, Utilities; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $statement = self::QUERY_STATEMENT_INSERT; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* QueryInsert constructor. |
36
|
|
|
* @param QueryBuild $queryBuild |
37
|
|
|
* @param string $table |
38
|
|
|
* @throws \Qpdb\QueryBuilder\Dependencies\QueryException |
39
|
|
|
*/ |
40
|
|
|
public function __construct( QueryBuild $queryBuild, $table = null ) |
41
|
|
|
{ |
42
|
|
|
parent::__construct( $queryBuild, $table ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return QueryInsertMultiple |
47
|
|
|
* @throws \Qpdb\QueryBuilder\Dependencies\QueryException |
48
|
|
|
*/ |
49
|
|
|
public function multiple() |
50
|
|
|
{ |
51
|
|
|
return new QueryInsertMultiple( $this->queryBuild, $this->queryStructure->getElement( QueryStructure::TABLE ) ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param bool|int $replacement |
56
|
|
|
* @return mixed|string |
57
|
|
|
*/ |
58
|
|
|
public function getSyntax( $replacement = self::REPLACEMENT_NONE ) |
59
|
|
|
{ |
60
|
|
|
$syntax = array(); |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Explain |
64
|
|
|
*/ |
65
|
|
|
$syntax[] = $this->getExplainSyntax(); |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* UPDATE statement |
69
|
|
|
*/ |
70
|
|
|
$syntax[] = $this->statement; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* PRIORITY |
74
|
|
|
*/ |
75
|
|
|
$syntax[] = $this->queryStructure->getElement( QueryStructure::PRIORITY ); |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* IGNORE clause |
79
|
|
|
*/ |
80
|
|
|
$syntax[] = $this->queryStructure->getElement( QueryStructure::IGNORE ) ? 'IGNORE' : ''; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* INTO table |
84
|
|
|
*/ |
85
|
|
|
$syntax[] = 'INTO ' . $this->queryStructure->getElement( QueryStructure::TABLE ); |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* FIELDS update |
89
|
|
|
*/ |
90
|
|
|
$syntax[] = $this->getSettingFieldsSyntax(); |
91
|
|
|
|
92
|
|
|
$syntax = implode( ' ', $syntax ); |
93
|
|
|
|
94
|
|
|
return $this->getSyntaxReplace( $syntax, $replacement ); |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return bool|mixed|\PDOStatement |
100
|
|
|
*/ |
101
|
|
|
public function execute() { |
102
|
|
|
return PdoWrapperService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS))->rowCount(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
} |