A3.4 Campus ADD_PLACE Procedure |
|
Finally we will create a stored procedure for the CAMPUS database named ADD_PLACE(campus, cuisine, place, error, msg) for inserting a new campus cuisine place. The first three parameters are inputs and the last two are outputs. Use a transaction and the primary keys of the tables to reject entries that would violate the constraints. ADD_PLACE will perform the following transaction. If the campus is in CAMPUSES and the cuisine is in CUISINES then if the place is not in PLACE_CUISINES it is added. The cuisine field can be empty if the place is already in PLACE_CUISINES. Finally, the campus and place are added to CAMPUS_PLACES. Define the error outputs as: "0" for no error, 1 not a valid campus, 2 not a valid cuisine, 3 the place is already in PLACE_CUISINES as a different cuisine, 4 there's already a cuisine of that type at that campus. Start with this code: /* PROCEDURE ADD_PLACE(IN campus1 VARCHAR(10), IN cuisine1 VARCHAR(25), IN place1 VARCHAR(50), OUT `error` INT, OUT msg VARCHAR(200)) */ **************; The input parameters are campus1, cuisine1, place1 followed by output parameters error, msg. The lines with asterisks (**************)indicate missing SQL statements. Your assignment is to fill in the missing SQL statements so the procedure works as defined. Watch this video for help. To test your routine, first make sure you are viewing the Database on the screen with the list of tables. Then click the Routines tab to access your ADD_PLACE routine. Click Execute and a form will appear to enter the input arguments for your routine.
To test error code 1, enter a non-existent Campus for campus1 (e.g., XYZ), any Cuisine for cuisine1 (e.g., Burgers) and any Place for place1 (e.g., Teddy's Bigger Burgers). To test error code 2, enter an invalid Cuisine for cuisine1 (e.g., Hamberders) along with a valid Campus for campus1 (e.g., UHM) and a valid Place for place1 (e.g., Teddy's Bigger Burgers). To test error code 3, enter a Place for place1 that is not in the PLACE_CUISINES table (e.g., Win-Spuntino) along with a valid campus (e.g., UHM) and cuisine (e.g., Italian). To test error code 4, enter a place with a cuisine for a campus that already has a different place of that cuisine. First, make sure there is already a Burger place for UHM (e.g., Teddys Bigger Burgers) and that there is another Burgers place (e.g., Big City Diner Waialae). Then try campus1 = UHM, cuisine1 = Burgers, place1 = Big City Diner Waialae. To test error code 0, you should try something that you know will work. Assuming there is no favorite Nepalese restaurant yet for UHWO, you can try campus1 = UHWO, cuisine1 = Nepalese, and place1 = Himalayan Kitchen.
|