From 2e1cbfb718e12e852acce103ecf4cd4f192e4db2 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" Date: Mon, 14 Feb 2011 20:27:00 +0000 Subject: [PATCH] Bug 616981: Make whine.pl work with PostgreSQL 8.4+ by fixing sql_string_until r=mkanat, a=mkanat git-svn-id: svn://10.0.0.236/trunk@261938 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/webtools/bugzilla/.bzrrev | 2 +- mozilla/webtools/bugzilla/Bugzilla/DB/Pg.pm | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mozilla/webtools/bugzilla/.bzrrev b/mozilla/webtools/bugzilla/.bzrrev index 597b355e49a..14be082f093 100644 --- a/mozilla/webtools/bugzilla/.bzrrev +++ b/mozilla/webtools/bugzilla/.bzrrev @@ -1 +1 @@ -7712 \ No newline at end of file +7713 \ No newline at end of file diff --git a/mozilla/webtools/bugzilla/Bugzilla/DB/Pg.pm b/mozilla/webtools/bugzilla/Bugzilla/DB/Pg.pm index e59a638a427..f0a395900c3 100644 --- a/mozilla/webtools/bugzilla/Bugzilla/DB/Pg.pm +++ b/mozilla/webtools/bugzilla/Bugzilla/DB/Pg.pm @@ -192,6 +192,18 @@ sub sql_string_concat { return '(CAST(' . join(' AS text) || CAST(', @params) . ' AS text))'; } +sub sql_string_until { + my ($self, $string, $substring) = @_; + + # PostgreSQL does not permit a negative substring length; therefore we + # use CASE to only perform the SUBSTRING operation when $substring can + # be found withing $string. + return "CASE WHEN " . $self->sql_position($substring, $string) + . " != 0 THEN SUBSTRING($string FROM 1 FOR " + . $self->sql_position($substring, $string) . " - 1)" + . " ELSE $string END"; +} + # Tell us whether or not a particular sequence exists in the DB. sub bz_sequence_exists { my ($self, $seq_name) = @_;