Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Using parameters - report results are outside the given range selected (time)
summercamp
<p>I am not a SQL expert , and I am an absolute beginner with BIRT so please bear with me.</p>
<p> </p>
<p>I am trying to write a report where the user can input a given time range, and the result will show data from a postgres database within those times.</p>
<p> </p>
<p>I'm using parameters for the user input.</p>
<p> </p>
<p>So when the user runs the report he gives a start time and an end time.</p>
<p> </p>
<p>But the result includes times which are outside the range, usually before the start time rather than after the end time.</p>
<p> </p>
<p>When the same query is executed in the DB (with the '?' hardcoded) I get the correct times shown.</p>
<p> </p>
<p>When I repeat the query in BIRT with the times hardcoded I still get results outside the time range.</p>
<p> </p>
<p>I think this shows that the problem is with BIRT and not the query.</p>
<p> </p>
<p>Is there something that needs to be changed in the parameter settings of BIRT so that only results within the time range specified by the user are returned? </p>
<p> </p>
<p>thanks in advance</p>
<p> </p>
<p>summer </p>
<p> </p>
<p>PS I am using Eclipse version Neon.2 Release (4.6.2) with Postgres v9.5</p>
<p> </p>
<p> </p>
Find more posts tagged with
Comments
Clement Wong
<p>Please let us know the SQL statement when you run it from a database client, outside of BIRT that works.</p>
<p> </p>
<p>Please attach your .rptdesign. Please remove the database URL and credentials, in case there is sensitive information.</p>
summercamp
<p>Hi Clement<br>
<br>
Thanks for your reply. Below is the DB code with text changes for security. The parts in bold text are replaced in BIRT with the parameter code '?'<br>
<br>
I can't see how to attach files though. I can cut and paste the rpt data if you wish.<br>
</p>
<p><span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">select</span></span><span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;"> DB.device.</span>name,<br>
DB.alarm_node.node_id,<br>
DB.alarm_node.alarm_time,<br>
DB.alarm_node.clear_time,<br>
to_char(DB.alarm_node.alarm_time,</span> <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">'day'</span></span>),<br>
DB.alarm_node.description_key<br>
from<span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;"> DB.alarm_node,</span>DB.device<br>
where DB.device.</span>node_id <span style="font-size:10.5pt;">=</span> <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">DB</span></span>.alarm_node.node_id<br>
and<span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;"> DB.alarm_node.</span>alarm_time <span style="font-size:10.5pt;">>=</span></span> <strong><span style="font-family:arial, sans-serif;">‘2017-05-01’</span></strong> <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">and</span></span> <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">DB</span></span>.alarm_node.alarm_time <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;"><</span></span> <strong><span style="font-family:arial, sans-serif;">‘2017-05-03’</span></strong><br><span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">and</span></span> <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">((</span></span>to_char(DB.alarm_node.alarm_time,'hh24:mi:ss') <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">between</span></span> <strong><span style="font-family:arial, sans-serif;">’18:00:00’</span></strong> <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">and</span></span> <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">'23:59:59'</span></span> <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">or</span></span><br>
to_char(DB.alarm_node.alarm_time,'hh24:mi:ss') <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">between</span></span> <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">'00:00:00'</span></span> <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">and</span></span> <strong><span style="font-family:arial, sans-serif;">’06:00:00’</span></strong><span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">)</span></span><br>
<span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;"> or</span></span> <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">trim(</span></span>to_char(DB.alarm_node.alarm_time, <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">'day'</span></span>)) <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">in</span></span> <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">(</span></span>'saturday','sunday'))<br>
and<span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;"> DB.alarm_node.</span>severity <span style="font-size:10.5pt;">=</span></span> <span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;">1</span></span><br>
order<span style="font-family:arial, sans-serif;"><span style="font-size:10.5pt;"> by</span> <span style="font-size:10.5pt;">alarm_time</span></span></p>
Clement Wong
<p>We'll need the report design to analyze.</p>
<p> </p>
<p> </p>
<p><em>> I can't see how to attach files though.</em></p>
<p> </p>
<p>When you reply, click on the "More Reply Options".</p>
<p> </p>
<p>Then under Attach Files, you'll need to Browse... for the file, and click on "Attach This File".</p>
<p> </p>
<p>Finally, click on "Add Reply".</p>
summercamp
<p>thanks Clement. File attached.</p>
Clement Wong
<p>Thanks for attaching the .rptdesign. My hunch is that the Data Set parameter substitutions are not being set to the format that you're expecting.</p>
<p> </p>
<p>Are you able to log the query that is received by the database server?</p>
<p> </p>
<p>We can also use an alternative method of substituting parameters in the beforeOpen event by replacing element of the SQL select statement with<em> this.queryText</em>.</p>
<p> </p>
<p>First, in the Data Set's Query, change the ?s to actual (dummy) values:</p>
<p> </p>
<p style="margin-left:40px;"><span style="font-family:'courier new', courier, monospace;">...<br>
and DB.alarm_node.alarm_time >=<strong> <span style="color:#b22222;">'2001-01-01'</span></strong> and DB.alarm_node.alarm_time <<strong> <span style="color:#b22222;">'2002-02-02'</span></strong><br>
and ((to_char(DB.alarm_node.alarm_time,'hh24:mi:ss') between <span style="color:#b22222;"><strong>'03:03:03'</strong></span> and '23:59:59' or<br>
to_char(DB.alarm_node.alarm_time,'hh24:mi:ss') between '00:00:00' and <span style="color:#b22222;"><strong>'04:04:04'</strong></span>)<br>
or trim(to_char(DB.alarm_node.alarm_time, 'day')) in ('saturday','sunday'))<br>
...</span></p>
<p style="margin-left:40px;"> </p>
<p> </p>
<p>Then in the Data Set's <em>beforeOpen </em>event, we will do the substitution of each parameter value. Now, I'm not sure what format you have allowed the end user to enter the date and time. I see the Prompt Text as "<em>enter start date and time (yyyy:mm:dd 24hh:mm:ss)</em>"</p>
<pre class="_prettyXprint _lang-">
// SQL snippet
//
// and DB.alarm_node.alarm_time >= '2001-01-01' and DB.alarm_node.alarm_time < '2002-02-02'
// and ((to_char(DB.alarm_node.alarm_time,'hh24:mi:ss') between '03:03:03' and '23:59:59' or
// to_char(DB.alarm_node.alarm_time,'hh24:mi:ss') between '00:00:00' and '04:04:04')
//
//
// Example if 'start date' where entered as 2017-05-18 08:18:26
// and if 'end end' where entered in the same yyyy-MM-dd hh:mm:ss format
this.queryText = this.queryText.replace("2001-01-01", params["start date"].value.split(" ")[0]);
this.queryText = this.queryText.replace("03:03:03", params["start date"].value.split(" ")[1]);
this.queryText = this.queryText.replace("2002-02-02", params["end date"].value.split(" ")[0]);
this.queryText = this.queryText.replace("04:04:04", params["end date"].value.split(" ")[1]);
</pre>
<p>You can log the this.queryText at each step to make sure the formatting/syntax is what the database is expecting. SInce you are using Open Source BIRT, whereas in commercial BIRT, you can write to Eclipse UI's Error Log directly, you'll need to relaunch Eclipse, and open "eclipsec.exe". The debug statement will be written to a separate window.</p>
<p> </p>
<p>You can add a debug statement like this:<br><span style="font-family:'courier new', courier, monospace;"> java.lang.System.out.println( this.queryText );</span><br>
<br>
</p>
summercamp
<p>Hi Clement</p>
<p> </p>
<p>I will try your solution, thanks for that.</p>
<p> </p>
<p>In the meantime, your statement :</p>
<p> </p>
<p><strong><em>"<span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">My hunch is that the Data Set parameter substitutions are not being set to the format that you're expecting."</span></em></strong></p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">doesn't follow the fact that the results will show data outside the time range even when I remove the parameters and hardcode the dates and times (from my original question):</span></p>
<p> </p>
<p><strong><em><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">"</span><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">When I repeat the query in BIRT with the times hardcoded I still get results outside the time range."</span></em></strong></p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">I will report back on my findings
</span></p>
Clement Wong
<p>Thanks for pointing that out. We can skip the substitution part for now.</p>
<p> </p>
<p>However, we would still want to see what query the database is receiving as compared to what the SQL statement is being sent.</p>
summercamp
<p>thanks Clement, I will see if I can extract that information for you</p>
summercamp
<p>Please can you let me know whether postgres logs this information somewhere? If it does what would the log be called? If not is there something I can add to the query to generate a log that will show what the database is receiving from BIRT?</p>
<p> </p>
<p>thanks again</p>
<p> </p>
<p>summer </p>
Clement Wong
<p>Yes, you'll need to enable logging on the Postgres server side.</p>
<p> </p>
<p>This was originally asked for Postgres 8.3, and there is a reply that the steps work for Postgres 9.5 (the version that you're using).</p>
<p><a data-ipb='nomediaparse' href='
https://stackoverflow.com/questions/722221/how-to-log-postgresql-queries'>https://stackoverflow.com/questions/722221/how-to-log-postgresql-queries</a></p>
;
Siva Rao
<p>Hi i have 2 parameters named as starttiem and endtime.It's datatype is time.</p>
<p>when i want to compare them it shows error as string is passing from the parameters.</p>
<p>how can i convert string to time format(12Hrs format) and compare those two times?</p>
<p> </p>
<p>Thanks in advance.</p>
Clement Wong
<p>Siva Rao,</p>
<p> </p>
<p>This is a different topic, and would be good to know more information about your issue.</p>
<p> </p>
<p>What version of BIRT you are using? Also, is it open source, or commercial?</p>
<p> </p>
<p>What database are you using?</p>
<p> </p>
<p>What is your current SQL statement that is being passed to the database server, and what is the syntax of the SQL that you would like it look like?</p>
<p> </p>
<p>Is there an exact error message that you can share?</p>