Skip to content

Commit 5c54203

Browse files
fix: read SQLite BLOB columns via sqlite3_column_blob instead of truncated text
Backport from lazarus branch. Refs #1980 Co-authored-by: ansgarbecker <ansgarbecker@users.noreply.github.com>
1 parent bd3ab46 commit 5c54203

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

‎source/dbconnection.pas‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3962,7 +3962,8 @@ procedure TSQLiteConnection.Query(SQL: String; DoStoreResult: Boolean=False; Log
39623962
Value: TGridValue;
39633963
QueryResult: Psqlite3_stmt;
39643964
QueryStatus: Integer;
3965-
i, OldRowsAffected: Integer;
3965+
i, NumBytes, OldRowsAffected: Integer;
3966+
AnsiStr: AnsiString;
39663967
CurrentSQL, NextSQL: PAnsiChar;
39673968
StepResult: Integer;
39683969
begin
@@ -3994,8 +3995,15 @@ procedure TSQLiteConnection.Query(SQL: String; DoStoreResult: Boolean=False; Log
39943995
Row := TGridRow.Create;
39953996
for i:=0 to FLib.sqlite3_column_count(QueryResult)-1 do begin
39963997
Value := TGridValue.Create;
3997-
Value.OldText := DecodeAPIString(FLib.sqlite3_column_text(QueryResult, i));
3998-
Value.OldIsNull := FLib.sqlite3_column_text(QueryResult, i) = nil;
3998+
if FLib.sqlite3_column_type(QueryResult, i) = SQLITE_BLOB then begin
3999+
NumBytes := FLib.sqlite3_column_bytes(QueryResult, i);
4000+
SetString(AnsiStr, PAnsiChar(FLib.sqlite3_column_blob(QueryResult, i)), NumBytes);
4001+
Value.OldText := String(AnsiStr);
4002+
Value.OldIsNull := False;
4003+
end else begin
4004+
Value.OldText := DecodeAPIString(FLib.sqlite3_column_text(QueryResult, i));
4005+
Value.OldIsNull := FLib.sqlite3_column_text(QueryResult, i) = nil;
4006+
end;
39994007
Row.Add(Value);
40004008
end;
40014009
Rows.Add(Row);

0 commit comments

Comments
 (0)