Hey Jeremy,
Thanks for the help! One slight problem here.
First of all, i couldn't do it with your first option. Secondly, the
example you gave generates:
select *
from members t
where data ? '$.alternate_emails[*] ? (@ like_regex ".
**'query_param_here_notice_quotes.*")'*
As you can see, lets say i give 'test' to query. instead of .*test.*, it
becomes .*'test'.*. Attention to the quotes before and after test. This
causes an error. If I use *Sequel.lit(query)* here, will this create SQL
injection possibility?
Thank you,
-Den
On Saturday, April 25, 2020 at 2:46:45 AM UTC+3, Jeremy Evans wrote:
>
> On Friday, April 24, 2020 at 3:47:32 PM UTC-7, Dennis O'Connell wrote:
>>
>> Hi Jeremy
>>
>> I use Models and i do not have access to DB instance using Rails module.
>> Due to this I tried to use *Model.with_sql.*
>>
>> MemberModel.with_sql('select *
>> from members t
>> where data @? \'$.alternate_emails[*] ? (@ like_regex
>> ".*?.*")\'', query.to_s).all
>>
>>
>> However, I got: *Mismatched number of placeholders (3) and placeholder
>> arguments (2) when using placeholder string*
>>
>> Well, there are 3 question marks indeed but first two of them is not
>> parameterized. It belongs to query. Third question mark, however, indeed a
>> parameter so query should be passed there.
>>
>> How can I solve this issue?
>>
>
> You could:
>
> 1) Use named placeholders (
> http://sequel.jeremyevans.net/rdoc/files/doc/querying_rdoc.html#label-Strings+with+Placeholders
> )
>
> 2) Use a placeholder for the ? operators and substitute the operators
> using literal SQL:
>
> MemberModel.with_sql('select *
> from members t
> where data ? \'$.alternate_emails[*] ? (@ like_regex
> ".*?.*")\'', Sequel.lit('@?'), Sequel.lit('?') , query.to_s).all
>
> Thanks,
> Jeremy
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sequel-talk/6a9c73de-17e4-4ee7-a377-8f7ea8255d17%40googlegroups.com.