#1 mORMot 1 » Batch Insert and Duplicates » 2019-09-08 21:43:52

Kirill
Replies: 3

Hello,

I need help to properly implement the batch insert with possible duplicates in the indexed field.

Initialization:

    Props := TSQLDBZEOSConnectionProperties.Create(
      Format(
        'zdbc:mysql://%s/%s?username=%s;password=%s',
        [Server.Host, Server.DataBase, Server.User, Server.Password]),
      '', '', ''); 

    Model := CreateKeywordModel;
    VirtualTableExternalRegister(Model, [TSQLKeyword], Props);
    Client := TSQLRestClientDB.Create(Model, nil, 'SomeTableName', TSQLRestServerDB);
    Client.Server.CreateMissingTables;  

Then the following:

      Client.BatchStart(TSQLKeyword, List.Count, [boInsertOrIgnore]);
      for I := 0 to List.Count - 1 do begin
        Item := TSQLKeyword(List.Items[I]);
        Client.BatchAdd(Item, True);
      end;

      R := Client.BatchSend(IDs);

R = 500, IDs array has become empty after I tried to insert 10 duplicates with 90 new items. I need a way to count "new" and "duplicates" items. Please advise.

Board footer

Powered by FluxBB