Skip to content
Permalink
Browse files

Issue #12: Call sqlite3_total_changes() after at least one call to sq…

…lite3_step(), otherwise SQLite does not seem to execute a non-result query. Should make updates in data and query grid working now.
  • Loading branch information
ansgarbecker committed Jan 1, 2020
1 parent cc82030 commit b869181f74eeba564d305122dbd86dfe8aa8c458
Showing with 7 additions and 5 deletions.
  1. +7 −5 source/dbconnection.pas
@@ -2984,7 +2984,7 @@ procedure TSQLiteConnection.Query(SQL: String; DoStoreResult: Boolean=False; Log
Value: TGridValue;
QueryResult: Psqlite3_stmt;
QueryStatus: Integer;
i: Integer;
i, OldRowsAffected: Integer;
CurrentSQL, NextSQL: PAnsiChar;
begin
if (FLockedByThread <> nil) and (FLockedByThread.ThreadID <> GetCurrentThreadID) then begin
@@ -3003,8 +3003,9 @@ procedure TSQLiteConnection.Query(SQL: String; DoStoreResult: Boolean=False; Log
TimerStart := GetTickCount;
SetLength(FLastRawResults, 0);
FRowsFound := 0;
FRowsAffected := FLib.sqlite3_total_changes(FHandle); // Temporary: substract these later from total num
FRowsAffected := 0;
FWarningCount := 0;
OldRowsAffected := FLib.sqlite3_total_changes(FHandle); // Temporary: substract these later from total num

QueryResult := nil;
NextSQL := nil;
@@ -3016,13 +3017,11 @@ procedure TSQLiteConnection.Query(SQL: String; DoStoreResult: Boolean=False; Log
FLastQueryNetworkDuration := 0;

if QueryStatus <> SQLITE_OK then begin
FRowsAffected := 0;
Log(lcError, GetLastErrorMsg);
raise EDbError.Create(GetLastErrorMsg);
end;
FRowsAffected := FLib.sqlite3_total_changes(FHandle) - FRowsAffected;
FRowsFound := 0;
if DoStoreResult then begin
if DoStoreResult and (FLib.sqlite3_column_count(QueryResult) > 0) then begin
Rows := TSQLiteGridRows.Create(Self);
while FLib.sqlite3_step(QueryResult) = SQLITE_ROW do begin
Row := TGridRow.Create;
@@ -3039,8 +3038,11 @@ procedure TSQLiteConnection.Query(SQL: String; DoStoreResult: Boolean=False; Log
SetLength(FLastRawResults, Length(FLastRawResults)+1);
FLastRawResults[Length(FLastRawResults)-1] := Rows;
end else begin
// Make one step through this non-result, otherwise SQLite does not seem to execute this query
FLib.sqlite3_step(QueryResult);
FLib.sqlite3_finalize(QueryResult);
end;
FRowsAffected := FLib.sqlite3_total_changes(FHandle) - OldRowsAffected;
DetectUSEQuery(SQL);
CurrentSQL := NextSQL;
if Trim(CurrentSQL) = '' then

0 comments on commit b869181

Please sign in to comment.
You can’t perform that action at this time.