Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Duplicate
-
Affects Version/s: 1.9
-
Fix Version/s: 2.0
-
Component/s: Database SQL/XMLDB
-
Labels:None
-
Affected Branches:MOODLE_19_STABLE
-
Fixed Branches:MOODLE_20_STABLE
Description
Oracle is case sensitive, so a query like:
select * from mdl_user where firstname = "name"
will only return exact matches - it won't return "Name", "NAME" etc like Mysql/postgres do.
this is a problem in many areas of moodle code and there seem to be various bugs in the tracker that are related.
Oracle 10g allows the setting of a Session var that changes this.
one of our clients came up with this code which they've put in lib/setup.lib which seems to fix it nicely!
if($CFG->dbtype == 'oci8po'){
if (!empty ($CFG->nls_sort)) {
$db->execute('ALTER SESSION SET NLS_SORT=' . $CFG->nls_sort);
}
if (!empty ($CFG->nls_comp)) {
$db->execute('ALTER SESSION SET NLS_COMP=' . $CFG->nls_comp);
}
}
they have then placed the correct vars for their version of oracle in the config vars $CFG->nls_sort and $CFG-nls_comp.
I think we should be a bit more clever and determine which Oracle version they are using, and if they are using a version prior to 10gR2 then use "ANSI" as the NLS_COMP and 'BINARY_CI' for NLS_SORT
but if they're using 10gR2 or higher use 'LINGUISTIC' for NLS_COMP and 'BINARY_CI' for NLS_SORT
there's a good Oracle article here that describes the commands:
http://www.orafaq.com/node/91
NOTE: the changes for older versions of oracle will not make "LIKE" queries case insensitve - only oracle 10gR2 supports this with the above changes.
![]()
Dan
Hi Dan,
if I'm not wrong, the example you've posted above:
select * from mdl_user where firstname = "name"
only performs case-insensitive matches under MySQL (and that's an odd behaviour). All the rest of DBs perform case-sensitive comparisons, and that's the way things must work.
So, if there are parts of Moodle relying in that MySQL "feature" we should fix all them ASAP.
Another thing is the "LIKE" statement, yes, there are some parts executing it in case-sensitive (LIKE) and case-insensitive (ILIKE) modes... I remember I was looking at that stuff for Oracle in Moodle 1.7 times and the NLS + "LINGUISTIC" stuff had some undesired effects... I don't remember more, but I'm sure I prospect that way... uhmm. Perhaps it was that, once executed... all the session becomes case-insensitive... and that causes problems in other queries executed later.. uhmm... horrible memory!
In any case, it's only a LIKE think. Never an = thing IMO.
Ciao