Is it possible to bulk upsert data with an array dml using IDBStatement? Or is it necessary to retrieve the FDConnection and create a FDQuery? (Multiple requests to xdata server to run a regular query)
I've tried several ways to add more than one value to a parameter, but only the first or last is executed. Even though the array size is 2. E.g. I always get one row in the database.
self.XDataBasis.cQuery := 'INSERT INTO foo (a, b) VALUES (:a, :b)';
I've tried several options: (Params is a TObjectList;)
1:
self.XDataBasis.Params.Add(TDBParam.Create('a', ftstring, 'test1'));
self.XDataBasis.Params.Add(TDBParam.Create('a', ftstring, 'test2'));
self.XDataBasis.Params.Add(TDBParam.Create('b', ftinteger, 1));
self.XDataBasis.Params.Add(TDBParam.Create('b', ftinteger, 1));
2:
self.XDataBasis.Params.Add(TDBParam.Create('a', ftstring, ['test1', 'test2']));
self.XDataBasis.Params.Add(TDBParam.Create('b', ftinteger,[ 1, 1]));
3:
self.XDataBasis.Params.AddRange(TDBParam.Create('a', ftstring, ['test1', 'test2']));
self.XDataBasis.Params.AddRange(TDBParam.Create('b', ftinteger,[ 1, 1]));
function TXDataBasis.RunExecute: integer;
begin
Statement.SetSQLCommand(cQuery);
if (Params<>nil) and (Params.Count > 0) then Statement.SetParams(Params);
if not Supports(Statement, IDBDatasetStatement, DBStmt) then
begin
Result := -1; //'not supported';
end
else
begin
Result := Statement.Execute;
end;
end;