Delphi Firedac under the Sqlite (11) Batch submit SQL command test

Source: Internet
Author: User
Tags insert integer sqlite first row

You can quickly complete the form design by pasting the following code directly onto a blank form: Object Dbgrid1:tdbgrid left = 0 top = 0 Width = 265 Height = 338 Align = Alleft DataSource = DataSource1 Ta BOrder = 0 Titlefont.charset = Default_charset Titlefont.color = Clwindowtext titlefont.height = -11 TitleFont.Nam E = ' Tahoma ' Titlefont.style = [] End object Button1:tbutton left = 280 top = Width = Height = Capti on = ' Button1 ' taborder = 1 OnClick = Button1Click End Object Button2:tbutton left = 280 top = Width = 75 Height = Caption = ' Button2 ' TabOrder = 2 OnClick = Button2click End Object Button3:tbutton left = 280 top = Rule Width = Height = Caption = ' Button3 ' taborder = 3 OnClick = Button3click End Object Button4:tbutton left = 280 top = 144 Width = Height = Caption = ' Button4 ' taborder = 4 OnClick = Button4click End Obje CT Fdconnection1:tfdconnection left = top = + End Object Fdphyssqlitedriverlink1:tfdphyssqlitedriverlink left = 167 top = ' End obj 'ECT fdguixwaitcursor1:tfdguixwaitcursor Provider = ' Forms ' left = 164 top = The End object Fdquery1:tfdquery Con Nection = FDConnection1 left = the top = The end of object Datasource1:tdatasource DataSet = FDQuery1 left = Top = The end

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Delphi/

Code:

EstablishprocedureTform1.formcreate (Sender:tobject);Conststrtable = ' CREATE TABLE MyTable (Id integer PRIMARY KEY autoincrement, Name string (Ten), age integer) '; Id (self-increasing), Name, agebeginFdconnection1.drivername: = ' SQLite ';
  Fdquery1.execsql (strtable); Fdquery1.open (' SELECT * from MyTable '); End; {Insert}procedureTform1.button1click (Sender:tobject);ConstStrinsert = ' INSERT into MyTable [name, Age] VALUES (: Name,: Age) ';beginFDQuery1.FetchOptions.AutoClose: = True;
  Default value Fdquery1.execsql (Strinsert, [' A ', 1]);
  Fdquery1.execsql (Strinsert, [' B ', 2]);
  Fdquery1.execsql (Strinsert, [' C ', 3]);

  Fdquery1.execsql (Strinsert, [' D ', 4]); Fdquery1.open (' SELECT * from MyTable '); End; {use; split, first row insert}procedureTform1.button2click (Sender:tobject);ConstStrinsert = ' INSERT into MyTable (Name, age) VALUES ('%s ',%d) ';varLSTR:string;beginLstr: = ';
  LSTR: = Lstr + Format (strinsert, [' AA ', 11]) + '; ';
  LSTR: = Lstr + Format (strinsert, [' BB ', 22]) + ';
  LSTR: = Lstr + Format (strinsert, [' CC ', 33]) + '; ';
  LSTR: = Lstr + Format (strinsert, [' DD ', 44]) + '; ';

  LSTR: = lstr + ' SELECT * from MyTable ';
  Fdquery1.execsql (LSTR); Fdquery1.open (); End; {Use the NextRecordset method to extract and execute all commands}procedureTform1.button3click (Sender:tobject);ConstStrinsert = ' INSERT into MyTable (Name, age) VALUES ('%s ',%d); ';beginFDQuery1.FetchOptions.AutoClose: = False;
  Ordinarily this is required to be set, but the test is not set can also be FDQuery1.SQL.Clear;
  FDQUERY1.SQL.ADD (Format (Strinsert, [' AAA ', 111]));
  FDQUERY1.SQL.ADD (Format (Strinsert, [' BBB ', 222]));
  FDQUERY1.SQL.ADD (Format (Strinsert, [' CCC ', 333]));

  FDQUERY1.SQL.ADD (Format (Strinsert, [' DDD ', 444]));

  FDQUERY1.SQL.ADD (' SELECT * from MyTable ');
  Fdquery1.execute (); Fdquery1.nextrecordset; End; {using DML array parameters}procedureTform1.button4click (Sender:tobject);ConstStrinsert = ' INSERT into MyTable [name, Age] VALUES (: Name,: Age); ';beginFDQuery1.FetchOptions.AutoClose: = False;
  FDQuery1.SQL.Text: = Strinsert; FDQuery1.Params.ArraySize: = 4; Prepare to execute the above statement 4 times {4 parameters are set respectively} Fdquery1.params[0].
  Asstrings[0]: = ' AAAA '; FDQUERY1.PARAMS[1].

  Asintegers[0]: = 1111; Fdquery1.params[0].
  ASSTRINGS[1]: = ' bbbb '; FDQUERY1.PARAMS[1].

  ASINTEGERS[1]: = 2222; Fdquery1.params[0].
  ASSTRINGS[2]: = ' CCCC '; FDQUERY1.PARAMS[1].

  ASINTEGERS[2]: = 3333; Fdquery1.params[0].
  ASSTRINGS[3]: = ' DDDD '; FDQUERY1.PARAMS[1].

  ASINTEGERS[3]: = 4444; Fdquery1.execute (4, 0);
  4 FDQUERY1.SQL.ADD (' SELECT * from MyTable ') are executed from 1; Fdquery1.nextrecordset; End;

Test Effect Diagram:

Alternatively, you can use the FIREDAC extended SQL script (Tfdscript), which also invokes the SQL instructions in the file directly.

Author:cnblogs in case

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.