views:

460

answers:

3

Is it possible to set a database role before running a report? I have a number of databases each containing a number of schemas with the same set of tables, where each schema has a number of roles to control read, write, data management and so on. None of these are default roles.

In sqlplus or TOAD I can do SET ROLE , before running a select statement. I would like to do the same in BIRT.

It may be possible to do this using the afterOpen event for the ODA Data Source, but I have not found any examples on how to get and use the native connection in JavaScript.

I am not allowed to add or change anything on the server end.

A: 

You can write a login trigger and do a set role in this trigger ( PL/SQL: DBMS_SESSION.SET_ROLE). You can determine the username, osuser, program and machine of the user who want to log in.

Theo
This is unfortunately not an option, as long as I am not allowed to do anything on the server end. There are also a number of servers.
stili
Talk to your DBA. When he/she knows a better solution, implement that solution. If he/she doesn't know a better solution ask him or her to check the code of the trigger and to install it in the production db's.
tuinstoel
A: 

Hello,

You can make an additional call to the database in the afterOpen method of the Data Source using Java. You can use JavaScript or a Java Event Handler to execute the SET ROLE statement, or to call a stored procedure that will execute it for you. This happens after the initial db connection is made, but before the Data Set query runs. It will be a little tricky to use the data source connection to make that call however, and I don't have the code right now to provide as an example.

Another way is to create a stored proc Data Set that will execute the desired command, and have that execute first. Drag and drop the Data Set into the report design, and make it invisible. It will run first before any other queries. Not the cleanest solution, but easy to do

Hope that helps

Le Birt Expert

Le Birt Expert
A: 

The approach to use a stored procedure for setting the role won't work - at least not on Apache Derby. Reason: lifetime of the set role is limited to the execution of the procedure itself - after returning from the procedure the role will be the same as before the procedure has been called, i.e. for executing the report the same as no role would have ever been set.

Thomas