Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » setting parameters
setting parameters [message #718594] Wed, 24 August 2011 15:31 Go to next message
marc.marshall is currently offline marc.marshall
Messages: 30
Registered: June 2011
Member
I have a Dataset that I have created in Java and it contains a BeforeOpen event handler. I dynamically create the prepared statement query and it is dependent on the three Report parameters values to what the prepared statement query will look like with in the BeforeOpen event handler. I could have 0 - 3 parameters that need to be populated on my dataset when the prepared statement is created. Is there any way to populate my dataset parameters in the BeforeOpen method on my dataset? Thanks for your suggestions and time.

Thanks,

Marc
Re: setting parameters [message #718611 is a reply to message #718594] Wed, 24 August 2011 15:56 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

You can access a data set parameter in the beforeOpen using inputParams
array.

inputParams["param_1"] = somevalue;

Jason

On 8/24/2011 3:31 PM, marc.marshall wrote:
> I have a Dataset that I have created in Java and it contains a
> BeforeOpen event handler. I dynamically create the prepared statement
> query and it is dependent on the three Report parameters values to what
> the prepared statement query will look like with in the BeforeOpen event
> handler. I could have 0 - 3 parameters that need to be populated on my
> dataset when the prepared statement is created. Is there any way to
> populate my dataset parameters in the BeforeOpen method on my dataset?
> Thanks for your suggestions and time.
>
> Thanks,
>
> Marc
Re: setting parameters [message #718615 is a reply to message #718611] Wed, 24 August 2011 16:42 Go to previous messageGo to next message
marc.marshall is currently offline marc.marshall
Messages: 30
Registered: June 2011
Member
Jason,

I have a Java Class with a BeforeOpen method that I have created to build the dataset query. I have tried to do this in the javascript BeforeOpen on my dataset and it no longer executes my Java Class when this code is in place. In the BeforeOpen I have the IDataSetInstance and the IReportContext objects being passed into the method. Is there any equivalent code in Java to set the parameter of my dataset? Thanks for any time and suggestions.

Thanks,

Marc
Re: setting parameters [message #718626 is a reply to message #718615] Wed, 24 August 2011 17:33 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

What version of BIRT are you using? I can get it like the following in 2.6.

@Override
public void beforeOpen(IDataSetInstance dataSet,
IReportContext reportContext) {
try{
Logger logger =
reportContext.getReportRunnable().getReportEngine().getLogger();
logger.log(Level.INFO,"test");
Object val = dataSet.getInputParameters().get("param_1");
dataSet.setInputParameterValue("param_1", new Integer(10102));
}catch(Exception e){
e.printStackTrace();
}

}

Jason

On 8/24/2011 4:42 PM, marc.marshall wrote:
> Jason,
>
> I have a Java Class with a BeforeOpen method that I have created to
> build the dataset query. I have tried to do this in the javascript
> BeforeOpen on my dataset and it no longer executes my Java Class when
> this code is in place. In the BeforeOpen I have the IDataSetInstance and
> the IReportContext objects being passed into the method. Is there any
> equivalent code in Java to set the parameter of my dataset? Thanks for
> any time and suggestions.
> Thanks,
>
> Marc
Re: setting parameters [message #718834 is a reply to message #718626] Thu, 25 August 2011 09:19 Go to previous messageGo to next message
marc.marshall is currently offline marc.marshall
Messages: 30
Registered: June 2011
Member
Jason,

I am using the most current version of Birt. This code will apply a value to an existing param that was added using the GUI param entry interface of my dataset. If this param is not already created in the GUI interface of my dataset then I get an error saying it could not be found:
The following items have errors:


ReportDesign (id = 1):
+ Undefined data set parameter: param_1.
Undefined data set parameter: param_1. ( 1 time(s) )

Am I using this wrong? Thanks for your suggestions and time.

Thanks,

Marc


Re: setting parameters [message #718845 is a reply to message #718626] Thu, 25 August 2011 09:35 Go to previous messageGo to next message
marc.marshall is currently offline marc.marshall
Messages: 30
Registered: June 2011
Member
Jason,

I forgot to say that I am creating my prepared statement dynamically. I can have 0-3 parameters that are needed by the dynamically created prepared statement. Therefore I am unable to create the parameters up front or I will get errors. Thanks for your time and suggestions.

Thanks,

Marc
Re: setting parameters [message #718919 is a reply to message #718845] Thu, 25 August 2011 11:25 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Marc,

In that case I would not use a dataset parameter. Can you post an
example of how the query is being built? Where do you get the 0-3
parameters?

Jason

On 8/25/2011 9:35 AM, marc.marshall wrote:
> Jason,
>
> I forgot to say that I am creating my prepared statement dynamically. I
> can have 0-3 parameters that are needed by the dynamically created
> prepared statement. Therefore I am unable to create the parameters up
> front or I will get errors. Thanks for your time and suggestions.
> Thanks,
>
> Marc
Re: setting parameters [message #718930 is a reply to message #718919] Thu, 25 August 2011 11:58 Go to previous messageGo to next message
marc.marshall is currently offline marc.marshall
Messages: 30
Registered: June 2011
Member
Jason,

This is an example of how I build my prepared statement. There are 4 report parameters "name", "number", "type" and "company" this information is what builds the following prepared statement:

sql = sql
+ "select A.KYVENID, "
+ "A.VENNAME, "
+ "A.VENSTATUS, "
+ "A.VENPHONE, "
+ "A.XADATASTATUS, "
+ "A.XAAUDITUID, "
+ "A.XAAUDITTS, "
+ "A.COMPANY, "
+ "A.VENNUM, "
+ "A.VENABOUT, "
+ "A.VENCONTACT, "
+ "A.VENEMAIL, "
+ "A.VENSTREET, "
+ "A.VENCITY, "
+ "A.VENZIP, "
+ "A.REMARKS, "
+ "from DATA.VENDORINFO A, " + "DATA.MASTERLIST B ";

sql = sql + "where ";

if (vname != null) {
if (vname.length() != 0) {
searchPercent = vname.indexOf("%");
searchUnderscore = vname.indexOf("_");
textAdded = true;
if (searchPercent == -1 && searchUnderscore == -1) {
sql = sql + "A.VENNAME = ?";
} else {
sql = sql + "A.VENNAME like ?";
}
}
}
if (textAdded) {
sql = sql + " and ";
}

textAdded = false;
if (vnumber != null) {
if (vnumber.length() != 0) {
searchPercent = vnumber.indexOf("%");
searchUnderscore = vnumber.indexOf("_");
textAdded = true;
if (searchPercent == -1 && searchUnderscore == -1) {
sql = sql + "A.VENNUM = ?";
} else {
sql = sql + "A.VENNUM like ?";
}
}
}
if (textAdded) {
sql = sql + " and ";
}

textAdded = false;
if (vtype != null) {
if (vtype.length() != 0) {
searchPercent = vtype.indexOf("%");
searchUnderscore = vtype.indexOf("_");
textAdded = true;
if (searchPercent == -1 && searchUnderscore == -1) {
sql = sql + "B.MLDESCRIPTION = ?";
} else {
sql = sql + "B.MLDESCRIPTION like ?";
}
}
}

if (textAdded) {
sql = sql + " and ";
}

sql = sql + "A.COMPANY = ?"
+ " and B.KYMASTERLISTID = CAST(A.VENTYPE as INTEGER)";


dataset.setQueryText(sql);
Re: setting parameters [message #718962 is a reply to message #718930] Thu, 25 August 2011 12:20 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Marc,

I assume you want the ? tied to one of the report parameter? If so,
skip the ? and reference the report parameter directly like:

String myparm = reportContext.getParameterValue("name");
sql = sql + "A.VENNAME = " + myparm;

Jason

On 8/25/2011 11:58 AM, marc.marshall wrote:
> sql = sql + "A.VENNAME = ?";
Re: setting parameters [message #718971 is a reply to message #718962] Thu, 25 August 2011 12:53 Go to previous messageGo to next message
marc.marshall is currently offline marc.marshall
Messages: 30
Registered: June 2011
Member
Jason,

The reason that I was using ? in the prepared statement was to stop the user from sql injection. I had read that a prepared statement helps stop the user from sql injection. I do understand that this prepared statement may not work though. Do you have any thoughts or suggestion on this matter? Thanks for your help that you have been giving me.

Thanks,

Marc
Re: setting parameters [message #718993 is a reply to message #718971] Thu, 25 August 2011 13:29 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

If you are worried about sql injection, check and validate the values
before using them, or use session variables. You can access session
variables using
//js
reportContext.getHttpServletRequest().getSession().getAttribute("test");

in java it will depend on the container. I did the following in tomcat.
//added catalina.jar and servlet-api.jar to build path and used:

Object o = reportContext.getHttpServletRequest();
if( o instanceof org.apache.catalina.connector.RequestFacade){
RequestFacade co = (RequestFacade) o;
HttpSession ses = co.getSession();
Object myobj =ses.getAttribute("test");
}

Jason

On 8/25/2011 12:53 PM, marc.marshall wrote:
> Jason,
>
> The reason that I was using ? in the prepared statement was to stop the
> user from sql injection. I had read that a prepared statement helps stop
> the user from sql injection. I do understand that this prepared
> statement may not work though. Do you have any thoughts or suggestion on
> this matter? Thanks for your help that you have been giving me.
>
> Thanks,
>
> Marc
Re: setting parameters [message #719016 is a reply to message #718594] Thu, 25 August 2011 15:42 Go to previous message
marc.marshall is currently offline marc.marshall
Messages: 30
Registered: June 2011
Member
Jason,

That helps and thank you for your suggestions and help with this topic.


Thanks,

Marc
Previous Topic:Calendar Gif Artifact
Next Topic:Chart Interactivity dropdown menu - Mac
Goto Forum:
  


Current Time: Tue Jul 29 19:09:43 EDT 2014

Powered by FUDForum. Page generated in 0.02600 seconds