Skip to content

Commit ef95576

Browse files
committed
Fixed statements INSERT and REPLACE + options.
1 parent 457d094 commit ef95576

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

‎src/Statements/InsertStatement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class InsertStatement extends Statement
110110
*/
111111
public function build()
112112
{
113-
$ret = 'INSERT ' . $this->options
114-
. 'INTO ' . $this->into;
113+
$ret = 'INSERT ' . $this->options;
114+
$ret = trim($ret) . ' INTO ' . $this->into;
115115

116116
if (! is_null($this->values) && count($this->values) > 0) {
117117
$ret .= ' VALUES ' . Array2d::build($this->values);

‎src/Statements/ReplaceStatement.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ class ReplaceStatement extends Statement
8787
*/
8888
public function build()
8989
{
90-
$ret = 'REPLACE ' . $this->options . 'INTO ' . $this->into;
90+
$ret = 'REPLACE ' . $this->options;
91+
$ret = trim($ret) . ' INTO ' . $this->into;
9192

9293
if (! is_null($this->values) && count($this->values) > 0) {
9394
$ret .= ' VALUES ' . Array2d::build($this->values);

‎tests/Builder/InsertStatementTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,16 @@ public function testBuilder()
6363
'INSERT INTO tbl SELECT * FROM bar ON DUPLICATE KEY UPDATE baz = 1',
6464
$stmt->build()
6565
);
66+
67+
/* Assertion 6 */
68+
/* INSERT [OPTIONS] INTO ... */
69+
$parser = new Parser(
70+
'INSERT DELAYED IGNORE INTO tbl SELECT * FROM bar'
71+
);
72+
$stmt = $parser->statements[0];
73+
$this->assertEquals(
74+
'INSERT DELAYED IGNORE INTO tbl SELECT * FROM bar',
75+
$stmt->build()
76+
);
6677
}
6778
}

‎tests/Builder/ReplaceStatementTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,16 @@ public function testBuilderSelect()
4343
$stmt->build()
4444
);
4545
}
46+
47+
public function testBuilderSelectDelayed()
48+
{
49+
$parser = new Parser(
50+
'REPLACE DELAYED INTO tbl(col1, col2, col3) SELECT col1, col2, col3 FROM tbl2'
51+
);
52+
$stmt = $parser->statements[0];
53+
$this->assertEquals(
54+
'REPLACE DELAYED INTO tbl(`col1`, `col2`, `col3`) SELECT col1, col2, col3 FROM tbl2',
55+
$stmt->build()
56+
);
57+
}
4658
}

0 commit comments

Comments
 (0)