Insert Batch Update
Posted: Tue 25 Jul 2017 16:57
Hello,
My scenario is batch inserting using the following method:
FBufferSize := 1000;
...
FLiteConnection.SQL.Params[0][FDBCount].AsLongWord := FCount;
FLiteConnection.SQL.Params[1][FDBCount].AsInteger := FHasher.GetHashValue(aExpression);
FLiteConnection.SQL.Params[2][FDBCount].AsLongWord := FTextRecordNumber;
...
Inc(FDBCount);
if (FDBCount = FBufferSize) then
begin
FLiteConnection.SQL.Execute(FDBCount);
FDBCount := 0;
end;
...
// End of process
if (FDBCount <> 0) then
begin
FLiteConnection.SQL.Execute(FDBCount);
FDBCount := 0;
end;
In the end of process, if the value of FDBCount=1, I get a ‘UNIQUE constraint failed’.
If I skip the SQL.Execute if FDBCount=1 and close everything, it does seem to save the record anyway.
If FDBCount>1, no issues. If I set the FBufferSize := 1, of course no problem.
I have a lot of records so simple inserts would take too much time.
I tried using a TLiteQuery connected to the connection, same problem.
Am I doing anything wrong? If not, is there a bug fix out?
I have the standard version (no source code).
Pierre
My scenario is batch inserting using the following method:
FBufferSize := 1000;
...
FLiteConnection.SQL.Params[0][FDBCount].AsLongWord := FCount;
FLiteConnection.SQL.Params[1][FDBCount].AsInteger := FHasher.GetHashValue(aExpression);
FLiteConnection.SQL.Params[2][FDBCount].AsLongWord := FTextRecordNumber;
...
Inc(FDBCount);
if (FDBCount = FBufferSize) then
begin
FLiteConnection.SQL.Execute(FDBCount);
FDBCount := 0;
end;
...
// End of process
if (FDBCount <> 0) then
begin
FLiteConnection.SQL.Execute(FDBCount);
FDBCount := 0;
end;
In the end of process, if the value of FDBCount=1, I get a ‘UNIQUE constraint failed’.
If I skip the SQL.Execute if FDBCount=1 and close everything, it does seem to save the record anyway.
If FDBCount>1, no issues. If I set the FBufferSize := 1, of course no problem.
I have a lot of records so simple inserts would take too much time.
I tried using a TLiteQuery connected to the connection, same problem.
Am I doing anything wrong? If not, is there a bug fix out?
I have the standard version (no source code).
Pierre