{"id":220,"date":"2010-07-16T20:22:05","date_gmt":"2010-07-17T01:22:05","guid":{"rendered":"http:\/\/anvil-of-time.com\/wordpress\/?p=220"},"modified":"2021-03-09T00:42:37","modified_gmt":"2021-03-09T05:42:37","slug":"powerbuilder-gotcha-datawindow-retrieval-arguments","status":"publish","type":"post","link":"https:\/\/anvil-of-time.com\/powerbuilder\/powerbuilder-gotcha-datawindow-retrieval-arguments\/","title":{"rendered":"PowerBuilder &#8216;Gotcha&#8217; &#8211; Datawindow retrieval arguments"},"content":{"rendered":"<p>So I&#8217;m working on a scheduling process and I have a datawindow object which takes a number of arguments.<br \/>I have them set up as al_pro_id (long), adt_end (datetime), adt_start (datetime), al_resource_id[] (long array), and al_dept_id (long).<\/p>\n<p>To save from maintaining two separate objects, I used this object for a datawindow as well as for datastores which check things behind the scene. Nothing here is unusual so far.<\/p>\n<p>In my code I inadvertently reversed the end date and the start date in one of my retrieves. Not surprising the retrieve returned no rows. So I check the sqlca, make sure the assignment of the datawindow object is correct, and validate the SQL from the object in a SQL session with the arguments put in place &#8211; all were fine.<\/p>\n<p>When I put a debug in the transaction object sqlpreview event this is what I got:<\/p>\n<p>Date parms in reverse order<\/p>\n<pre name=\"code\" class=\"SQL\">select rs.resource_id\n, rs.resource_ds\n, rs.bok_qy\n, qty_bok = ( select count(*) from RR_EVENT_RESOURCE_SCHED ers\n\t\t\tWHERE ers.resource_id = rg.resource_id\n\t\t\tAND ers.evt_start_ts &lt; {ts &#039;2010-07-16 09:15:00.000&#039;}\n\t\t\tAND ers.evt_stop_ts &gt; {ts &#039;2010-07-16 10:15:00.000&#039;}\n\t\t\tAND ers.evt_resource_sch_id not in (89407))\n, rrg.num_req_qty\n, pr.proc_name\n, chosen = CASE WHEN (select count(*) from RR_EVENT_RESOURCE_SCHED ersd WHERE ersd.resource_id = rg.resource_id\n\tAND ersd.evt_resource_sch_id in ({ts &#039;2010-07-16 09:15:00.000&#039;})) &gt; 0 THEN &#039;Y&#039; ELSE &#039;N&#039; END\nfrom RR_PROCESS pr \njoin RR_REQUIRED_RESOURCE_GROUP rrg on pr.pro_id = rrg.pro_id\njoin RR_SCHEDULING_GROUP sg on rrg.sch_grp_id = sg.sch_grp_id \njoin RR_RESOURCE_GROUP rg on sg.sch_grp_id = rg.sch_grp_id\njoin RR_RESOURCE rs on rg.resource_id = rs.resource_id\nleft outer join RR_ROOM rm on rg.resource_id = rm.resource_id and rm.row_status_cd = &#039;A&#039; and rm.or_dpt_id = {ts &#039;2010-07-16 10:15:00.000&#039;}\nleft outer join RR_PERSON p on rs.persn_id = p.persn_id and p.row_status_cd = &#039;A&#039;\nwhere IsNull(rm.resource_id,0) = 0 and IsNull(p.persn_id,0) = 0\nand p.pro_id = 89407<\/pre>\n<p>\u00a0<\/p>\n<p>Date parms in correct order<\/p>\n<pre name=\"code\" class=\"SQL\">select rs.resource_id\n, rs.resource_ds\n, rs.bok_qy\n, qty_bok = ( select count(*) from RR_EVENT_RESOURCE_SCHED ers \n\t\t\tWHERE ers.resource_id = rg.resource_id\n\t\t\tAND ers.resource_evt_start_ts &lt; {ts &#039;2010-07-16 10:15:00.000&#039;}\n\t\t\tAND ers.resource_evt_stop_ts &gt; {ts &#039;2010-07-16 09:15:00.000&#039;}\n\t\t\tAND ers.evt_resource_sch_id not in (89407))\n, rrg.num_req_qy\n, pr.proc_name\n, chosen = CASE WHEN (select count(*) from RR_EVENT_RESOURCE_SCHED ersd\n\t\t\tWHERE ersd.resource_id = rg.resource_id\n\t\t\tAND ersd.evt_resource_sch_id in (89407)) &gt; 0 THEN &#039;Y&#039; ELSE &#039;N&#039; END\nfrom RR_PROCESS pr\njoin RR_REQUIRED_RESOURCE_GROUP rrg on pr.pro_id = rrg.pro_id\njoin RR_SCHEDULING_GROUP sg WITH on rrg.sch_grp_id = sg.sch_grp_id \njoin RR_RESOURCE_GROUP rg on sg.sch_grp_id = rg.sch_grp_id\njoin RR_RESOURCE rs on rg.resource_id = rs.resource_id\nleft outer join RR_ROOM rm on rg.resource_id = rm.resource_id and rm.row_status_cd = &#039;A&#039; and rm.or_dpt_id = 1\nleft outer join dbo.RR_PERSON p on rs.persn_id = p.persn_id and p.row_status_cd = &#039;A&#039;\nwhere IsNull(rm.resource_id,0) = 0 and IsNull(p.persn_id,0) = 0\nand p.pro_id = 8202<\/pre>\n<p>\u00a0<\/p>\n<p>Notice the mis-assignment of the arguments in the first statement. The only reason this didn&#8217;t throw an error is because the timestamp values are converted to numeric in MS SQLServer. I don&#8217;t really have an explanation as to why Powerbuilder was submitting the SQL in the first statement. I guess just make sure you validate the order of the arguments you send in a retrieve.<\/p>\n\n\n<p>Updated March 2021<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So I&#8217;m working on a scheduling process and I have a datawindow object which takes a number of arguments.I have them set up as al_pro_id (long), adt_end (datetime), adt_start (datetime), al_resource_id[] (long array), and al_dept_id (long). To save from maintaining two separate objects, I used this object for a datawindow as well as for datastores&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":[21,12,16,15],"_links":{"self":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/220"}],"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=220"}],"version-history":[{"count":11,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/220\/revisions"}],"predecessor-version":[{"id":1764,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/220\/revisions\/1764"}],"wp:attachment":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/media?parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/categories?post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/tags?post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}