TurboMagic 92 Posted November 29, 2023 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
Uwe Raabe 2063 Posted November 29, 2023 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. 1 Share this post Link to post
TurboMagic 92 Posted November 30, 2023 (edited) 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 November 30, 2023 by TurboMagic Share this post Link to post
Uwe Raabe 2063 Posted November 30, 2023 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
Serge_G 87 Posted December 1, 2023 (edited) 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 December 1, 2023 by Serge_G Share this post Link to post
TurboMagic 92 Posted December 1, 2023 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
TurboMagic 92 Posted December 1, 2023 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
TurboMagic 92 Posted December 3, 2023 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