Forráskód Böngészése

Add a cursor to fetch storage when available

DricomDragon 5 éve
szülő
commit
98fda8878c
1 módosított fájl, 16 hozzáadás és 1 törlés
  1. 16 1
      SQL/plpgsql/create_add_missing_stocks.sql

+ 16 - 1
SQL/plpgsql/create_add_missing_stocks.sql

@@ -3,8 +3,12 @@ $$
 DECLARE
     proCursor CURSOR FOR SELECT pro_id FROM Product;
     proId Product.pro_id%TYPE;
+
     warCursor CURSOR FOR SELECT war_id FROM Warehouse;
     warId Warehouse.war_id%TYPE;
+
+    stoCursor CURSOR FOR SELECT sto_quantity FROM Stock WHERE pro_id = proId AND war_id = warId;
+    stoQuantity Stock.sto_quantity%TYPE;
 BEGIN
     RAISE NOTICE 'Start';
 
@@ -19,7 +23,18 @@ BEGIN
         LOOP
             FETCH warCursor INTO warId;
             EXIT WHEN warId IS NULL;
-            RAISE NOTICE 'Pro % for war %', proId, warId;
+
+            -- Find associated storage
+            OPEN stoCursor;
+            FETCH stoCursor INTO stoQuantity;
+            IF stoQuantity IS NULL
+            THEN
+                RAISE NOTICE 'Pro % for war % not available', proId, warId;
+            ELSE 
+                RAISE NOTICE 'Pro % for war % stores %', proId, warId, stoQuantity;
+            END IF;
+            CLOSE stoCursor;
+            
         END LOOP;
         CLOSE warCursor;
     END LOOP;