1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Adrian Dumitru |
5
|
|
|
* Date: 7/24/2017 |
6
|
|
|
* Time: 6:34 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\InsertMultiple; |
19
|
|
|
use Qpdb\QueryBuilder\Traits\LowPriority; |
20
|
|
|
use Qpdb\QueryBuilder\Traits\Replacement; |
21
|
|
|
use Qpdb\QueryBuilder\Traits\Utilities; |
22
|
|
|
|
23
|
|
|
class QueryInsertMultiple extends QueryStatement implements QueryStatementInterface |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
use InsertMultiple, Replacement, 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
|
|
|
$this->queryStructure->setElement( QueryStructure::FIELDS, array() ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getSyntax( $replacement = self::REPLACEMENT_NONE ) |
47
|
|
|
{ |
48
|
|
|
$syntax = array(); |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Explain |
52
|
|
|
*/ |
53
|
|
|
$syntax[] = $this->getExplainSyntax(); |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* UPDATE statement |
57
|
|
|
*/ |
58
|
|
|
$syntax[] = $this->statement; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* PRIORITY |
62
|
|
|
*/ |
63
|
|
|
$syntax[] = $this->queryStructure->getElement( QueryStructure::PRIORITY ); |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* IGNORE clause |
67
|
|
|
*/ |
68
|
|
|
$syntax[] = $this->queryStructure->getElement( QueryStructure::IGNORE ) ? 'IGNORE' : ''; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* INTO table |
72
|
|
|
*/ |
73
|
|
|
$syntax[] = 'INTO ' . $this->queryStructure->getElement( QueryStructure::TABLE ); |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* FIELDS update |
77
|
|
|
*/ |
78
|
|
|
$syntax[] = $this->getInsertMultipleRowsSyntax(); |
79
|
|
|
|
80
|
|
|
$syntax = implode( ' ', $syntax ); |
81
|
|
|
|
82
|
|
|
return $this->getSyntaxReplace( $syntax, $replacement ); |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function execute() |
87
|
|
|
{ |
88
|
|
|
return PdoWrapperService::getInstance()->query( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) )->rowCount(); |
89
|
|
|
} |
90
|
|
|
} |