|
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 |
|
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 |
Alessio Pollero 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 |
|
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 #774349 is a reply to message #774307] |
Tue, 03 January 2012 18:52 |
|
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 #774826 is a reply to message #774374] |
Wed, 04 January 2012 17:55 |
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.02832 seconds