unit ZQueryBatchDML;
interface
uses ZConnection, ZDataSet;
procedure ExecuteQueryBatchInsert;
implementation
uses SysUtils;
procedure ExecuteQueryBatchInsert;
var Connection: TZConnection;
Query: TZQuery;
DMLidx: Integer;
Succeeded: Boolean;
begin
Connection := TZConnection.Create(nil);
{assign everything to connect}
Query := TZQuery.Create(nil);
Query.Connection := Connection;
Connection.Connect;
try
Connection.ExecuteDirect('CREATE TABLE DML_INSERT_DEMO('+
'ID INTEGER NOT NULL,'+
'NUM VARCHAR(32),'+
'INSERT_TIMESTAMP DATETIME)');
Connection.StartTransaction;
Succeeded := False;
try
Query.SQL.Text := 'INSERT INTO DML_INSERT_DEMO VALUES (:ID,:NUM,:INSERT_TIMESTAMP)';
Query.Params.BatchDMLCount := 10;
for DMLidx := 0 to 9 do begin
Query.Params[0].AsIntegers[DMLidx] := DMLidx +1;
Query.Params[1].AsStrings[DMLidx] := IntToStr(DMLidx);
Query.Params[2].AsDateTimes[DMLidx] := now;
end;
Query.ExecSQL;
Assert(
Query.RowsAffected = 10);
Succeeded := True;
finally
if Succeeded
then Connection.Commit
else Connection.Rollback;
end;
finally
Query.Free;
Connection.Free;
end;
end;
end.