Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/QueryReflection/BasePdoQueryReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ abstract class BasePdoQueryReflector implements QueryReflector, RecordingReflect

private const MYSQL_UNKNOWN_TABLE = '42S02';

private const MYSQL_INTEGRITY_CONSTRAINT_VIOLATION = '23000';

private const PDO_SYNTAX_ERROR_CODES = [
self::MYSQL_SYNTAX_ERROR_CODE,
self::PSQL_SYNTAX_ERROR,
Expand All @@ -48,6 +50,7 @@ abstract class BasePdoQueryReflector implements QueryReflector, RecordingReflect
self::MYSQL_SYNTAX_ERROR_CODE,
self::MYSQL_UNKNOWN_COLUMN_IN_FIELDLIST,
self::MYSQL_UNKNOWN_TABLE,
self::MYSQL_INTEGRITY_CONSTRAINT_VIOLATION,
];

protected const MAX_CACHE_SIZE = 50;
Expand Down
3 changes: 3 additions & 0 deletions src/QueryReflection/MysqliQueryReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ final class MysqliQueryReflector implements QueryReflector, RecordingReflector

private const MYSQL_UNKNOWN_COLUMN_IN_FIELDLIST = 1054;

private const MYSQL_AMBIGUOUS_COLUMN_IN_FROM_CLAUSE = 1052;

public const MYSQL_UNKNOWN_TABLE = 1146;

private const MYSQL_INCORRECT_TABLE = 1103;
Expand All @@ -33,6 +35,7 @@ final class MysqliQueryReflector implements QueryReflector, RecordingReflector
private const MYSQL_ERROR_CODES = [
self::MYSQL_SYNTAX_ERROR_CODE,
self::MYSQL_UNKNOWN_COLUMN_IN_FIELDLIST,
self::MYSQL_AMBIGUOUS_COLUMN_IN_FROM_CLAUSE,
self::MYSQL_UNKNOWN_TABLE,
self::MYSQL_INCORRECT_TABLE,
];
Expand Down
26 changes: 26 additions & 0 deletions tests/default/config/.phpunit-phpstan-dba-mysqli.cache

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions tests/rules/SyntaxErrorInPreparedStatementMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,26 @@ public function testSyntaxErrorInQueryRule(): void
$this->analyse([__DIR__ . '/data/syntax-error-in-prepared-statement.php'], $expectedErrors);
}

public function test_prepared_statement_method_reports_ambiguous_using_column(): void
{
if (MysqliQueryReflector::NAME === getenv('DBA_REFLECTOR')) {
if ('mariadb' === $_ENV['DBA_PLATFORM']) {
$expectedError = "Query error: Column 'adaid' in FROM is ambiguous (1052).";
} else {
$expectedError = "Query error: Column 'adaid' in from clause is ambiguous (1052).";
}
} elseif (PdoMysqlQueryReflector::NAME === getenv('DBA_REFLECTOR')) {
$expectedError = "Query error: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'adaid' in from clause is ambiguous (23000).";
} else {
self::markTestSkipped('This regression only applies to MySQL reflectors.');
}

$this->analyse(
[__DIR__ . '/data/ambiguous-using-column.php'],
[[$expectedError, 11]],
);
}

public function testBug94()
{
if (MysqliQueryReflector::NAME === getenv('DBA_REFLECTOR')) {
Expand Down
11 changes: 11 additions & 0 deletions tests/rules/config/.phpunit-phpstan-dba-mysqli.cache

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/rules/config/.phpunit-phpstan-dba-pdo-mysql.cache

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions tests/rules/data/ambiguous-using-column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace AmbiguousUsingColumnRuleTest;

use staabm\PHPStanDba\Tests\Fixture\Connection;

class Foo
{
public function preparedStatement(Connection $connection): void
{
$connection->preparedQuery(
'SELECT first.adaid
FROM ada first
JOIN ada second ON second.adaid = first.adaid
JOIN ada third USING(adaid)',
[],
);
}
}
28 changes: 14 additions & 14 deletions tests/sqlAst/config/.phpunit-phpstan-dba-mysqli.cache

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading