/** * Returns the proper SQL to do LIKE in a case-insensitive way for oracle * and Postgres * * Note the LIKE are case sensitive for Oracle. Oracle 10g is required to use * the caseinsensitive search using regexp_like() or NLS_COMP=LINGUISTIC :-( * See http://docs.moodle.org/en/XMLDB_Problems#Case-insensitive_searches * * @uses $CFG * @param string $field Number of records per page * @param string $data Number of records per page * @param integer $operator Number of records per page * @return string */ function sql_olike($field, $data, $operator=0) { global $CFG; $not = ''; switch ($operator) { case 0: // contains $value = "'%$data%'"; $oci8_value = "'$data'"; break; case 1: // does not contain $not = 'NOT'; $value = "'%$data%'"; $oci8_value = "'$data'"; break; case 2: // equal to $value = "'$data'"; $oci8_value = "'^$data$'"; break; case 3: // starts with $value = "'$data%'"; $oci8_value = "'^$data'"; break; case 4: // ends with $value = "'%$data'"; $oci8_value = "'$data$'"; break; case 5: // empty $value = "''"; $oci8_value = "''"; break; case 7: // is defined break; } switch ($CFG->dbfamily) { case 'postgres': return " $field $not ILIKE $value "; case 'oracle': return "$not regexp_like($field, $oci8_value, 'i') "; default: return " $field $not LIKE $value "; } }