https://bugzilla.wikimedia.org/show_bug.cgi?id=20275
--- Comment #16 from Aryeh Gregor <[email protected]> 2009-08-30 01:08:20 UTC --- (In reply to comment #14) > A simple test: > > mysql> SELECT '\\' LIKE '\\' AS a, '\\' LIKE '\\\\' AS b; > +---+---+ > | a | b | > +---+---+ > | 1 | 1 | > +---+---+ > 1 row in set (0.03 sec) > > sqlite> SELECT '\\' LIKE '\\' AS a, '\\' LIKE '\\\\' AS b; > 1|0 > > So the double-escaping is wrong for SQLite. I don't have any of the other > supported DBMSes handy to test with. Nikerabbit points out that I forgot the ESCAPE thing, so of course SQLite doesn't treat backslash specially. If I add ESCAPE '\', it matches MySQL: sqlite> SELECT '\\' LIKE '\\', '\\' LIKE '\\\\', '\\' LIKE '\\' ESCAPE '\', '\\' LIKE '\\\\' ESCAPE '\'; 1|0|0|1 (In reply to comment #15) > I like Alex's idea, here is an example of its implementation. I used different > names for constants. I prefer LIKE_ to MATCH_, personally. Also, PERCENT and UNDERSCORE are more readily comprehensible if you know much of any SQL, IMO. > It still has some problems though - even after replacement > of switch statement with ifs using === I'm still afraid of possible problems > when someone calls the function with an int parameter intended to be used as a > string. Then define a class, like class LikePercent {} class LikeUnderscore {} Then use those as magic markers. You can create a function or static method or member variable or whatever to avoid having to write "new LikePercent": $dbr->like( 'foo', likePercent() ); $dbr->like( 'foo', Database::percent() ); $dbr->like( 'foo', $dbr->percent ); where each of those three would return or be equal to "new LikePercent". A somewhat more hackish way of avoiding the problem in practice is to define LIKE_PERCENT to be 440366359746.12671 and LIKE_UNDERSCORE to be 501450300271.66339, or something like that. This is kind of scary-looking, I have to say. I'd like feedback from Tim or Brion before committing any system like this. Maybe there's a better way we're missing. -- Configure bugmail: https://bugzilla.wikimedia.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug. You are on the CC list for the bug. _______________________________________________ Wikibugs-l mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/wikibugs-l
