The following code implements how to convert FireDAC detal to SQL
1 functionTfddatasethelper.deltatosql (ConstAkeyfields:string):string;2 var3 Row, Col:integer;4 Datsrow:tfddatsrow;5 Datatype:tfddatatype;6OldValue, NewValue:string;7FieldNames, Values, Sqlwhere, TableName, Keyfields:string;8 begin9 TenResult: ="'; One AKeyfields: =Akeyfields; - ifKeyfields.isempty Then -Keyfields: =Updateoptions.keyfields; the -TableName: =Delta.DataView.Table.Name; - forRow: =0 toDelta.DataView.Rows.Count-1 Do - begin +Datsrow: =Delta.dataview.rows[row]; - + ifDatsrow.rowstateinch[Tfddatsrowstate.rsmodified, tfddatsrowstate.rsdeleted] Then ASqlwhere: =Preparesqlwhere (Datsrow, keyfields); at -Values: ="'; -FieldNames: ="'; - CaseDatsrow.rowstate of - tfddatsrowstate.rsinserted: - begin in forCol: =0 toDatSRow.Table.Columns.Count-1 Do - begin toDataType: =Datsrow.table.columns[col]. DataType; + - ifDataTypeinch[Dtblob, Dthblob] Then the Continue; * $ if notFieldnames.isempty ThenPanax NotoginsengFieldNames: = FieldNames +','; - the if notValues.isempty Then +Values: = values +','; A theFieldNames: = FieldNames +Datsrow.table.columns[col]. Name; +Values: = values +Var2sql (DataType, Datsrow.getdata (Col, Tfddatsrowversion.rvdefault)); - $ End; $ - if notResult.isempty Then -Result: = result +';'+Slinebreak; the -Result: = result +'INSERT into'+ TableName +'('+ FieldNames +') VALUES ('+ Values +')';Wuyi End; the - tfddatsrowstate.rsmodified: Wu begin - forCol: =0 toDatSRow.Table.Columns.Count-1 Do About begin $DataType: =Datsrow.table.columns[col]. DataType; -OldValue: =Var2sql (DataType, Datsrow.getdata (Col, tfddatsrowversion.rvoriginal)); -NewValue: =Var2sql (DataType, Datsrow.getdata (Col, Tfddatsrowversion.rvdefault)); - A ifOldValue <> NewValue Then + begin the if notValues.isempty Then -Values: = values +','; $ theValues: = values + Format ('%s=%s', [Datsrow.table.columns[col]. Name, NewValue]); the End; the the End; - if notValues.isempty Then in if notResult.isempty Then theResult: = result +';'+Slinebreak; the AboutResult: = result +'UPDATE'+ TableName +'SET'+ Values +Sqlwhere; the End; the tfddatsrowstate.rsdeleted: the begin + if notResult.isempty Then -Result: = result +';'+Slinebreak; the BayiResult: = result +'DELETE from'+ TableName +Sqlwhere; the End; the End; - - End; the the End;
Convert FireDAC detal to SQL