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

error on sql-IN() and empty-array #292

Open
Tracked by #123
staabm opened this issue Feb 14, 2022 · 0 comments
Open
Tracked by #123

error on sql-IN() and empty-array #292

staabm opened this issue Feb 14, 2022 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@staabm
Copy link
Owner

staabm commented Feb 14, 2022

should error, as a sql error occurs when ids is an empty-array.

// should error
function inIDs(array $ids) {
  $pdo->query('SELECT email FROM ada WHERE adaid IN('. implode(',', $ids) .')', PDO::FETCH_ASSOC);
}

// should error
function inIDs(array $ids) {
  $stmt = $pdo->prepare('SELECT email FROM ada WHERE adaid IN(?)');
  $stmt->execute([implode(',', $ids)]);
}

// fine
/** @param non-empty-array $ids */
function inIDs(array $ids) {
  $pdo->query('SELECT email FROM ada WHERE adaid IN('. implode(',', $ids) .')', PDO::FETCH_ASSOC);
}
@staabm staabm added the enhancement New feature or request label Feb 14, 2022
@staabm staabm mentioned this issue Feb 14, 2022
13 tasks
@staabm staabm added this to the SQL AST milestone Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant