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)
how to access query result
rali
Hello,
does anybody know how to access the query result of a report. I'd like to not render a report if one or more queries that it does is empty, otherwise i get a report with an empty template.
Thank you
Rali
Find more posts tagged with
Comments
rali
Hi all,<br />
<br />
in case someone else wondered how to do the same thing:<br />
<br />
<a class='bbc_url' href='
http://www.eclipse.org/birt/phoenix/deploy/reportEngineAPI.php#idataextractiontask'>Report
Engine API</a><br />
<br />
Rali
rali
Hi all,
i thought that using IDataExtractionTask my problem was solved, but after a while i found out that the data i was getting wasn't the one i was interested to get.
I'm probably getting something wrong but it seems to me that asking if the queries that i made returned a result is a pretty basic functionality that everyone needs. I mean there is no point in a report that doesn't contain data. But i can't get any info on how to access the query result only.
IDataExtractionTask gives me a resultSetList that contains 10 items. Having in mind that my report has only two queries. It seems like it contains all the data that is in the report, but i can't find a way to isolate only the query results.
Any ideas?
Thank you!
Rali
JasonW
Rali,<br />
<br />
The data extraction task pulls the data that is actually bound to elements. So if you want to check a query you can bind it to a table and then call the data extraction task on the table. (Name the table it makes it easier to specify which report item you want to extract).<br />
<br />
You may also want to just use a visibility expression to hide an empty table. You can then use a label to explain the report has no data.<br />
<a class='bbc_url' href='
http://www.birt-exchange.com/forum/eclipse-birt-newsgroup-mirror/13379-checking-rowcount-dataset.html'>http://www.birt-exchange.com/forum/eclipse-birt-newsgroup-mirror/13379-checking-rowcount-dataset.html</a><br
/>
<br />
Jason
JasonW
Rali,
If you stick with the data extract task set the name of the table like this:
task.selectResultSet( thenameofyourboundtable);
Jason
rali
Hi Jason,<br />
<br />
thank you so much for your answer, i've been trying for weeks to find an answer.<br />
I'm trying to create a chain of pdf reports and then put them toghether in one pdf file which front page is sort of a "contents" that indicates the page numbers of every single report. So if i hide the table that has no result i'd still have a blank page or a page with only the header and footer in it.<br />
Using the data extraction task the way you told me works perfectly. If the table is empty the pdf is not rendered and not included in the contents page.<br />
Maybe sub reports or something like that would be a better solution, i chose to create more separate pdf files and then merge them in a single file 'cause i thought that it would be easier :$ <br />
Just one last question: i'm calling the method <em class='bbc'>getPageCount()</em> on a report document object expecting to get the total number of pages, instead i get always 1 as a result. I also tried to call the <em class='bbc'>getTotalPage()</em> and the <em class='bbc'>getPageCount()</em> on an a render task object but i still get 1 as a result. The pdf file has 3 pages. I'm surely doing something wrong
<br />
My executeReport mothod:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
public static int executeReport(HashMap param) throws EngineException, BirtException {
IReportRunnable design = null;
design = reportEngine.openReportDesign("d:/eclipse/workspace/Designs/" + (String) param.get("reportDesign") + ".rptdesign");
IRunTask runTask = reportEngine.createRunTask(design);
runTask.setParameterValues(param);
runTask.run("c:/birt/temps/test.rptdocument");
IReportDocument reportDocument = reportEngine.openReportDocument("c:/birt/temps/test.rptdocument");
/**********************************************************/
IDataExtractionTask iDataExtract = reportEngine.createDataExtractionTask(reportDocument);
ArrayList resultSetList = (ArrayList) iDataExtract.getResultSetList();
iDataExtract.selectResultSet("QueryResultTable");
IExtractionResults iExtractResults = iDataExtract.extract();
IDataIterator iData = null;
try {
if (iExtractResults != null) {
iData = iExtractResults.nextResultIterator();
if (iData.isEmpty()) {
iData.close();
iDataExtract.close();
return 0;
}
iData.close();
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
iDataExtract.close();
/***********************************************************/
IRenderTask renderTask = reportEngine.createRenderTask(reportDocument);
PDFRenderOption options = new PDFRenderOption();
options.setOutputFileName("c:/birt/temps/" + (String) param.get("tempName") + ".pdf");
options.setOutputFormat("pdf");
renderTask.setRenderOption(options);
renderTask.render();
reportDocument.close();
return (int) renderTask.getPageCount();
}
</pre>
<br />
<br />
<br />
Once again, thank you very much.<br />
<br />
Regards,<br />
Rali
JasonW
Rali,
The getPageCount should be used on the rptdocument.
document = engine.openReportDocument("output/resample/mcb.rptdocument");
long pgcnt = document.getPageCount();
Jason