[yunqa.de] BLOB field is incorrectly being written into DB and truncated by BindDataSet - FIXED.

  • From: Jone Word <corabelster@xxxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Tue, 17 Feb 2009 19:45:59 +0300

Hi!

  There's an incorrect processing of BLOB field with BindDataSet, which
results
in incorrect posting of this field into DB using TDataSetProvider &
TDISQLite** objects.
This happens when BLOB data contains null (#0) characters. BLOB is being
treated as a string! I spent hours and hours finding why my BLOB object is
always being truncated.
 So I've corrected the code so now it works OK. The following is what I did:

OLD code (DISQLite3DataSet.pas):
--------------------------
 if f.IsBlob then
    sqlite3_check_stmt(sqlite3_bind_str(AStmt, i, Utf8String(Value)),
AStmt);
--------------------------

NEW code:
-------------------------
 SValue: String;
....
                  if f.IsBlob then
                    begin
                      if Old then
                        SValue := tblobfield(f).OldValue else
                            SValue := tblobfield(f).NewValue;
                       sqlite3_check_stmt(sqlite3_bind_blob(AStmt, i,
PAnsiChar(svalue), tblobfield(f).blobsize, SQLITE_TRANSIENT), AStmt);
                    end
----------------------------

Other related posts: