How to get data from two databases via FastReport - delphi

I have created a report using FastReport Designer (Delphi 2010). I have one TfrxIBXQuery (Query1) connected with main database -Base1(frxIBXComponents.DefaultDatabase:=Base1). It works fine, I can get data using Query1+MasterData band.
The problem arises when I'm trying to get data from another database in the same report.
In Designer I drop new frxIBXDatabase (Base2), set the necessary properties. Add new TfrxIBXQuery (Query2) and connect it with Base2.
But I can't get any data from Query2 because it does not see Base2.
How do I solve this problem?

When you look at the properties tab from your query component, can you see any FieldAliases?
If not, you should check the SQL, FastReport can be really picky when it comes to parameters.
Try changing parameter names and see if that works.

If you want to use two or more databases inside report - you should use two TfrxIBXDatabase inside report (on the Data tab)
Clear frxIBXComponents.DefaultDatabase property

Related

Delphi 10 -how to delete detail records automatically when delete master?

I'm using Delphi 10 with Firedac , I have with two tables in a Master-Detail configuration , A(Document) and B(DocDetail) . In my Form I have two DBgrids, linked to each Datasource respectively. I want a configuration, if possible, that delete all records items in table DocDetail when I delete its corresponding Master record in the master DBgrid. Is there any configuration in the table FDTable component that does such action ? Or there any other way to do delete master - delete detail in Delphi side ? (I know that it is possible to do it in database side through a constraint delete cascade). Thanks for your help.
The properties you are looking for on the TFDQuery component are FetchOptions.DetailCascade and/or FetchOptions.DetailServerCascade
From the help on DetailServerCascade
When DetailServerCascade is False, then FireDAC posts client-side
cascading changes to the database. The client-side cascading changes
are performed when DetailCascade is True. So DetailServerCascade
should be used together with DetailCascade.
If you are using CachedUpdates you may also need a TFDSchemaAdapter component. This CentralizedCachedUpdates Sample page list all of the steps need to setup the components when using cached updates.
I am using this on one form with good results. It was a little bit picky to get it all setup correctly. Basically every DataSet involved in the update needs to point to one common TFDSchemaAdapter component. Then any Master datasets need to have their FetchOptions.DetailCascade set to true to ensure that the rows are correctly deleted from the child datasets

GroupFooter from FastReports not getting data using DBX instead of ADO in delphi

Since I don't want to use ODBC connections anymore, I'm trying to get DBX work for my reports. Almost everything works the same as it worked with the tfrxAdoQuery, but not the GroupFooter.
I used to have a MasterData that used a ADOQuery1: TfrxAdoQuery and I changed to a DBXQuery1:TfrxDBXQuery. Its fields like [BDXQuery."name"] work fine now than I'm using a different type of query, but only inside the MasterData. This is the way it looks in the MasterData and when the report is displayed it comes correctly:
For some reason, the Footer's tfrxMemoViews dont show the DBXQuery1."anyField" that I try to display.
This is the way it looks in the footer but in the report just dont show the name.
The difference is the DatasetName can't be set for the DBXQuery (as it was set when using the ADOquery). When I was using ADO, the DatabaseName seem to be assinged arbitrarilly with a name like 'header' which did not belong to any component or variable. Now it should be more manageable since the fields that are set are DataSet (wich can be chosen from a group that has all the DataSets, in my case I can choose DBXQuery1) and DataField, which can be chosen from one of the predetermined fields that are in the DBXQuery1.
Any help will be highly appreciated

AnyDac aka FireDac cannot generate update query

I was using UniDac for a long time now and decided to move on to FireDac as it has good Asynch methods after moving on i saw that none of my data editing works anymore it gives me an error:
[FireDAC][Phys]-330. Cannot generate update query. Update table undefined.
What I am trying to do here is i have a TFDStoredProc component who gets all the data from the database and lets me edit it, with unidac I could easily edit the data without any problem like this:
StoredProc.Edit;
StoredProcCreatedID.Value := SomeValue;
StoredProc.Post;
and it worked, but with AnyDac it doesn't, I tried specifying manually the UpdateTable which leads to another problem:
[FireDAC][Phys][ODBC][Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid column name 'CreatedID'.
I am using Microsoft SQL Server 2012 FireDac 8.0 and stored procedures for getting back results any ideas?
P.S.
The query looks like this
SELECT
CreatedBy as CreatedID,
usr.UserName as CreatedBy
FROM
Sales
LEFT JOIN
Users usr ON usr.ID = Sales.CreatedBy
it looks like the FireDac update builder doesn't recognize the aliases on the fields, any help would be appreciated.
Well i figured out what was the issue, it seems that if you specify a alias in the query for a field the Origin property will be set to the alias and not the real field i downloaded CNPack a must have for a delphi developer also its free, ran the component selector and changed all my aliased fields to their real fields and it works, but this is still a big issue in FireDac component because it doesnt recognize the aliased fields, lets hope it will be fixed in the future as to specify for every query what table it should update and what fields that just allot of work if you are migrating from a big project in my case 220+ stored procedures.

FastReport4: Refresh Dataset

My Report.ShowPreparedReport didn't recognize a new addition to my frxDBDataset.
So, I was building 1 report using TfrxDBDataset linked to a TVirtualTable.
Previously only 10 fields stated in Report1.fr3 and it works well.
I do the SaveAs from Report1.fr3 to Report2.fr3 in designer mode
Get back to my Delphi and add 1 new field "tec" in my TVirtualTable
Go back again in ReportDesigner (file Report2.fr3) and see that my new "tec" field is listed in Data tree.
Add the "tec" field to the report.
Preview while on designer and it was normal.
Run the program and call to preview report, it says "field 'tec' cannot be found" or something like that.
Anyone got solution?
Thanks
Please Try.
TVirtualTable.Refresh;
frxDBDataset.FieldAliases.Clear;
When you clear aliases then call Designer
FastReport automatically updates aliases.
That was the perfect solution for me.

FireDAC - Show SQL after Macro Expantion

I am trying to use Macros in FireDAC to Preprocess my SQL Queries. I have a TADQuery object on a Data Module with the SQL set to something like:
Select * from MyTable
join OtherTable on MyTable.Key = OtherTable.Key
&Where
Then in my code I do this:
WhereClause = 'stuff based on my form';
Query.MacroByName('Where').AsRaw := WhereClause;
Query.Open;
This has worked great for complicated queries because it lets me make sure my fields and join conditions are correct using the SQL Property editor.
My problem is when the SQL statements ends up invalid because of my where clause. Is there any way to see the SQL after pre-processing that is going to be executed? Right now I am catching the FireDac errors and showing the SQL that is on EADDBEngineException object. However that is still showing my original SQL with the macros. If I can't get to it after the error happens is there anyway to force the Macro replacement to take place so I can look at the SQL in the debugger to help me see what is wrong.
If it matters I am connecting to a MS Access database with the goal of moving to SQL Server in the near future.
Apart from using Text property, to monitor what SQL is actually going to the database engine, consider using the "FDMonitor" FireDAC utility. According to the DokWiki pages (below):
drop a TFDMoniRemoteClientLink component on your form,
Set its Tracing property to True,
Add the MonitorBy=Xxx connection definition parameter to your existing FDConnection component. You can do this in the IDE object inspector, by selecting your FDConnection component, expanding the Params property, and setting MonitorBy to mbRemote.
Note that the TFDMoniXxxxClientLink should come before TFDConnection in the data module or form creation order, so adjust this by right clicking on the form or data module, then Creation Order, and moving the TFDMoni.. component above the FDConnection.
Also, it's helpful in the options of the TFDMoniXxxxClientLink, to disable most of the events being recorded, otherwise all the data returned is also shown in the FireDAC monitor. Expand the EventKinds property, and turn all the event kinds off, except for perhaps ekConnConnect, ekConnPrepare, and ekCmdExecute.
Then open the FireDAC Monitor from the IDE, (Tools > FireDAC Monitor). Start your app only once the monitor is running. Double click on a trace event (in the Trace Output tab), and you will see the actual SQL sent to the database in the bottom pane.
It also seems likely that adding the EventType of ekConnPrepare as mentioned above, would show you when the query's Prepare is called, but I haven't played enough with it say for sure.
Please see the following pages on the DocWiki for more information:
Overview: FDMonitor
How to: Tracing and Monitoring (FireDAC)
Other FireDAC utilities: Utilities (FireDAC)
(Just to remove this question from list of unanswered questions)
From comments:
Well, I've roughly checked what's happening there and I'm still not
sure if calling Prepare (which is useless for you as I get) is the
minimal requirement to trigger that preprocessing. Though, the
preprocessed SQL, the one which is sent to the DBMS you can access
through the Text property (quite uncommon name for such property). – TLama Feb
21 '14 at 8:18

Resources