Jump to content
Changes to the Jaspersoft community edition download ×

computed query string - impossible?

2005 IR Help

Recommended Posts

By: Alexandru Cârstoiu - acarstoiu

computed query string - impossible?

2004-07-29 05:40



The problem is simple. $V{...} is NOT accepted by the JasperReports engine in the report query string. So how can I compute (parts of) the query string, based on the parameters received?


To be more specific, I have to perform a search and replace on the parameter of a report before actually using its value in the query. And I can't do it before running the report.









By: Mykel Alvis - evilarchitect

RE: computed query string - impossible?

2004-07-29 06:57

First of all, you're correct. Variables aren't until much later.


The simplest method is to pass the query string or parts of it in as a parameter. Generate the query outside of JasperReports and supply it as a parameter using $P!{xx}


I'm unsure if it's possible to use a scriptlet and get a "default" value to a parameter as a result of a scriptlet call. That's seems a little hokey, but maybe it'd work.









By: Alexandru Cârstoiu - acarstoiu

RE: computed query string - impossible?

2004-07-30 04:39

Thanks for the tip. It may very well work, but it's not that documented (check the API and you'll see).


I discovered that if you declare a (not for promting) parameter with a default value that is an expression depending on previously declared parameters, IT WORKS!







By: Mykel Alvis - evilarchitect

RE: computed query string - impossible?

2004-07-30 07:41

From the tutorial:


There are two possible ways to use parameters in the query:


1. The parameters are used like normal java.sql.PreparedStatement parameters using the following syntax:




2. Sometimes is useful to use parameters to dynamically modify portions of the SQL query or to pass the entire SQL query as a parameter to the report filling routines. In such a case, the syntax differs a little, like in the following example:


SELECT * FROM Orders ORDER BY $P!{OrderByClause}


This issue has actually be hashed around on the forum a bit as well. It comes up A LOT.


I'm wondering if the order of the parameters is critical. Like, if $P{foo} depends on $P{bar}, then if foo has to come after bar in the parameters definitions or if JR is smart enough to understand dependencies. I guess I could go check the code.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...