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

Raise if not enough bind values are passed to a raw sql statement #15

Merged
merged 1 commit into from
Mar 6, 2025

Conversation

jhollinger
Copy link
Owner

@jhollinger jhollinger commented Mar 4, 2025

Raises OccamsRecord::MissingBindValuesError if not enough bind values are passed in. #14

res = OccamsRecord.
  sql("SELECT * FROM widgets WHERE user_id = :user_id AND name = :name AND age = :age", {user_id: 5}).
  run

# OccamsRecord::MissingBindValuesError: Missing binds (name, age) in SELECT * FROM widgets WHERE user_id = %{user_id} AND name = %{name} AND age = %{age}

Positional binds will show the number of missing binds:

res = OccamsRecord.
  sql("SELECT * FROM widgets WHERE user_id = ? AND name = ? AND age = ?", [5]).
  run

# OccamsRecord::MissingBindValuesError: Missing binds (2) in SELECT * FROM widgets WHERE user_id = %s AND name = %s AND age = %s

@jhollinger jhollinger force-pushed the raise-on-missing-bind-values branch 2 times, most recently from 9592cfc to 92a3c12 Compare March 4, 2025 18:28
@jhollinger jhollinger force-pushed the raise-on-missing-bind-values branch from 92a3c12 to 6bbabea Compare March 4, 2025 18:33
@jhollinger jhollinger marked this pull request as ready for review March 6, 2025 17:51
@jhollinger jhollinger merged commit f56f754 into main Mar 6, 2025
3 checks passed
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.

1 participant