Skip to content

Commit b8a8a19

Browse files
authored
prevent Query error: Incorrect table name '' (1103). (#456)
1 parent 209142a commit b8a8a19

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

src/QueryReflection/QueryReflection.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,11 @@ private function resolveQueryStringExpr(Expr $queryExpr, Scope $scope, bool $res
228228
if ($queryExpr instanceof Encapsed) {
229229
$string = '';
230230
foreach ($queryExpr->parts as $part) {
231-
$string .= $this->resolveQueryStringExpr($part, $scope);
231+
$resolvedPart = $this->resolveQueryStringExpr($part, $scope);
232+
if (null === $resolvedPart) {
233+
return null;
234+
}
235+
$string .= $resolvedPart;
232236
}
233237

234238
return $string;

tests/rules/data/syntax-error-in-prepared-statement.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,9 @@ public function preparedNamedParamsSubstitution(Connection $connection)
323323
{
324324
$connection->preparedQuery('SELECT email FROM ada WHERE email = :param OR email = :parameter', ['param' => 'abc', 'parameter' => 'def']);
325325
}
326+
327+
public function bug442(Connection $conn, string $table)
328+
{
329+
$conn->executeQuery("SELECT * FROM `$table`");
330+
}
326331
}

tests/rules/data/syntax-error-in-query-function.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@ public function conditionalSyntaxError(\mysqli $mysqli)
3838

3939
mysqli_query($mysqli, $query);
4040
}
41+
42+
public function bug442(\mysqli $mysqli, string $table)
43+
{
44+
mysqli_query($mysqli, "SELECT * FROM `$table`");
45+
}
4146
}

tests/rules/data/syntax-error-in-query-method.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,9 @@ public function conditionalSyntaxErrorInQueryUnion(PDO $pdo)
117117

118118
$pdo->query('SELECT email, adaid FROM ada '.$add.' LIMIT 1', PDO::FETCH_ASSOC);
119119
}
120+
121+
public function bug442(PDO $pdo, string $table)
122+
{
123+
$pdo->query("SELECT * FROM `$table`");
124+
}
120125
}

0 commit comments

Comments
 (0)