Bug 1953 [3/6]: refactoring to remove superfluous where clause.
authorAndrew Moore <andrew.moore@liblime.com>
Tue, 29 Jul 2008 16:42:47 +0000 (11:42 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Wed, 30 Jul 2008 08:45:21 +0000 (03:45 -0500)
refactored the SQL query to remove a confusing and superfluous 'WHERE 1' clause.

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Koha.pm

index 5a7fe4d..b5f6f91 100644 (file)
@@ -891,17 +891,22 @@ sub displayServers {
     my ( $position, $type ) = @_;
     my $dbh    = C4::Context->dbh;
 
-    my $strsth = "SELECT * FROM z3950servers where 1";
+    my $strsth = 'SELECT * FROM z3950servers';
+    my @where_clauses;
     my @bind_params;
 
     if ( $position ) {
         push @bind_params, $position;
-        $strsth .= ' AND position = ? ';
+        push @where_clauses, ' position = ? ';
     }
 
     if ( $type ) {
         push @bind_params, $type;
-        $strsth .= ' AND type = ? ';
+        push @where_clauses, ' type = ? ';
+    }
+
+    if ( @where_clauses ) {
+        $strsth .= ' WHERE ' . join( ' AND ', @where_clauses );
     }
 
     my $rq = $dbh->prepare($strsth);