MDL-24079 glossary now using new sql_like

This commit is contained in:
Petr Skoda
2010-09-04 14:15:48 +00:00
parent 800bb0f70f
commit e99cfeb83f
3 changed files with 16 additions and 11 deletions
+1 -2
View File
@@ -158,8 +158,7 @@ if ( $hook >0 ) {
} elseif ( $action == "add" ) {
if ( $confirm ) {
$ILIKE = $DB->sql_ilike();
$dupcategory = $DB->get_records_sql("SELECT * FROM {glossary_categories} WHERE name $ILIKE ? AND glossaryid=?", array($name, $glossary->id));
$dupcategory = $DB->get_records_sql("SELECT * FROM {glossary_categories} WHERE ".$DB->sql_like('name','?', false)." AND glossaryid=?", array($name, $glossary->id));
if ( $dupcategory ) {
echo "<h3 class=\"main\">" . get_string("add"). " " . get_string("category","glossary"). "</h3>";
+7 -4
View File
@@ -1200,7 +1200,6 @@ function glossary_search($course, $searchterms, $extended = 0, $glossary = NULL)
$REGEXP = $DB->sql_regex(true);
$NOTREGEXP = $DB->sql_regex(false);
}
$LIKE = $DB->sql_ilike(); // case-insensitive
$searchcond = array();
$params = array();
@@ -1212,14 +1211,14 @@ function glossary_search($course, $searchterms, $extended = 0, $glossary = NULL)
foreach ($searchterms as $searchterm) {
$i++;
$NOT = ''; /// Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle
$NOT = false; /// Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle
/// will use it to simulate the "-" operator with LIKE clause
/// Under Oracle and MSSQL, trim the + and - operators and perform
/// simpler LIKE (or NOT LIKE) queries
if (!$DB->sql_regex_supported()) {
if (substr($searchterm, 0, 1) == '-') {
$NOT = ' NOT ';
$NOT = true;
}
$searchterm = trim($searchterm, '+-');
}
@@ -1239,7 +1238,11 @@ function glossary_search($course, $searchterms, $extended = 0, $glossary = NULL)
$params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)";
} else {
$searchcond[] = "$concat $NOT $LIKE :ss$i";
if ($NOT) {
$searchcond[] = "$concat NOT LIKE :ss$i"; //TODO: MDL-24080
} else {
$searchcond[] = $DB->sql_like($concat, ":ss$i", false);
}
$params['ss'.$i] = "%$searchterm%";
}
}
+8 -5
View File
@@ -145,7 +145,6 @@
$REGEXP = $DB->sql_regex(true);
$NOTREGEXP = $DB->sql_regex(false);
}
$LIKE = $DB->sql_ilike(); // case-insensitive
$searchcond = array();
$alcond = array();
@@ -159,14 +158,14 @@
foreach ($searchterms as $searchterm) {
$i++;
$NOT = ''; /// Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle
$NOT = false; /// Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle
/// will use it to simulate the "-" operator with LIKE clause
/// Under Oracle and MSSQL, trim the + and - operators and perform
/// simpler LIKE (or NOT LIKE) queries
if (!$DB->sql_regex_supported()) {
if (substr($searchterm, 0, 1) == '-') {
$NOT = ' NOT ';
$NOT = true;
}
$searchterm = trim($searchterm, '+-');
}
@@ -193,13 +192,17 @@
if ($textlib->strlen($searchterm) < 2) {
continue;
}
$searchcond[] = "$concat $NOT $LIKE :ss$i";
if ($NOT) {
$searchcond[] = "$concat NOT LIKE :ss$i"; //TODO: MDL-24080
} else {
$searchcond[] = $DB->sql_like($concat, ":ss$i", false);
}
$params['ss'.$i] = "%$searchterm%";
}
}
if (empty($searchcond)) {
$where = " 1=2 "; // no search result
$where = "AND 1=2 "; // no search result
} else {
$searchcond = implode(" AND ", $searchcond);