aaberg / sql2o

sql2o is a small library, which makes it easy to convert the result of your sql-statements into objects. No resultset hacking required. Kind of like an orm, but without the sql-generation capabilities. Supports named parameters.
http://sql2o.org
MIT License
1.15k stars 229 forks source link

How to use like match? #283

Closed ysdxz207 closed 7 years ago

ysdxz207 commented 7 years ago

My sql is : select * from permission where 1 = 1 and permission_name like '%:permissionName%' ; I am using 'query.addParameter("permissionName", "select")'. Error is : Failed to add parameter with name 'permissionName'. No parameter with that name is declared in the sql.

ysdxz207 commented 7 years ago

I saw the source code found that if I use quote then ":permissionName" will not be replaced with "?". So how should I write my sql?

zapodot commented 7 years ago

This should work: SQL: select * from permission where 1 = 1 and permission_name like :permissionName; Java: query.addParameter("permissionName", "%select%")

Please report back if you still can't get it to work

ysdxz207 commented 7 years ago

It works! Thank you very much!