From 6d9c9459a7bdbd856100c39c148706e707c1811b Mon Sep 17 00:00:00 2001 From: "bugreport%peshkin.net" Date: Thu, 27 May 2004 02:40:18 +0000 Subject: [PATCH] Bug 243351: Fix mysql version sensitivity in case-sensitive search r=jouni a=justdave git-svn-id: svn://10.0.0.236/trunk@157000 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/webtools/bugzilla/Bugzilla/DB.pm | 10 ++++++++++ mozilla/webtools/bugzilla/Bugzilla/Search.pm | 10 +++++++++- mozilla/webtools/bugzilla/checksetup.pl | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mozilla/webtools/bugzilla/Bugzilla/DB.pm b/mozilla/webtools/bugzilla/Bugzilla/DB.pm index 684869006ec..a766a6e04ba 100644 --- a/mozilla/webtools/bugzilla/Bugzilla/DB.pm +++ b/mozilla/webtools/bugzilla/Bugzilla/DB.pm @@ -164,6 +164,16 @@ sub _handle_error { return 0; # Now let DBI handle raising the error } +my $cached_server_version; +sub server_version { + return $cached_server_version if defined($cached_server_version); + my $dbh = Bugzilla->dbh; + my $sth = $dbh->prepare('SELECT VERSION()'); + $sth->execute(); + ($cached_server_version) = $sth->fetchrow_array(); + return $cached_server_version; +} + 1; __END__ diff --git a/mozilla/webtools/bugzilla/Bugzilla/Search.pm b/mozilla/webtools/bugzilla/Bugzilla/Search.pm index 241439cf590..5f0e625aa5d 100644 --- a/mozilla/webtools/bugzilla/Bugzilla/Search.pm +++ b/mozilla/webtools/bugzilla/Bugzilla/Search.pm @@ -711,7 +711,15 @@ sub init { $term = "$ff != $q"; }, ",casesubstring" => sub { - $term = "INSTR(CAST($ff AS BINARY), CAST($q AS BINARY))"; + # mysql 4.0.1 and lower do not support CAST + # mysql 3.*.* had a case-sensitive INSTR + # (checksetup has a check for unsupported versions) + my $server_version = Bugzilla::DB->server_version; + if ($server_version =~ /^3\./) { + $term = "INSTR($ff ,$q)"; + } else { + $term = "INSTR(CAST($ff AS BINARY), CAST($q AS BINARY))"; + } }, ",substring" => sub { $term = "INSTR(LOWER($ff), " . lc($q) . ")"; diff --git a/mozilla/webtools/bugzilla/checksetup.pl b/mozilla/webtools/bugzilla/checksetup.pl index 8fc37f2ad5e..9d23579454a 100755 --- a/mozilla/webtools/bugzilla/checksetup.pl +++ b/mozilla/webtools/bugzilla/checksetup.pl @@ -1449,6 +1449,11 @@ if ($my_db_check) { " Bugzilla requires version $sql_want or later of MySQL.\n" . " Please visit http://www.mysql.com/ and download a newer version.\n"; } + if (( $sql_vers =~ /^4\.0\.(\d+)/ ) && ($1 < 2)) { + die "\nYour MySQL server is incompatible with Bugzilla.\n" . + " Bugzilla does not support versions 4.x.x below 4.0.2.\n" . + " Please visit http://www.mysql.com/ and download a newer version.\n"; + } my @databases = $dbh->func('_ListDBs'); unless (grep /^$my_db_name$/, @databases) {