Problem updating Blob fields using TDBXCommand (Delphi 2010)

Problem updating Blob fields using TDBXCommand (Delphi 2010)

Postby F10Software » Wed 28 Jul 2010 22:05

{It runs fine but only blob fields are not updated, Blob just remains Null}

function TfrmMain.TesteUpdateBlob: Integer;
var
Con: TSQLConnection;
Command: TDBXCommand;
ParamVarchar, ParamBlob: TDBXParameter;
begin
try
{Connecting}
Con := TSQLConnection.Create(Self);
Con.DriverName := 'DevartInterBase';
Con.GetDriverFunc := 'getSQLDriverInterBase';
Con.LibraryName := 'dbexpida40.dll';
Con.VendorLib := 'fbclient.dll';
Con.LoginPrompt := False;
Con.Params.Add('DriverName=DevartInterBase');
Con.Params.Add('DataBase=C:\Teste.fdb');
Con.Params.Add('User_Name=SYSDBA');
Con.Params.Add('Password=masterkey');
Con.Params.Add('SQLDialect=3');
Con.Params.Add('BlobSize=-1');
Con.Params.Add('WaitOnLocks=True');
Con.Params.Add('Charset=Win1252');
Con.Params.Add('CharLength=1');
Con.Params.Add('EnableBCD=True');
Con.Params.Add('OptimizedNumerics=True');
Con.Params.Add('LongStrings=True');
Con.Params.Add('UseQuoteChar=False');
Con.Params.Add('FetchAll=False');
Con.Open;

{Creating Command but using TDBXCommand instead of TSQLQuery}

Command := Con.DBXConnection.CreateCommand;
Command.CommandType := TDBXCommandTypes.DbxSQL;
Command.Text := 'update table set field_varchar = ?, field_blob = ? where id = 1';

{Some VarChar Params}

ParamVarchar := TDBXParameter.Create;
ParamVarchar.DataType := TDBXDataTypes.AnsiStringType;
ParamVarchar.Value.SetAnsiString('Teste');

{A Blob Param}
ParamBlob := TDBXParameter.Create;
ParamBlob.DataType := TDBXDataTypes.BlobType;
ParamBlob.Value.SetStream(TFileStream.Create('C:\Arquivo.teste', fmOpenRead), True);

{Setting values for them}
Command.Parameters.AddParameter(ParamVarchar);
Command.Parameters.AddParameter(ParamBlob);

Command.ExecuteUpdate;
Result := Command.RowsAffected;
finally
if Assigned(Con) then begin
if Con.Connected then
Con.Close;
FreeAndNil(Con);
end;
if Assigned(Command) then
FreeAndNil(Command);
if Assigned(ParamVarchar) then
FreeAndNil(ParamVarchar);
if Assigned(ParamBlob) then
FreeAndNil(ParamBlob);
end;
end;

{I'm using your 2.50 DBXIDA driver with Firebird 2.13}
F10Software
 
Posts: 2
Joined: Sat 20 Dec 2008 10:53

Postby Dimon » Thu 29 Jul 2010 16:08

This problem is connected with the specificity of work of TDBXParameter. To solve the problem insert the folowing code:

ParamBlob.Value.SetStream(TFileStream.Create('C:\Arquivo.teste', fmOpenRead), True); //it's your code
ParamBlob.Value.ValueType.ValueTypeFlags := ParamBlob.Value.ValueType.ValueTypeFlags or TDBXValueTypeFlags.ExtendedType;
Dimon
Devart Team
 
Posts: 2885
Joined: Mon 05 Mar 2007 16:32


Return to dbExpress driver for InterBase & Firebird