GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • src/Statements
    • InsertStatement.php
    • ReplaceStatement.php
  • tests/Builder
    • InsertStatementTest.php
    • ReplaceStatementTest.php
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/Statements/InsertStatement.php‎

Copy file name to clipboardExpand all lines: src/Statements/InsertStatement.php
+2-2Lines 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);
Collapse file

‎src/Statements/ReplaceStatement.php‎

Copy file name to clipboardExpand all lines: src/Statements/ReplaceStatement.php
+2-1Lines 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);
Collapse file

‎tests/Builder/InsertStatementTest.php‎

Copy file name to clipboardExpand all lines: tests/Builder/InsertStatementTest.php
+11Lines 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
}
Collapse file

‎tests/Builder/ReplaceStatementTest.php‎

Copy file name to clipboardExpand all lines: tests/Builder/ReplaceStatementTest.php
+12Lines 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 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.