Replacing SQL just before to open
I need to modify the SQL statement before to FR executes it. Parameter system it is not enough.
For example my SQL statement is:
SELECT * FROM Customer WHERE %%MyFilterTag%% ORDER BY %%MyOrderTag%%
Then, from the source, I need to replace %%MyFilterTag%% by my custom filter and %%MyOrderTag%% by my custom sort.
Is there a FR event that is called just before the database is opened?
Thank you
For example my SQL statement is:
SELECT * FROM Customer WHERE %%MyFilterTag%% ORDER BY %%MyOrderTag%%
Then, from the source, I need to replace %%MyFilterTag%% by my custom filter and %%MyOrderTag%% by my custom sort.
Is there a FR event that is called just before the database is opened?
Thank you
Comments
There is no such event. You may enumerate available datasources and replace SelectCommand before running a report:
FastReport.ReportPage
FastReport.ReportTitleBand
FastReport.PageHeaderBand
FastReport.TextObject
FastReport.DataBand
FastReport.TextObject
FastReport.TextObject
FastReport.DataHeaderBand
FastReport.TextObject
FastReport.TextObject
FastReport.LineObject
FastReport.PageFooterBand
I'm not getting any TableDataSource object in report who have two TableDataSources.
Please help me with that. It's urgent.
Another approach would be to implement some kind of parametrisation of SQL queries in report.
Lets say I want to print list of products (SELECT code, name FROM product).
Before print user want to filter his list of products by several parameters (in business application).
User filters his data by: code like '0%' and length between 10 and 20 ...
In report SQL statement we could enter: SELECT code, name FROM product [param_where].
"param_where" would be parameter who we pass from business application's code.
This approach is very usable in edit (design) mode and in release mode.
Thanks.
foreach (Base c in report.Dictionary.AllObjects)
...
The parameterized sql is not an option. [] are reserved symbols in many sql dialects.
I'm actually looking at doing the same thing. I just started to look at reporting tools and there are some features I need.
One feature I need is to replace the SQL just before execution so I can add our Security.
Here's an example:
Report will generate following SQL.
Select f1, f2, f3, role from xyz
I need to replace the sql with following.
Select f1, f2, f3, role from xyz as a
Inner Join Security as b on b.role = a.role
Inner Join User as c on c.User = b.User
If you know the name of the query, you may use the following code:
TableDataSource table = Report.GetDataSource("MyQuery") as TableDataSource;
table.SelectCommand = "select * from ... ...";
You can put this code in the report script, the best place is Report.StartReport event.
I would ask you as suggestion to add an event in FR, for example OnBeforeOpen, where you can change the SQL string in runtime just before FR executes it.
The current solution, iterating all report objects, works fine, but it is not efficient, specially in environments like slow web servers, many users and reports with many objects.
Replacing SQL just before open is a common requirement.
Thank you
In my case, I use embedded functions in the SQL, for example
SELECT * FROM Customers WHERE %%GetValue('Filter')%%
Thank you