Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for INSERT INTO ... VALUES ... syntax in SQL queries #2498

Open
1 task
Chouby opened this issue Oct 2, 2024 · 0 comments
Open
1 task

Add support for INSERT INTO ... VALUES ... syntax in SQL queries #2498

Chouby opened this issue Oct 2, 2024 · 0 comments

Comments

@Chouby
Copy link
Contributor

Chouby commented Oct 2, 2024

Bug Description

Prepared SQL queries with INSERT INTO ... VALUES ... filled with the correct number of placeholders using the syntax commonly used for queries with IN(...) clauses (implode() + array_fill()) emit a warning.

Minimal Code Snippet

The issue happens when running this command:

phpcs --standard=WordPress -s testfile.php

... over a file containing this code:

$all_relationships = array(
	array( 1, 1 ),
	array( 1, 2 ),
	array( 1, 3 ),
);
$wpdb->query(
	$wpdb->prepare(
		sprintf(
			"INSERT INTO {$wpdb->term_relationships} (object_id, term_taxonomy_id) VALUES %s",
			implode( ',', array_fill( 0, count( $all_relationships ), '(%d,%d)' ) )
		),
		array_merge( ...$all_relationships )
	)
);

Error Code

Incorrect number of replacements passed to $wpdb->prepare().
Found 1 replacement parameters, expected 0.
(WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber)

Environment

Question Answer
PHP version 8.0.28
PHP_CodeSniffer version 3.10.3
WordPressCS version 3.1.0
PHPCSUtils version 1.0.12
PHPCSExtra version 1.2.1
WordPressCS install type Composer project local

Additional Context (optional)

Tested Against develop Branch?

  • I have verified the issue still exists in the develop branch of WordPressCS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant