From: Sam Morris Date: Mon, 14 Feb 2011 20:11:44 +0000 (-0800) Subject: Bug 616981: Make whine.pl work with PostgreSQL 8.4+ by fixing sql_string_until X-Git-Tag: bugzilla-3.6.5~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13eecb92ffe9cccb74af8114a76da8184c37e833;p=thirdparty%2Fbugzilla.git Bug 616981: Make whine.pl work with PostgreSQL 8.4+ by fixing sql_string_until r=mkanat, a=mkanat --- diff --git a/Bugzilla/DB/Pg.pm b/Bugzilla/DB/Pg.pm index 9c785e580a..123040f739 100644 --- a/Bugzilla/DB/Pg.pm +++ b/Bugzilla/DB/Pg.pm @@ -184,6 +184,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) = @_;