Browse Source

verify Fixed web-simple's db test

Mike Smith 11 years ago
parent
commit
9036143d4b
1 changed files with 14 additions and 3 deletions
  1. 14 3
      web-simple/app.pl

+ 14 - 3
web-simple/app.pl

@@ -17,15 +17,26 @@ sub dispatch_request {
     $queries ||= 1;
     $queries ||= 1;
     my $rand;
     my $rand;
     my @response;
     my @response;
-    for ( 1 .. $queries ) {
+    if ($queries == 1) {
         my $id = int(rand 10000) + 1;
         my $id = int(rand 10000) + 1;
         $sth->execute($id);
         $sth->execute($id);
         $sth->bind_col(2, \$rand);
         $sth->bind_col(2, \$rand);
         if ( my @row = $sth->fetch ) {
         if ( my @row = $sth->fetch ) {
-          push @response, { id => $id, randomNumber => $rand };
+            [ 200, [ 'Content-type' => 'application/json', ], 
+              [ encode_json({ id => $id, randomNumber => $rand })] ];
         }
         }
     }
     }
-    [ 200, [ 'Content-type' => 'application/json', ], [ encode_json(\@response)] ];
+    else {
+      for ( 1 .. $queries ) {
+          my $id = int(rand 10000) + 1;
+          $sth->execute($id);
+          $sth->bind_col(2, \$rand);
+          if ( my @row = $sth->fetch ) {
+              push @response, { id => $id, randomNumber => $rand };
+          }
+      }
+      [ 200, [ 'Content-type' => 'application/json', ], [ encode_json(\@response)] ];
+    }
   }
   }
 }
 }