Closed s-cenni closed 3 years ago
Hi @s-cenni,
nice to read you again working on solving Moodle vs Oracle issues :+1:!
Please, double check your code since e.g. $where = preg_replace('/^true AND/', '', $where);
should be improved with your new true strategy too: while your version will still work it doesn't act as the original code which removes the initial true condition.
Besides there's no need to call preg_replace()
3 times: for performance reasons it could be just $where = preg_replace('/^true( AND| OR)?/', '', $where);
(not tested).
I'd suggest to propose your code changed to adress what written above.
IMHO the true value should be a constant (here, a local variable too), properly commented with an example for being cross-compatible with the DBs supported by Moodle, which should be more maintainable and let others to change e.g. this constant value w/o knowing anything of the logics around that but the reason why for this particular value.
HTH, Matteo
Hi @s-cenni , Hi @scara ,
Thanks for spotting this Sara, and thanks for pointing this out Matteo. I'd love to see this into a PR so that I can spot out the differences more easily, and we can discuss it further.
Hi @scara, hi @ndunand , I send my PR (https://github.com/ndunand/moodle-enrol_attributes/pull/13)
Thanks Matteo for your great suggestions! (Yes, I keep going with my battle! Using Oracle always gives me a lot of work & fun!! ;) )
Temporarily I left the '1 = 1' condition in just one line because in the other parts 'where true' is replaced by the regexs. I didn't changed it because I'm not sure how to write an always true condition in SQL :(. Maybe it would be easier to change PHP code to create the correct query without this condition...
Hi @s-cenni, same in MSSQL :smirk:. Besides, mine was just an hint.
With Oracle I get this error.
in this query $select .= ' RIGHT JOIN '.$CFG->prefix.'user_info_data d'.$join_id.' ON d'.$join_id.'.userid = u.id'; $where .= ' (d'.$join_id.'.fieldid = '.$customkey.' AND ( d'.$join_id.'.data = \''.$rule->value.'\' OR d'.$join_id.'.data LIKE \'%;'.$rule->value.'\' OR d'.$join_id.'.data LIKE \''.$rule->value.';%\' OR d'.$join_id.'.data LIKE \'%;'.$rule->value.';%\' ))';
There are 2 problems: 1) data is a CLOB that needs to be manage with $DB->sql_like function https://docs.moodle.org/dev/Data_manipulation_API#SQL_compatibility_functions 2) Oracle doens't like the where true condition
I replaced $where = 'true'; with $where = '1 = 1'; and change the function arraysyntax_tosql in this way
and changing
$users = $DB->get_records_sql($select . $arraysql['select'] . $where . $arraysql['where']);
in$users = $DB->get_records_sql($select . $arraysql['select'] . $where . $arraysql['where'],$arraysql['params']);
(in lib.php) and$debug_users = $DB->get_records_sql($debug_sqlquery);
in$debug_users = $DB->get_records_sql($debug_sqlquery,$debug_arraysql['params']);
If you want I can send all my change code with a Pull Request
Bye Sara