Hi,
I have the following stored procedure:
Code:
CREATE PROCEDURE create_order(IN inCustomerId INT, IN inProductId INT)
BEGIN
DECLARE orderId INT;
DECLARE exit handler for sqlwarning rollback;
DECLARE exit handler for sqlexception rollback;
START TRANSACTION;
-- Insert a new record into orders and obtain the new order ID
INSERT INTO tbl_orders (order_date, customer_id)
VALUES (NOW(), inCustomerId);
-- Obtain the new Order ID
SELECT LAST_INSERT_ID() INTO orderId;
-- Insert order items in order_items table
INSERT INTO tbl_order_items (order_id, pd_id, pd_name, qty, pd_price)
SELECT orderId
, pd.pd_id
, pd.pd_name
, pd.pd_qty
, pd.pd_price
FROM tbl_products pd
WHERE pd.pd_id = inProductId;
-- Insert credits in to credits acct only if pd type is 1, 2 or 3
INSERT INTO tbl_customer_credit_acct (customer_id, pd_id, qty)
SELECT inCustomerId, pd.pd_id, pd.qty
FROM tbl_products pd
WHERE pd.pd_id = inProductId AND (pd.pd_type = 1 OR pd.pd_type = 2 OR pd.pd_type = 3);
-- Return the Order ID
SELECT orderId;
COMMIT;
What I have found is that if a customer orders a product that is not of product type 1, 2, or 3 the procedure rolls back becuase the final insert produces a not found state.
How would you add a continue handler for not found to this procedure?
I tried adding the following but i get a sql syntax error:
Code:
DECLARE continue handler for not found;
Any help would be appreciated.