Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Change query Text based on the database type from JS Script event handler(changing database query based on the connected database)
Change query Text based on the database type from JS Script event handler [message #768778] Tue, 20 December 2011 19:25 Go to next message
Alessio Pollero is currently offline Alessio PolleroFriend
Messages: 74
Registered: August 2011
Member
I want to change the query text of a datasource depending on the connected database before that the query get executed by the birt runtime, i think that the best fit for this purpose should be beforeOpen event on the dataset by how can i get the name of the database server? basically what i want to do is explained in the below pseudocode :

IF DataBaseType == 'PostgreSQL' THEN 
this.query = " Something"
ELSE IF DataBaseType == 'MSSQL' THEN 
this.query = "Something Else ... " 

AND SO ON ...



Can it be done in Java Script ? How ?


Thanks.
Re: Change query Text based on the database type from JS Script event handler [message #768834 is a reply to message #768778] Tue, 20 December 2011 22:30 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Why not just use the driver class in the if clause like:

var driverclass =
this.getDataSource().getExtensionProperty("odaDriverClass");
//MySql
if( driverclass == "com.mysql.jdbc.Driver" ){
//this.queryText will contain the original query that you build in the
//design
this.queryText = "Select * from orderdetails";
}

Jason

On 12/20/2011 2:25 PM, Alessio Pollero wrote:
> I want to change the query text of a datasource depending on the
> connected database before that the query get executed by the birt
> runtime, i think that the best fit for this purpose should be beforeOpen
> event on the dataset by how can i get the name of the database server?
> basically what i want to do is explained in the below pseudocode :
>
> IF DataBaseType == 'PostgreSQL' THEN this.query = " Something"
> ELSE IF DataBaseType == 'MSSQL' THEN this.query = "Something Else ... "
> AND SO ON ...
>
>
> Can it be done in Java Script ? How ?
>
> Thanks.
Re: Change query Text based on the database type from JS Script event handler [message #772266 is a reply to message #768834] Thu, 29 December 2011 11:26 Go to previous messageGo to next message
Alessio Pollero is currently offline Alessio PolleroFriend
Messages: 74
Registered: August 2011
Member
The problem is that when i pass the connection from the engine task with this code :

task.getAppContext().put("OdaJDBCDriverPassInConnection", myConn);


The properties "odaDriverClass" of the datasource is not updated and i get the driver class defined in the report datasource at design time ... I need to get the value from the actual connection ....

I solved the problem getting the JDBC Connection in this way :

var con = reportContext.getAppContext().get("OdaJDBCDriverPassInConnection");
if(con != null) {
	var driverclass  = con.getMetaData().getURL();
	if(driverclass.indexOf("sqlserver") > 0) {
         this.queryText = "SQL SERVER QUERY ";
        }

[Updated on: Thu, 29 December 2011 14:53]

Report message to a moderator

Re: Change query Text based on the database type from JS Script event handler [message #774241 is a reply to message #772266] Tue, 03 January 2012 15:20 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

What version of BIRT are you using? If myConn is a real connection the
engine should be using it and not the one in the design.

Jason

On 12/29/2011 6:26 AM, Alessio Pollero wrote:
> The problem is that when i pass the connection from the engine task with
> this code :
> task.getAppContext().put("OdaJDBCDriverPassInConnection", myConn);
>
> The properties "odaDriverClass" of the datasource is not updated and i
> get the driver class defined in the report datasource at design time ...
> I need to get the value from the actual connection ....
>
> Is it possible to retrieve the "OdaJDBCDriverPassInConnection" from the
> beforeOpen(javascript) of the datasorce and get the database connected
> from that Connection object ?
Re: Change query Text based on the database type from JS Script event handler [message #774307 is a reply to message #774241] Tue, 03 January 2012 17:08 Go to previous messageGo to next message
Alessio Pollero is currently offline Alessio PolleroFriend
Messages: 74
Registered: August 2011
Member
I'm using BIRT Runtime 3.7.0, everything works fine after the changes that i've done. The only strange thing is that the extension property odaDriverClass doesn't change based on the connection passed with OdaJDBCDriverPassInConnection .
Re: Change query Text based on the database type from JS Script event handler [message #774349 is a reply to message #774307] Tue, 03 January 2012 18:52 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

How are you checking this? After designing the report manually change
the password using xml design to an invalid password to verify it is not
using the passed in connection.

Jason

On 1/3/2012 12:09 PM, Alessio Pollero wrote:
> I'm using BIRT Runtime 3.7.0, everything works fine after the changes
> that i've done. The only strange thing is that the extension property
> odaDriverClass doesn't change based on the connection passed with
> OdaJDBCDriverPassInConnection .
Re: Change query Text based on the database type from JS Script event handler [message #774374 is a reply to message #774349] Tue, 03 January 2012 19:45 Go to previous messageGo to next message
Alessio Pollero is currently offline Alessio PolleroFriend
Messages: 74
Registered: August 2011
Member
The connection works fine, when i pass the connection through OdaJDBCDriverPassInConnection property then the report get connected with the passed connection. The only problem is that if i read the value of the property "odaDriverClass" on the dataset beforeOpen event as you suggested in one of the previous post :

var driverclass = this.getDataSource().getExtensionProperty("odaDriverClass");


i get the url of the database defined in the designer, the values of properties of the new connection are not automatically reflected to the dataset extension properties.
Re: Change query Text based on the database type from JS Script event handler [message #774826 is a reply to message #774374] Wed, 04 January 2012 17:55 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

That is correct. It does not update the design, just uses the new
connection.

Jason

On 1/3/2012 2:45 PM, Alessio Pollero wrote:
> The connection works fine, when i pass the connection through
> OdaJDBCDriverPassInConnection property then the report get connected
> with the passed connection. The only problem is that if i read the value
> of the property "odaDriverClass" on the dataset beforeOpen event as you
> suggested in one of the previous post :
> var driverclass =
> this.getDataSource().getExtensionProperty("odaDriverClass");
>
> i get the url of the database defined in the designer, the values of
> properties of the new connection are not automatically reflected to the
> dataset extension properties.
Previous Topic:[SOLVED]crosstab in subreport
Next Topic:Number format - complete zero suppress
Goto Forum:
  


Current Time: Fri Apr 19 03:31:07 GMT 2024

Powered by FUDForum. Page generated in 0.02531 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top