canonical / sqlair

Friendly type mapping for SQL databases
Apache License 2.0
16 stars 8 forks source link

Input in '' quotation are not parsed by SQLair #148

Closed ycliuhw closed 2 months ago

ycliuhw commented 2 months ago

The problem is that if we want to use regexorLIKEin SQLite, we have to quote the value. However, I found that SQLair currently ignores any parameters in quotations. For example, thename_prefixparameter inWHERE name LIKE '$M.name_prefix%'will be ignored by sqlair. Then, the SQLite raises an error:invalid input parameter: argument of type \"M\" not used by query`.

Aflynn50 commented 2 months ago

For use cases like this I would recommend using CONCAT. For example you could do:

SELECT name FROM user WHERE name LIKE CONCAT($M.name_prefix, '%')

The limitation of not parsing query input parameters in quotes, either " or ' applies also to regular ? SQL query parameters. In SQLair we purposefully pass over anything contained in quotes.

ycliuhw commented 2 months ago

Yeah, this could be a workaround. Thanks, @Aflynn50 .