Skip to content

Commit

Permalink
Prevent adding a comma if key isn't in the first position
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrgicak committed May 17, 2024
1 parent b338090 commit fdef255
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions tests/WP_SQLite_Query_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,20 @@ public function testRecoverSerialized() {
$this->assertEquals( $obj, $unserialized );
}

public function testOnDuplicateKey() {
$this->assertQuery("

Check failure on line 509 in tests/WP_SQLite_Query_Tests.php

View workflow job for this annotation

GitHub Actions / Check code style

Opening parenthesis of a multi-line function call must be the last content on the line

Check failure on line 509 in tests/WP_SQLite_Query_Tests.php

View workflow job for this annotation

GitHub Actions / Check code style

String "\n CREATE TABLE `test` (\n `id` INT PRIMARY KEY,\n `text` VARCHAR(255),\n );\n " does not require double quotes; use single quotes instead
CREATE TABLE `test` (
`id` INT PRIMARY KEY,
`text` VARCHAR(255),
);
");

Check failure on line 514 in tests/WP_SQLite_Query_Tests.php

View workflow job for this annotation

GitHub Actions / Check code style

Closing parenthesis of a multi-line function call must be on a line by itself
// The order is deliberate to test that the query works with the keys in any order.
$this->assertQuery( "INSERT INTO test (`text`, `id`)

Check failure on line 516 in tests/WP_SQLite_Query_Tests.php

View workflow job for this annotation

GitHub Actions / Check code style

Opening parenthesis of a multi-line function call must be the last content on the line
VALUES ('test', 1)
ON DUPLICATE KEY UPDATE `text` = 'test1'"
);
}

public function testShowColumns() {

$query = 'SHOW COLUMNS FROM wp_posts';
Expand Down
5 changes: 3 additions & 2 deletions wp-includes/sqlite/class-wp-sqlite-translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2803,9 +2803,10 @@ private function translate_on_duplicate_key( $table_name ) {
$this->rewriter->add( new WP_SQLite_Token( '(', WP_SQLite_Token::TYPE_OPERATOR ) );

$max = count( $conflict_columns );
foreach ( $conflict_columns as $i => $conflict_column ) {
$i = 0;

Check warning on line 2806 in wp-includes/sqlite/class-wp-sqlite-translator.php

View workflow job for this annotation

GitHub Actions / Check code style

Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
foreach ( $conflict_columns as $conflict_column ) {
$this->rewriter->add( new WP_SQLite_Token( '"' . $conflict_column . '"', WP_SQLite_Token::TYPE_KEYWORD, WP_SQLite_Token::FLAG_KEYWORD_KEY ) );
if ( $i !== $max - 1 ) {
if ( ++$i < $max ) {
$this->rewriter->add( new WP_SQLite_Token( ',', WP_SQLite_Token::TYPE_OPERATOR ) );
$this->rewriter->add( new WP_SQLite_Token( ' ', WP_SQLite_Token::TYPE_WHITESPACE ) );
}
Expand Down

0 comments on commit fdef255

Please sign in to comment.