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

Failing AST test with non-named column #570

Closed
wants to merge 9 commits into from
Closed

Failing AST test with non-named column #570

wants to merge 9 commits into from

Conversation

jakubvojacek
Copy link
Contributor

Hello @staabm

this is related to #566 (comment), this is the reproducing case. When count(*) (or other functions) is used without alias, it fails to narrow down the type for integer indexed key in the resulting PDOStatement.

I tried playing around with ParserInference but couldn't find a easy way to fix this yet

@staabm
Copy link
Owner

staabm commented Mar 16, 2023

to implement this I think we need SQLFTW/sqlftw@da4e035 which will be part of the next sqlftw release, since it looks pretty similar to what I had in mind when reporting SQLFTW/sqlftw#15

@jakubvojacek
Copy link
Contributor Author

perfect, cant wait for this

@staabm
Copy link
Owner

staabm commented Mar 17, 2023

Today a new sqlftw was released. You can give it a try and update the lob with this PR and add a fix for you problem if you like

@jakubvojacek
Copy link
Contributor Author

I will give it a go over the weekend! Thanks

@jakubvojacek
Copy link
Contributor Author

The fix for the correct type inference was easy, but tests are failing @staabm

We got some problems with postgres tests, since AST does not work there, it fails (https://github.com/staabm/phpstan-dba/actions/runs/4454918527/jobs/7824413966?pr=570)

For the same reason, it also fails for php 7.3 and lower

Any idea how to overcome this, please?

@staabm
Copy link
Owner

staabm commented Mar 18, 2023

I think we should move ast tests, e.g.

if (\PHP_VERSION_ID >= 70400 && 'pdo-pgsql' !== getenv('DBA_REFLECTOR')) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/sql-ast-narrowing.php');
}

into a separate test-class and enable the runtime-config for SQL AST only for this new test-class


make sure to re-base this PR as in parallel another PR was merged

@jakubvojacek
Copy link
Contributor Author

Is this what you had in mind please?

Copy link
Owner

@staabm staabm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a whole new defaultAst suite, but just a new SqlAstInferenceTest.php within the existing default test-suite, which enables sql-ast like on setup/teardown, like we did for paramter validation in bb2b845#diff-428d052928087e660593dfd032cc0445056ba9fe2780ddb2292983fefe04ac87R18-R26

@@ -13,6 +13,6 @@ public function count(PDO $pdo): void
assertType('PDOStatement<array{myemail: numeric-string|null, 0: numeric-string|null}>', $stmt);

$stmt = $pdo->query('SELECT count(email) as myemail, count(email) from ada');
assertType('PDOStatement<array{myemail: numeric-string|null, 0: numeric-string|null, count(email): numeric-string, 1: numeric-string|null}>', $stmt);
assertType('PDOStatement<array{myemail: numeric-string|null, 0: numeric-string|null, count(email): numeric-string|null, 1: numeric-string|null}>', $stmt);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test no longer runs with SQL AST enabled

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

Successfully merging this pull request may close these issues.

2 participants