push_pin
lock
Understanding logic in SearchEngine
I'm trying to understand how the SearchEngine work. What is the difference between the 2 searchengines below? I get 2 different results. In case In the second case I get a row, where y_eb_eval_koder.x_ft_heading == '82', which it shouldn't be allowed to. Case 1: String null; SearchEngine se; se.addField('y_eb_eval_koder.id'); se.addField('y_eb_eval_koder.x_ft_heading'); se.addCriteria('y_eb_eval_koder.x_ft_heading', 'Equals', '80', 'And', 1); se.addCriteria('y_eb_eval_koder.x_eb_post', 'Is', null, 'Or', 2); se.addCriteria('y_eb_eval_koder.x_eb_post', 'Equals', '0', 'And', 2); se.buildSql() gives: select a0.id, a0.x_ft_heading from y_eb_eval_koder a0 where a0.x_ft_heading = ? and (a0.x_eb_post is NULL or a0.x_eb_post = ?) //reducing parantheses select a0.id, a0.x_ft_heading from y_eb_eval_koder a0 where a0.x_ft_heading = ? and (a0.x_eb_post is NULL or a0.x_eb_post = ?) Case 2: String null; SearchEngine se; se.addField('y_eb_eval_koder.id'); se.addField('y_eb_eval_koder.x_ft_heading'); se.addCriteria('y_eb_eval_koder.x_eb_post', 'Is', null, 'Or', 1); se.addCriteria('y_eb_eval_koder.x_eb_post', 'Equals', '0', 'And', 1); se.addCriteria('y_eb_eval_koder.x_ft_heading', 'Equals', '80', 'And', 2); Using se.buildSql() and reducing parantheses again, I get this: select a0.id,a0.x_ft_heading from y_eb_eval_koder a0 where ((a0.x_eb_post is NULL or a0.x_eb_post = ?) and ((a0.x_ft_heading = ?))) //reducing parantheses select a0.id,a0.x_ft_heading from y_eb_eval_koder a0 where (a0.x_eb_post is NULL or a0.x_eb_post = ?) and a0.x_ft_heading = ?) Trusting the printed SQL I end up with the following: Case 1 : select a0.id, a0.x_ft_heading from y_eb_eval_koder a0 where a0.x_ft_heading = ? and (a0.x_eb_post is NULL or a0.x_eb_post = ?) Case 2 : select a0.id, a0.x_ft_heading from y_eb_eval_koder a0 where (a0.x_eb_post is NULL or a0.x_eb_post = ?) and a0.x_ft_heading = ? Isn¨t those the exact same expressions, just with the 2 where-statements switched?
Last reply
Hi, I've encountered the issue Kasper is describing quite a bit, and it's a little annoying. 🙂 Also some clarification here would be great. Is Kasper right in that this: cred.addCriteria('y_eb_eval_koder.x_password', 'BeginsWith', 'mx', 'Or', 1); //Crit A cred.addCriteria('y_eb_eval_koder.x_password', 'BeginsWith', 'zw', 'And', 1); //Crit B cred.addCriteria('y_eb_eval_koder.x_ft_heading', 'Equals', '80', 'And', 2); //Crit C is supposed to correspond to: (A OR B) AND C , but it's not working correctly because of this bug: https://community.superoffice.com/en/product-releases/bugs-wishes/product-issue/?bid=25596&azure=1 ? I see that using "in" is proposed as a workaround, but that only works for Integers as Kasper also points out. Any chance the bug will be corrected some time soon?