Skip to content

Commit

Permalink
Fixed statements INSERT and REPLACE + options.
Browse files Browse the repository at this point in the history
  • Loading branch information
pszalko committed Feb 15, 2019
1 parent 457d094 commit ef95576
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Statements/InsertStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ class InsertStatement extends Statement
*/
public function build()
{
$ret = 'INSERT ' . $this->options
. 'INTO ' . $this->into;
$ret = 'INSERT ' . $this->options;
$ret = trim($ret) . ' INTO ' . $this->into;

if (! is_null($this->values) && count($this->values) > 0) {
$ret .= ' VALUES ' . Array2d::build($this->values);
Expand Down
3 changes: 2 additions & 1 deletion src/Statements/ReplaceStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class ReplaceStatement extends Statement
*/
public function build()
{
$ret = 'REPLACE ' . $this->options . 'INTO ' . $this->into;
$ret = 'REPLACE ' . $this->options;
$ret = trim($ret) . ' INTO ' . $this->into;

if (! is_null($this->values) && count($this->values) > 0) {
$ret .= ' VALUES ' . Array2d::build($this->values);
Expand Down
11 changes: 11 additions & 0 deletions tests/Builder/InsertStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,16 @@ public function testBuilder()
'INSERT INTO tbl SELECT * FROM bar ON DUPLICATE KEY UPDATE baz = 1',
$stmt->build()
);

/* Assertion 6 */
/* INSERT [OPTIONS] INTO ... */
$parser = new Parser(
'INSERT DELAYED IGNORE INTO tbl SELECT * FROM bar'
);
$stmt = $parser->statements[0];
$this->assertEquals(
'INSERT DELAYED IGNORE INTO tbl SELECT * FROM bar',
$stmt->build()
);
}
}
12 changes: 12 additions & 0 deletions tests/Builder/ReplaceStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,16 @@ public function testBuilderSelect()
$stmt->build()
);
}

public function testBuilderSelectDelayed()
{
$parser = new Parser(
'REPLACE DELAYED INTO tbl(col1, col2, col3) SELECT col1, col2, col3 FROM tbl2'
);
$stmt = $parser->statements[0];
$this->assertEquals(
'REPLACE DELAYED INTO tbl(`col1`, `col2`, `col3`) SELECT col1, col2, col3 FROM tbl2',
$stmt->build()
);
}
}

0 comments on commit ef95576

Please sign in to comment.