Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to get errors from TFDSchemaAdapter


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Apr 18, 2016 3:10 AM Last Post By: Asbjørn Heid
Asbjørn Heid

Posts: 267
Registered: 11/12/12
How to get errors from TFDSchemaAdapter  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 14, 2016 4:05 AM
I have a fairly plain cached master/detail setup, using the TFDSchemaAdapter, set up as explained in the help.

When I call schemaAdapter.ApplyUpdates(0) and a DB error occurs (for example due to some constraint violation), the call returns 1.

However, I can't seem to find any way to find the actual error so I can raise some meaningful exception. Neither OnError or OnReconcileRow is called.

What am I missing?

I'm using XE6 (latest updates).

Cheers
- Asbjørn
Dmitry Arefiev

Posts: 1,406
Registered: 12/7/03
Re: How to get errors from TFDSchemaAdapter
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 14, 2016 11:55 PM   in response to: Asbjørn Heid in response to: Asbjørn Heid
After XE6 there were many changes in this area. But you can try this:
http://docwiki.embarcadero.com/RADStudio/Seattle/en/Caching_Updates_%28FireDAC%29#Reviewing_Errors

--
With best regards,
Dmitry
Asbjørn Heid

Posts: 267
Registered: 11/12/12
Re: How to get errors from TFDSchemaAdapter  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 15, 2016 1:46 AM   in response to: Dmitry Arefiev in response to: Dmitry Arefiev
Dmitry Arefiev wrote:
After XE6 there were many changes in this area. But you can try this:
http://docwiki.embarcadero.com/RADStudio/Seattle/en/Caching_Updates_%28FireDAC%29#Reviewing_Errors

Thanks, I'll try filtering as reconcile does not seem to work, I have AutoCommitUpdates enabled and as mentioned the OnReconcileRow does not fire.

The only issue I see with filtering is that I don't see how to get the queries from the schema adapter.

Does this mean I need to do the filtering manually on the queries? So if I add another detail query I must remember to add the filtering code for that query as well? I guess I could always iterate over all components on the datamodule and discover it that way, but that seems a bit hackish...

Cheers
- Asbjørn
Asbjørn Heid

Posts: 267
Registered: 11/12/12
Re: How to get errors from TFDSchemaAdapter  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 18, 2016 3:09 AM   in response to: Asbjørn Heid in response to: Asbjørn Heid
Asbjørn Heid wrote:

Does this mean I need to do the filtering manually on the queries?

Ah I had missed some crucial details of the TDatSTable class.

Here's how I ended up solving it. This is a class helper method.

procedure TFDCustomSchemaAdapterHelper.ApplyUpdatesEx;
var
	dbError: TFDException;
	ErrorCount: integer;
	i, j: integer;
	table: TFDDatSTable;
	row: TFDDatSRow;
begin
	ErrorCount := Self.ApplyUpdates(0);
	
	if (ErrorCount <= 0) then
		exit;
	
	for i := 0 to Self.Count-1 do
	begin
		table := Self.TableAdapters[i].DatSTable;
		
		for j := 0 to table.Rows.Count-1 do
		begin
			row := table.Rows[0];
			if (not row.HasErrors) then
				continue;
			
			row.RowError.Duplicate(dbError);
			raise dbError;
		end;
	end;
	
	raise EFDException.Create('Error applying updates');
end;


Is it safe to raise the RowError object directly?

- Asbjørn

Edited by: Asbjørn Heid on Apr 18, 2016 3:10 AM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02