Convert FireDAC detal to SQL

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.