Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

problem with ( in qoutes #442

Open
1 task
hcn501 opened this issue Sep 17, 2021 · 7 comments
Open
1 task

problem with ( in qoutes #442

hcn501 opened this issue Sep 17, 2021 · 7 comments

Comments

@hcn501
Copy link

hcn501 commented Sep 17, 2021

Prerequisites

Description

Steps to Reproduce

Expected behavior:

Actual behavior:

Reproduces how often:

Versions

Additional Information

@hcn501 hcn501 changed the title $sql = $sql . " AND ($key LIKE '" . $valuex . "'";After this the above problem with ( in qoutes Sep 17, 2021
@hcn501
Copy link
Author

hcn501 commented Sep 17, 2021

After this code the rest of the code is not formatted in correct colours: $sql = $sql . " AND ($key LIKE '" . $valuex . "'";
It is the ( making the wrong formatting of text colours. If i remove the ( then coulors are correct.
Is there anybody who can fix this bug..... Thanks in advance:-)

@hcn501
Copy link
Author

hcn501 commented Sep 17, 2021

Wrong colours:
Skærmbillede 2021-09-17 kl  18 34 49
Correct colour:
Skærmbillede 2021-09-17 kl  18 37 39

@hcn501 hcn501 closed this as completed Sep 17, 2021
@hcn501 hcn501 reopened this Sep 17, 2021
@KapitanOczywisty
Copy link
Contributor

This is known issue and rather hard to fix. Try to avoid incomplete sql syntax, for example:

$value = ['testA', 'testB'];

if(isset($value) AND count($value)){
	$search = array_map(fn($valuex) => "{$key} LIKE '%{$valuex}%'", $value);
	$search = implode(' OR ', $search);
} else {
	$search = "{$key} = '0'";
}

$sql .= " AND ({$search})";

Even better would be to use prepared statements to prevent some attacks using insecure variables https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php

@echantigny
Copy link

This is an issue even if the query itself is unbroken.

See this example, where everything after the $query variable loses the syntax highlighting

<?php 
$query = "SELECT
		`users`.`total_review` AS `total`,
		`users`.`negative_review`,
		`note`.`satisfaction`,
		`note`.`recommendation` AS `question_6`
	FROM (
		SELECT
			`exam_note_users`.`satisfaction`,
			`exam_note_users`.`recommendation`
		FROM `exam_note_users`
		WHERE
			`exam_note_users`.`question_id` IS NULL
			AND `exam_note_users`.`category_id` IS NULL
			AND `exam_note_users`.`company_id`=:company_id
	) AS `note`, 
	(
		SELECT
			`exam_users`.`total_review`,
			`exam_users`.`negative_review`
		FROM `exam_users`
		WHERE
			AND `exam_users`.`company_id`=:company_id
    ) AS `users`";

$statementAggregation = $database->prepare($query);
$statementAggregation->bindValue(":company_id", $rowReportCompany["company_id"], PDO::PARAM_INT);
$statementAggregation->execute();
$rowAggregation = $statementAggregation->fetch();
?>

Taking the last parentheses and making it it's own string gets the syntax highlighting back

<?php 
$query = "SELECT
		`users`.`total_review` AS `total`,
		`users`.`negative_review`,
		`note`.`satisfaction`,
		`note`.`recommendation` AS `question_6`
	FROM (
		SELECT
			`exam_note_users`.`satisfaction`,
			`exam_note_users`.`recommendation`
		FROM `exam_note_users`
		WHERE
			`exam_note_users`.`question_id` IS NULL
			AND `exam_note_users`.`category_id` IS NULL
			AND `exam_note_users`.`company_id`=:company_id
	) AS `note`, 
	(
		SELECT
			`exam_users`.`total_review`,
			`exam_users`.`negative_review`
		FROM `exam_users`
		WHERE
			AND `exam_users`.`company_id`=:company_id";
$query .=") AS `users`";

$statementAggregation = $database->prepare($query);
$statementAggregation->bindValue(":company_id", $rowReportCompany["company_id"], PDO::PARAM_INT);
$statementAggregation->execute();
$rowAggregation = $statementAggregation->fetch();
?>

@KapitanOczywisty
Copy link
Contributor

@echantigny I'm unable to reproduce your issue. Can you provide screenshot showing the problem? Which version of atom are you using? Which version of language-php?

That's how your code looks like on my end (don't mind whitespace symbols):
image

@echantigny
Copy link

echantigny commented Jan 13, 2022

@KapitanOczywisty I just realised that the github issue I was looking at for VSCode sent me here, on the Atom project.

If it really is linked projects, this is what I have installed with PHP Intelephense. Otherwise, well... you can ignore my messages. :)

Version: 1.63.2 (user setup)
Commit: 899d46d82c4c95423fb7e10e68eba52050e30ba3
Date: 2021-12-15T09:40:02.816Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.19043

And as of this morning (VS Code updated last night), it looks like this is fixed now.

Sorry!

@KapitanOczywisty
Copy link
Contributor

@echantigny This is the right place, VS Code is using syntax from this repository and Intelephense doesn't provide syntax highlighting.

Last update was a month ago, so there might be something wrong if VS Code updated yesterday. I've also tested your code in VS Code yesterday and it was fine. Let me know if something similar happens again.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants