GeezerVison is showing github.com — Changed implementation of build() methods to generate more consistent… · phpmyadmin/sql-parser@457d094
File treeExpand 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/Statement.php +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -173,12 +173,12 @@ public function build() | 173 | 173 |
| 174 | 174 | // Checking if the name of the clause should be added. | 175 | 175 | if ($type & 2) { | 176 | | - $query .= $name . ' '; | | 176 | + $query = trim($query) . ' ' . $name; | 177 | 177 | } | 178 | 178 |
| 179 | 179 | // Checking if the result of the builder should be added. | 180 | 180 | if ($type & 1) { | 181 | | - $query .= $class::build($this->$field) . ' '; | | 181 | + $query = trim($query) . ' ' . $class::build($this->$field); | 182 | 182 | } | 183 | 183 | } | 184 | 184 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/Statements/InsertStatement.php +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -111,7 +111,7 @@ class InsertStatement extends Statement | 111 | 111 | public function build() | 112 | 112 | { | 113 | 113 | $ret = 'INSERT ' . $this->options | 114 | | - . ' INTO ' . $this->into; | | 114 | + . '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 +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -87,7 +87,7 @@ 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 . 'INTO ' . $this->into; | 91 | 91 |
| 92 | 92 | if (! is_null($this->values) && count($this->values) > 0) { | 93 | 93 | $ret .= ' VALUES ' . Array2d::build($this->values); | |
Collapse file Copy file name to clipboardExpand all lines: tests/Builder/CreateStatementTest.php +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -334,7 +334,7 @@ public function testBuildSelect() | 334 | 334 | 'CREATE TABLE new_tbl SELECT * FROM orig_tbl' | 335 | 335 | ); | 336 | 336 | $this->assertEquals( | 337 | | - 'CREATE TABLE new_tbl SELECT * FROM orig_tbl ', | | 337 | + 'CREATE TABLE new_tbl SELECT * FROM orig_tbl', | 338 | 338 | $parser->statements[0]->build() | 339 | 339 | ); | 340 | 340 | } | |
Collapse file Copy file name to clipboardExpand all lines: tests/Builder/InsertStatementTest.php +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,7 +16,7 @@ public function testBuilder() | 16 | 16 | ); | 17 | 17 | $stmt = $parser->statements[0]; | 18 | 18 | $this->assertEquals( | 19 | | - 'INSERT INTO tbl(`col1`, `col2`, `col3`) VALUES (1, "str", 3.14)', | | 19 | + 'INSERT INTO tbl(`col1`, `col2`, `col3`) VALUES (1, "str", 3.14)', | 20 | 20 | $stmt->build() | 21 | 21 | ); | 22 | 22 |
| @@ -27,7 +27,7 @@ public function testBuilder() | 27 | 27 | ); | 28 | 28 | $stmt = $parser->statements[0]; | 29 | 29 | $this->assertEquals( | 30 | | - 'INSERT INTO tbl(`order`) VALUES (1)', | | 30 | + 'INSERT INTO tbl(`order`) VALUES (1)', | 31 | 31 | $stmt->build() | 32 | 32 | ); | 33 | 33 |
| @@ -38,7 +38,7 @@ public function testBuilder() | 38 | 38 | ); | 39 | 39 | $stmt = $parser->statements[0]; | 40 | 40 | $this->assertEquals( | 41 | | - 'INSERT INTO tbl SET FOO = 1', | | 41 | + 'INSERT INTO tbl SET FOO = 1', | 42 | 42 | $stmt->build() | 43 | 43 | ); | 44 | 44 |
| @@ -49,7 +49,7 @@ public function testBuilder() | 49 | 49 | ); | 50 | 50 | $stmt = $parser->statements[0]; | 51 | 51 | $this->assertEquals( | 52 | | - 'INSERT INTO tbl SELECT * FROM bar ', | | 52 | + 'INSERT INTO tbl SELECT * FROM bar', | 53 | 53 | $stmt->build() | 54 | 54 | ); | 55 | 55 |
| @@ -60,7 +60,7 @@ public function testBuilder() | 60 | 60 | ); | 61 | 61 | $stmt = $parser->statements[0]; | 62 | 62 | $this->assertEquals( | 63 | | - 'INSERT INTO tbl SELECT * FROM bar ON DUPLICATE KEY UPDATE baz = 1', | | 63 | + 'INSERT INTO tbl SELECT * FROM bar ON DUPLICATE KEY UPDATE baz = 1', | 64 | 64 | $stmt->build() | 65 | 65 | ); | 66 | 66 | } | |
Collapse file Copy file name to clipboardExpand all lines: tests/Builder/ReplaceStatementTest.php +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,7 @@ public function testBuilder() | 15 | 15 | ); | 16 | 16 | $stmt = $parser->statements[0]; | 17 | 17 | $this->assertEquals( | 18 | | - 'REPLACE INTO tbl(`col1`, `col2`, `col3`) VALUES (1, "str", 3.14)', | | 18 | + 'REPLACE INTO tbl(`col1`, `col2`, `col3`) VALUES (1, "str", 3.14)', | 19 | 19 | $stmt->build() | 20 | 20 | ); | 21 | 21 | } | @@ -27,7 +27,7 @@ public function testBuilderSet() | 27 | 27 | ); | 28 | 28 | $stmt = $parser->statements[0]; | 29 | 29 | $this->assertEquals( | 30 | | - 'REPLACE INTO tbl(`col1`, `col2`, `col3`) SET col1 = 1, col2 = "str", col3 = 3.14', | | 30 | + 'REPLACE INTO tbl(`col1`, `col2`, `col3`) SET col1 = 1, col2 = "str", col3 = 3.14', | 31 | 31 | $stmt->build() | 32 | 32 | ); | 33 | 33 | } | @@ -39,7 +39,7 @@ public function testBuilderSelect() | 39 | 39 | ); | 40 | 40 | $stmt = $parser->statements[0]; | 41 | 41 | $this->assertEquals( | 42 | | - 'REPLACE INTO tbl(`col1`, `col2`, `col3`) SELECT col1, col2, col3 FROM tbl2 ', | | 42 | + 'REPLACE INTO tbl(`col1`, `col2`, `col3`) SELECT col1, col2, col3 FROM tbl2', | 43 | 43 | $stmt->build() | 44 | 44 | ); | 45 | 45 | } | |
Collapse file Copy file name to clipboardExpand all lines: tests/Builder/SelectStatementTest.php +11-11Lines changed: 11 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,8 +17,8 @@ public function testBuilder() | 17 | 17 | $stmt = $parser->statements[0]; | 18 | 18 |
| 19 | 19 | $this->assertEquals( | 20 | | - 'SELECT * FROM t1 LEFT JOIN (t2, t3, t4) ' | 21 | | - . 'ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c) ', | | 20 | + 'SELECT * FROM t1 LEFT JOIN (t2, t3, t4) ' | | 21 | + . 'ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)', | 22 | 22 | $stmt->build() | 23 | 23 | ); | 24 | 24 | } | @@ -29,7 +29,7 @@ public function testBuilderUnion() | 29 | 29 | $stmt = $parser->statements[0]; | 30 | 30 |
| 31 | 31 | $this->assertEquals( | 32 | | - 'SELECT 1 UNION SELECT 2 ', | | 32 | + 'SELECT 1 UNION SELECT 2', | 33 | 33 | $stmt->build() | 34 | 34 | ); | 35 | 35 | } | @@ -45,18 +45,18 @@ public function testBuilderAlias() | 45 | 45 | $stmt = $parser->statements[0]; | 46 | 46 |
| 47 | 47 | $this->assertEquals( | 48 | | - 'SELECT sgu.id, sgu.email_address FROM `sf_guard_user` AS `sgu` ' | | 48 | + 'SELECT sgu.id, sgu.email_address FROM `sf_guard_user` AS `sgu` ' | 49 | 49 | . 'RIGHT JOIN `student_course_booking` AS `scb` ON sgu.id = scb.user_id ' | 50 | 50 | . 'WHERE `has_found_course` = \'1\' GROUP BY sgu.id ' | 51 | | - . 'ORDER BY scb.id DESC LIMIT 0, 300 ', | | 51 | + . 'ORDER BY scb.id DESC LIMIT 0, 300', | 52 | 52 | $stmt->build() | 53 | 53 | ); | 54 | 54 | } | 55 | 55 |
| 56 | 56 | public function testBuilderEndOptions() | 57 | 57 | { | 58 | 58 | /* Assertion 1 */ | 59 | | - $query = 'SELECT pid, name2 FROM tablename WHERE pid = 20 FOR UPDATE '; | | 59 | + $query = 'SELECT pid, name2 FROM tablename WHERE pid = 20 FOR UPDATE'; | 60 | 60 | $parser = new Parser($query); | 61 | 61 | $stmt = $parser->statements[0]; | 62 | 62 |
| @@ -66,7 +66,7 @@ public function testBuilderEndOptions() | 66 | 66 | ); | 67 | 67 |
| 68 | 68 | /* Assertion 2 */ | 69 | | - $query = 'SELECT pid, name2 FROM tablename WHERE pid = 20 LOCK IN SHARE MODE '; | | 69 | + $query = 'SELECT pid, name2 FROM tablename WHERE pid = 20 LOCK IN SHARE MODE'; | 70 | 70 | $parser = new Parser($query); | 71 | 71 | $stmt = $parser->statements[0]; | 72 | 72 |
| @@ -79,10 +79,10 @@ public function testBuilderEndOptions() | 79 | 79 | public function testBuilderIntoOptions() | 80 | 80 | { | 81 | 81 | /* Assertion 1 */ | 82 | | - $query = 'SELECT a, b, a+b INTO OUTFILE "/tmp/result.txt"' | | 82 | + $query = 'SELECT a, b, a+b INTO OUTFILE "/tmp/result.txt"' | 83 | 83 | . ' COLUMNS TERMINATED BY \',\' OPTIONALLY ENCLOSED BY \'"\'' | 84 | 84 | . ' LINES TERMINATED BY \'\n\'' | 85 | | - . ' FROM test_table '; | | 85 | + . ' FROM test_table'; | 86 | 86 | $parser = new Parser($query); | 87 | 87 | $stmt = $parser->statements[0]; | 88 | 88 |
| @@ -94,7 +94,7 @@ public function testBuilderIntoOptions() | 94 | 94 |
| 95 | 95 | public function testBuildGroupBy() | 96 | 96 | { | 97 | | - $query = 'SELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country '; | | 97 | + $query = 'SELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country'; | 98 | 98 | $parser = new Parser($query); | 99 | 99 | $stmt = $parser->statements[0]; | 100 | 100 |
| @@ -106,7 +106,7 @@ public function testBuildGroupBy() | 106 | 106 |
| 107 | 107 | public function testBuildIndexHint() | 108 | 108 | { | 109 | | - $query = 'SELECT * FROM address FORCE INDEX (idx_fk_city_id) IGNORE KEY FOR GROUP BY (a, b,c) WHERE city_id<0 '; | | 109 | + $query = 'SELECT * FROM address FORCE INDEX (idx_fk_city_id) IGNORE KEY FOR GROUP BY (a, b,c) WHERE city_id<0'; | 110 | 110 | $parser = new Parser($query); | 111 | 111 | $stmt = $parser->statements[0]; | 112 | 112 |
| |
Collapse file Copy file name to clipboardExpand all lines: tests/Builder/StatementTest.php +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,7 +34,7 @@ public function testBuilder() | 34 | 34 | 'SELECT DISTINCT `sakila`.`film`.`film_id` AS `fid`, COUNT(film_id) ' . | 35 | 35 | 'FROM `film`, `actor` ' . | 36 | 36 | 'WHERE film_id > 10 OR actor.age > 25 ' . | 37 | | - 'LIMIT 10, 1 ', | | 37 | + 'LIMIT 10, 1', | 38 | 38 | (string) $stmt | 39 | 39 | ); | 40 | 40 | } | |
Collapse file Copy file name to clipboardExpand all lines: tests/Builder/TransactionStatementTest.php +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,8 +20,8 @@ public function testBuilder() | 20 | 20 |
| 21 | 21 | $this->assertEquals( | 22 | 22 | 'START TRANSACTION;' . | 23 | | - 'SELECT @A:=SUM(salary) FROM table1 WHERE type=1 ;' . | 24 | | - 'UPDATE table2 SET summary = @A WHERE type=1 ;' . | | 23 | + 'SELECT @A:=SUM(salary) FROM table1 WHERE type=1;' . | | 24 | + 'UPDATE table2 SET summary = @A WHERE type=1;' . | 25 | 25 | 'COMMIT', | 26 | 26 | $stmt->build() | 27 | 27 | ); | |
|