Jump to content
TurboMagic

TFDBatchMove with non NULL column in target table

Recommended Posts

I'm using D11.3 and a Firebird database. I use TFDBatchMove to copy rows from one database (the old one before the update of the application) to the empty DB installed with the update. Now when that new database contains a new column declared as non Null it crashes.

 

How to prevent this or how to deal with this?

Share this post


Link to post

If the source table doesn't provide a value for that column, you need to do that yourself, which implies that you know which value has to be written to that field. Depending on your batch move architecture, that might be done in OnNewRecord of the target dataset or OnWriteRecord of TBatchMove.

  • Like 1

Share this post


Link to post

I tried OnNewRecord now, but it doesn't seem to get called. What am I'm doing wrong?

 

Here I assign OnNewRecord via code, since FWriter is created at runtime:

FWriter.FDDataSet.OnNewRecord   := OnNewRecord;

 

Here's the implementation of that event:

procedure TDBCopy.OnNewRecord(DataSet: TDataSet);
begin
  if (FWriter.ActualTableName.ToUpper = 'KASSE_EINSTELLUNGEN') then
  begin
    DataSet.FieldByName('DRAWBACK_CALCULATION').AsInteger := 0;
  end;

  if (FWriter.ActualTableName.ToUpper = 'KASSE_PRINTSETTINGS') then
  begin
    DataSet.FieldByName('PRINT_SMALL_BONS').AsInteger := 0;
  end;
end;

But when running FBatchMove.Execute; the breakpoint in the event is never ever called.

And the way my application crashes indicates that it's actually never run.

 

Do I need to activate something somewhere?

I only assign TableNames to FReader.TableName and FWriter.TableName and then run FBatchMove.Execute;

Edited by TurboMagic

Share this post


Link to post

You need to give way more information about your components and their properties.

 

F.i. setting Direct in a TFDBatchMoveDataSetWriter will probably not call Append and thus OnNewRecord is not called.

Also using an TFDBatchMoveSQLWriter will not call OnNewRecord either.

 

 

Share this post


Link to post

One other way is to use a Query as datasource, then you can rename columns or set columns and so on

i.e

SELECT ...., KASE_EINSTELLUNGEN as DRAWBACK_CALCULATION, 0 AS PRINT_SMALLBONS .... FROM

You said you use onNewRecord but, did you try onBeforePost ? (I don't check if this event is called)

Edited by Serge_G

Share this post


Link to post

Well, when I provide an SQL query for the reader as you describe I'm getting more inflexible
when adding new fields to that table in comparison to only having to deal with cases where a "not NULL"

for a column needs to be dealt with.

 

Since Uwe hints that a SQLWriter will not call OnNewRecord I will try the TFDBatchMoveDataSetWriter now.

If that calls this event and lets me call FieldByName it should do.

Share this post


Link to post

Ok, the plan with the TFDBatchMoveDataSetWriter  isn't so easy. It lacks the .TableName property and it looks like I need to assign a TDataSet to that one.

Seems more investigation is required.

Share this post


Link to post

Ok, I have a solution now, thanks to Uwe's suggestion:
If I use a DataSetWriter instead of a SQL one, I can assign a TFDTable component to that one, which has the TableName property
and which calls OnNewRecord just fine. In that one can I check the table name and if it's one of the tables where not Null columns
have been added later on, I can check these columns for 'not NULL' and assign a default value there.

 

In my tests the DB functionality of having default values didn't work. Maybe the TFDBatchMove added NULL values itsself for
these additional columns...

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×