GeezerVison is showing github.com — Fixed statements INSERT and REPLACE + options. · phpmyadmin/sql-parser@ef95576
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/Statements/InsertStatement.php +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -110,8 +110,8 @@ class InsertStatement extends Statement |
110 | 110 | */ |
111 | 111 | public function build() |
112 | 112 | { |
113 | | - $ret = 'INSERT ' . $this->options |
114 | | - . 'INTO ' . $this->into; |
| 113 | + $ret = 'INSERT ' . $this->options; |
| 114 | + $ret = trim($ret) . ' INTO ' . $this->into; |
115 | 115 |
|
116 | 116 | if (! is_null($this->values) && count($this->values) > 0) { |
117 | 117 | $ret .= ' VALUES ' . Array2d::build($this->values); |
|
Collapse file
Copy file name to clipboardExpand all lines: src/Statements/ReplaceStatement.php +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -87,7 +87,8 @@ class ReplaceStatement extends Statement |
87 | 87 | */ |
88 | 88 | public function build() |
89 | 89 | { |
90 | | - $ret = 'REPLACE ' . $this->options . 'INTO ' . $this->into; |
| 90 | + $ret = 'REPLACE ' . $this->options; |
| 91 | + $ret = trim($ret) . ' INTO ' . $this->into; |
91 | 92 |
|
92 | 93 | if (! is_null($this->values) && count($this->values) > 0) { |
93 | 94 | $ret .= ' VALUES ' . Array2d::build($this->values); |
|
Collapse file
Copy file name to clipboardExpand all lines: tests/Builder/InsertStatementTest.php +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -63,5 +63,16 @@ public function testBuilder() |
63 | 63 | 'INSERT INTO tbl SELECT * FROM bar ON DUPLICATE KEY UPDATE baz = 1', |
64 | 64 | $stmt->build() |
65 | 65 | ); |
| 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 | + ); |
66 | 77 | } |
67 | 78 | } |
Collapse file
Copy file name to clipboardExpand all lines: tests/Builder/ReplaceStatementTest.php +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -43,4 +43,16 @@ public function testBuilderSelect() |
43 | 43 | $stmt->build() |
44 | 44 | ); |
45 | 45 | } |
| 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 | + } |
46 | 58 | } |