Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BSierakowski/31d648b57e1ff42cb4850edc16985db5 to your computer and use it in GitHub Desktop.
Save BSierakowski/31d648b57e1ff42cb4850edc16985db5 to your computer and use it in GitHub Desktop.
statuses_and_descriptions = ActiveRecord::Base.sanitize_sql_array([UPDATE_CONTACT_STATUS_AND_DESCRIPTION_SQL, {
team_id:, hs_object_id: hs_object_id.to_s
}])
ActiveRecord::Base.connection.exec_query(statuses_and_descriptions)
@pjb3
Copy link

pjb3 commented Apr 4, 2024

Yeah, that works for parameters in a Hash:

>> User.sanitize_sql_array(["select * from users where id = :id", id: 1])
=> "select * from users where id = 1"

But what I'm actually trying to do is get the query for one that I use with select_all, which would look like this:

User.connection.select_all("select first_name from users where id = $1", nil, [1])

But sanitize_sql_array doesn't work with the style of parameters that select_all requires:

>> User.sanitize_sql_array(["select * from users where id = $1", 1])
=> "select * from users where id = $1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment