]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 616981: Make whine.pl work with PostgreSQL 8.4+ by fixing sql_string_until
authorSam Morris <sam@robots.org.uk>
Mon, 14 Feb 2011 20:11:29 +0000 (12:11 -0800)
committerMax Kanat-Alexander <mkanat@bugzilla.org>
Mon, 14 Feb 2011 20:11:29 +0000 (12:11 -0800)
r=mkanat, a=mkanat

Bugzilla/DB/Pg.pm

index 2f42064e8ad6d61a0ed4753f32ae070189fbe5e9..888040ee80c941c02a0b6b8655a87fd37029c898 100644 (file)
@@ -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) = @_;