MySQL + UNIDAC Use transaction example

Source: Internet
Author: User

//Note: MySQL must use the InnoDB engine to support transactional functionality, otherwise the following transaction-related code will be invalidated. SQL Server and Oracle haven't tried yet, and the company tried to send the code back tomorrow. Procedure Tform1.btn1click (sender:tobject);varI, J:integer;beginUniconnection1.connect; Try    Tryunitransaction1.connections[0].      StartTransaction;      UniQuery1.Params.Clear; UniQuery1.SQL.Text:='INSERT INTO User (Username,password) VALUES (: Username,:p assword)'; UniQuery1.Params.ParamByName ('username'). Value: ='Eboy'; UniQuery1.Params.ParamByName ('Password'). Value: ='1111'; Uniquery1.execsql; //If you do not use transactions, this entry is inserted into theUniQuery1.Params.Clear; UniQuery1.SQL.Text:='INSERT INTO User (Username,password) VALUES (: Username,:p assword)'; UniQuery1.Params.ParamByName ('username'). Value: ='FRR'; UniQuery1.Params.ParamByName ('Password'). Value: ='123'; Uniquery1.execsql; //If you do not use transactions, this entry is inserted into theUniQuery1.Params.Clear; UniQuery1.SQL.Text:='INSERT INTO User (Username,password) VALUES (: Username,:p assword)'; UniQuery1.Params.ParamByName ('username'). Value: ='LJ'; UniQuery1.Params.ParamByName ('Password'). Value: ='880414'; Uniquery1.execsql; //If you do not use transactions, this entry is inserted into theUniQuery1.Params.Clear; UniQuery1.SQL.Text:='INSERT INTO User (Username,password) VALUES (: Username,:p assword)'; UniQuery1.Params.ParamByName ('username'). Value: ='LJ'; UniQuery1.Params.ParamByName ('Password'). IsNull;//The field is set to NOT NULL, so there is an error hereUniquery1.execsql;//when the transaction is turned on, the above three bars will be rolled backunitransaction1.connections[0].    Commit; exceptOn E:exception Do      beginunitransaction1.connections[0].        Rollback;      ShowMessage (E.message); End; End; finallyUniconnection1.disconnect; End;End;
MySQL + UNIDAC Use transaction example

MySQL + UNIDAC Use transaction example

Related Article

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.