Browse Source

Compliance of updates method with test specifications (#5067)

jcheron 5 years ago
parent
commit
79bca15ad7
1 changed files with 11 additions and 6 deletions
  1. 11 6
      frameworks/PHP/symfony/src/Controller/DbRawController.php

+ 11 - 6
frameworks/PHP/symfony/src/Controller/DbRawController.php

@@ -23,7 +23,7 @@ class DbRawController
      */
      */
     public function db(): JsonResponse
     public function db(): JsonResponse
     {
     {
-        $statement = $this->connection->prepare('SELECT * FROM world WHERE id = ?');
+        $statement = $this->connection->prepare('SELECT * FROM World WHERE id = ?');
         $statement->execute([mt_rand(1, 10000)]);
         $statement->execute([mt_rand(1, 10000)]);
         $world = $statement->fetch(FetchMode::ASSOCIATIVE);
         $world = $statement->fetch(FetchMode::ASSOCIATIVE);
 
 
@@ -41,7 +41,7 @@ class DbRawController
         // possibility for enhancement is the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php
         // possibility for enhancement is the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php
         $worlds = [];
         $worlds = [];
 
 
-        $statement = $this->connection->prepare('SELECT * FROM world WHERE id = ?');
+        $statement = $this->connection->prepare('SELECT * FROM World WHERE id = ?');
         for ($i = 0; $i < $queries; ++$i) {
         for ($i = 0; $i < $queries; ++$i) {
             $statement->execute([mt_rand(1, 10000)]);
             $statement->execute([mt_rand(1, 10000)]);
             $worlds[] = $statement->fetch(FetchMode::ASSOCIATIVE);
             $worlds[] = $statement->fetch(FetchMode::ASSOCIATIVE);
@@ -60,12 +60,17 @@ class DbRawController
 
 
         $worlds = [];
         $worlds = [];
 
 
-        $statement = $this->connection->prepare('UPDATE world SET randomNumber=? WHERE id=?');
+        $writeStatement = $this->connection->prepare('UPDATE World SET randomNumber= ? WHERE id= ?');
+        $readStatement = $this->connection->prepare('SELECT id,randomNumber FROM World WHERE id = ?');
+
         for ($i = 0; $i < $queries; ++$i) {
         for ($i = 0; $i < $queries; ++$i) {
             $id = mt_rand(1, 10000);
             $id = mt_rand(1, 10000);
-            $randomNumber = mt_rand(1, 10000);
-            $statement->execute([$randomNumber, $id]);
-            $worlds[] = ['id' => $id, 'randomNumber' => $randomNumber];
+            $readStatement->execute([$id]);
+            $world =  $readStatement->fetch(FetchMode::ASSOCIATIVE);
+            $writeStatement->execute(
+                [$world['randomNumber'] = mt_rand(1, 10000), $id]
+            );
+            $worlds[] = $world;
         }
         }
 
 
         return new JsonResponse($worlds);
         return new JsonResponse($worlds);