{"id":374,"date":"2015-04-22T17:47:35","date_gmt":"2015-04-22T22:47:35","guid":{"rendered":"http:\/\/thenoyes.com\/littlenoise\/?p=374"},"modified":"2015-04-22T17:51:24","modified_gmt":"2015-04-22T22:51:24","slug":"breakpoints-for-stored-procedures-and-functions","status":"publish","type":"post","link":"https:\/\/thenoyes.com\/littlenoise\/?p=374","title":{"rendered":"Breakpoints for stored procedures and functions"},"content":{"rendered":"<p>and without creating a table to pass the state around (really just an excuse to use the named locks feature).<\/p>\n<pre>DELIMITER \/\/\r\nDROP FUNCTION IF EXISTS SET_BREAKPOINT\/\/\r\nCREATE FUNCTION SET_BREAKPOINT()\r\nRETURNS tinyint\r\nNO SQL\r\nBEGIN\r\n\t-- Acquire lock 1\r\n\t-- Wait until lock 2 is taken to signal that we may continue\r\n\tDO GET_LOCK(CONCAT('lock_1_', CONNECTION_ID()), -1);\r\n\tREPEAT\r\n\t\tDO 1;\r\n\tUNTIL IS_USED_LOCK(CONCAT('lock_2_', CONNECTION_ID())) END REPEAT;\r\n\tDO RELEASE_LOCK(CONCAT('lock_1_', CONNECTION_ID()));\r\n\r\n\t-- Acquire lock 3 to acknowledge message to continue.\r\n\t-- Wait for lock 2 to be released as signal of receipt.\r\n\tDO GET_LOCK(CONCAT('lock_3_', CONNECTION_ID()), -1);\r\n\tREPEAT\r\n\t\tDO 1;\r\n\tUNTIL IS_FREE_LOCK(CONCAT('lock_2_', CONNECTION_ID())) END REPEAT;\r\n\tDO RELEASE_LOCK(CONCAT('lock_3_', CONNECTION_ID()));\r\n\r\n\tRETURN 1;\r\nEND\/\/\r\n\r\nDROP FUNCTION IF EXISTS NEXT_BREAKPOINT\/\/\r\nCREATE FUNCTION NEXT_BREAKPOINT(connection_id int)\r\nRETURNS tinyint\r\nNO SQL\r\nBEGIN\r\n\t-- Acquire lock 2 as a signal to go past the breakpoint\r\n\t-- Wait until lock 3 is taken as signal of receipt.\r\n\tDO GET_LOCK(CONCAT('lock_2_', connection_id), -1);\r\n\tREPEAT\r\n\t\tDO 1;\r\n\tUNTIL IS_USED_LOCK(CONCAT('lock_3_', connection_id)) END REPEAT;\r\n\tDO RELEASE_LOCK(CONCAT('lock_2_', connection_id));\r\n\r\n\tRETURN 1;\r\nEND\/\/\r\n\r\nDROP PROCEDURE IF EXISTS test_the_breakpoints\/\/\r\nCREATE PROCEDURE test_the_breakpoints()\r\nNO SQL\r\nBEGIN\r\n\tSELECT CONCAT('In another session: DO NEXT_BREAKPOINT(', CONNECTION_ID(), ');') as `instructions`;\r\n\r\n\tDO SET_BREAKPOINT();\r\n\r\n\tSELECT 'do it again' as `now:`;\r\n\r\n\tDO SET_BREAKPOINT();\r\n\r\n\tSELECT 'end' as `the`;\r\nEND\/\/\r\nDELIMITER ;\r\n\r\nCALL test_the_breakpoints();\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>and without creating a table to pass the state around (really just an excuse to use the named locks feature). DELIMITER \/\/ DROP FUNCTION IF EXISTS SET_BREAKPOINT\/\/ CREATE FUNCTION SET_BREAKPOINT() RETURNS tinyint NO SQL BEGIN &#8212; Acquire lock 1 &#8212; Wait until lock 2 is taken to signal that we may continue DO GET_LOCK(CONCAT(&#8216;lock_1_&#8217;, CONNECTION_ID()), [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[],"class_list":["post-374","post","type-post","status-publish","format-standard","hentry","category-mysql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2IBF1-62","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=374"}],"version-history":[{"count":5,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/374\/revisions"}],"predecessor-version":[{"id":379,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/374\/revisions\/379"}],"wp:attachment":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}