Warning: Use of undefined constant id - assumed 'id' (this will throw an Error in a future version of PHP) in
/kunden/247608_14469/webseiten/wp-content/themes/wordblab/functions.php on line
28
Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in
/kunden/247608_14469/webseiten/wp-content/themes/wordblab/functions.php on line
29
Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in
/kunden/247608_14469/webseiten/wp-content/themes/wordblab/functions.php on line
9
Wer sich mit dem SQL-Skript aus dem MySQL Cursor Beispiel beschäftigt hat wird festgestellt haben, dass der dort definierte Trigger check_amount
nur funktioniert, wenn nicht mehr Produkte bestellt werden, als insgesamt überhaupt in allen Geschäften (engl. stores) verfügbar sind. Im Beispiel-Skript gibt es insgesamt 550 Fernseher:
1
2
3
4
| -- Insert some products
INSERT INTO products(prod_id,name,store,stock) VALUES (NULL,'Fernseher','Berlin',250)$
INSERT INTO products(prod_id,name,store,stock) VALUES (NULL,'Fernseher','Potsdam',200)$
INSERT INTO products(prod_id,name,store,stock) VALUES (NULL,'Fernseher','Bremen',100)$ |
-- Insert some products
INSERT INTO products(prod_id,name,store,stock) VALUES (NULL,'Fernseher','Berlin',250)$
INSERT INTO products(prod_id,name,store,stock) VALUES (NULL,'Fernseher','Potsdam',200)$
INSERT INTO products(prod_id,name,store,stock) VALUES (NULL,'Fernseher','Bremen',100)$
Wird nun die folgende Anfrage gestellt, dann werden mehr als 550 Fernseher bestellt und es kommt zu einem Trigger-Fehler:
1
| INSERT INTO orders(user_id,product,amount) VALUES (1,'Fernseher',1300)$ |
INSERT INTO orders(user_id,product,amount) VALUES (1,'Fernseher',1300)$
Um diesen Fehler zu beseitigen, habe ich den check_amount
-Trigger erweitert, so dass eine Stored Procedure namens availableQuantity
abgefragt wird, welche dann Auskunft darüber liefert, wie hoch die verfügbare Anzahl eines Produktes ist. Ist diese Anzahl kleiner als die bestellte Menge, dann wird die bestellte Menge einfach auf die maximal verfügbare Anzahl gesetzt.
Weiterlesen …
Letzte Kommentare