On May 16, 2013, at 6:22 PM, Bobby Impollonia <bob...@gmail.com> wrote:
> Sounds like a useful feature. > > Regarding case sensitivity, perhaps it would better if each of these methods > (even like() and contains()) took a keyword argument along the lines of > col.endswith('foo', case_sensitive=False) rather than adding extra methods > with weird names like iendswith. yes I've thought of that, though we already have "ilike()" for "like()", as this is a well known Postgresql operator, so I fear this might introduce some inconsistency. We'd really need to add "case_sensitive" to like() as well and everywhere, and just have "ilike()" be a synonym for "like(..., case_sensitive=False)". Additionally, case_sensitive might need to default to "None" - in its absence, technically we don't know if the underlying database is doing case sensitive comparison or not. Setting it to "True" means, "we will use known case-insensitive techniques for the target backend". But then what do we do on a backend that doesn't have "ilike"? do we raise an error? what if some backend already has case-insensitive collation set up ? > > On Monday, May 13, 2013 3:44:38 PM UTC-7, Michael Bayer wrote: > > On May 13, 2013, at 6:30 PM, Daniel Grace <thisgen...@gmail.com> wrote: > >> So today I identified a small bug in my code and then, while trying to >> resolve it, came to a few realizations: >> >> 1. column.contains(str) does not escape characters in str such as % and _. >> Presumably, column.startswith(str) and column.endswith(str) have the same >> behavior. > > this will be called "autoescape" and is ticket 2694: > http://www.sqlalchemy.org/trac/ticket/2694 . if someone wants to work on a > patch for this it would be v. helpful. It's a little late to turn on the > escaping for all users now as it would break existing workarounds. > > >> >> 2. There is a distinct lack of column.icontains(str), though the current >> implementation means it's identical to column.ilike('%' + str + '%') > > since we do have "ilike()" as an operator "icontains()" would be appropriate > at this point (also startswith,endswith). > > >> >> 3. There is no builtin function (that I found, please correct me if I'm >> wrong!) for escaping a string being passed to any functions in this family. > > will be 2694 > >> >> While I think that column.like and column.ilike should definitely /not/ >> escape their argument (you know you're trying for a pattern match here, and >> that you're matching against a pattern), I think that the >> .contains/.startswith/.endswith family of functions probably should perform >> this escaping transparently. Between DBAPI 2.0, SQLAlchemy and >> parameterized querying I don't need to worry about escaping input, so why >> should I have to pay attention to that detail when using .contains? Also, >> case insensitive versions of the above would probably be useful. >> >> That said, a proper fix might be complicated since it could inadvertently >> break existing code that relies on the current behavior of .contains() > >> >> -- Daniel >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to sqlalchemy+...@googlegroups.com. >> To post to this group, send email to sqlal...@googlegroups.com. >> Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.