Skip to content

Commit

Permalink
MDL-24079 glossary now using new sql_like
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 4, 2010
1 parent 800bb0f commit e99cfeb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
3 changes: 1 addition & 2 deletions mod/glossary/editcategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@

} 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>";

Expand Down
11 changes: 7 additions & 4 deletions mod/glossary/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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, '+-');
}
Expand All @@ -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%";
}
}
Expand Down
13 changes: 8 additions & 5 deletions mod/glossary/sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@
$REGEXP = $DB->sql_regex(true);
$NOTREGEXP = $DB->sql_regex(false);
}
$LIKE = $DB->sql_ilike(); // case-insensitive

$searchcond = array();
$alcond = array();
Expand All @@ -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, '+-');
}
Expand All @@ -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);
Expand Down

0 comments on commit e99cfeb

Please sign in to comment.