{"id":438,"date":"2010-10-07T20:20:55","date_gmt":"2010-10-08T01:20:55","guid":{"rendered":"http:\/\/anvil-of-time.com\/wordpress\/?p=438"},"modified":"2021-03-09T13:25:26","modified_gmt":"2021-03-09T18:25:26","slug":"powerbuilder-gotcha-malformed-imbedded-sql","status":"publish","type":"post","link":"https:\/\/anvil-of-time.com\/powerbuilder\/powerbuilder-gotcha-malformed-imbedded-sql\/","title":{"rendered":"PowerBuilder &#8216;Gotcha&#8217; &#8211; Malformed Imbedded SQL"},"content":{"rendered":"<p>I came across a statement like this while tracking down a separate issue and at first didn&#8217;t think much of it since it wasn&#8217;t related to the problem at hand. However, when running my process through the debugger I noticed a SQL error which caught my attention.<\/p>\n<pre>&lt;code&gt;UPDATE dbo.shipperDetail\nSET contractId = (SELECT max(docId) \n\t\t\tFROM dbo.orderHeader\n\t\t\tWHERE dbo.shipperDetail.catalogNo = dbo.orderHeader.catalogNo\n\t\t\tAND dbo.shipperDetail.partNo = dbo.orderHeader.partNo\n\t\t\tAND dbo.shipperDetail.customerNo = dbo.orderHeader.customerNo\n\t\t\tand dbo.orderHeader.status = &#039;A&#039;)\nFROM dbo.shipper\nWHERE&lt;strong&gt; dbo.shipperDetail =&lt;\/strong&gt; :al_ship_id -- what column?\nAND dbo.shipper.shipperNo = dbo.shipperDetail.shipperNo\nAND dbo.shipper.shipFlag = &#039;N&#039;\nUSING SQLCA;\nCOMMIT;&lt;\/code&gt;<\/pre>\n<p>Notice the WHERE clause.<\/p>\n<p>Since SQLCA.SQLCode was not checked after the initial UPDATE statement, the error was not caught. This was in a production application for several years. Remember that only imbedded SELECT statements are validated when you &#8216;compile&#8217; or save a script.<\/p>\n\n\n<p>Updated March 2021<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I came across a statement like this while tracking down a separate issue and at first didn&#8217;t think much of it since it wasn&#8217;t related to the problem at hand. However, when running my process through the debugger I noticed a SQL error which caught my attention. &lt;code&gt;UPDATE dbo.shipperDetail SET contractId = (SELECT max(docId) FROM&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,3,10],"tags":[12,16],"_links":{"self":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/438"}],"collection":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/comments?post=438"}],"version-history":[{"count":7,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/438\/revisions"}],"predecessor-version":[{"id":1859,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/438\/revisions\/1859"}],"wp:attachment":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/media?parent=438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/categories?post=438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/tags?post=438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}