Mega Search
23.2 Million


Sign Up

Make a donation  
TBlobField Delphi 2010 and XE2 (migration)  
News Group: embarcadero.public.delphi.database.interbase_express

Hi everybody. I have problem with blobfields in Delphi Xe2. In Delphi 2010 this code works great. 
This is how i saved to blobfield
{code}
    dane.SQLtmp.Close;
        dane.SQLtmp.SQL.Clear;
        dane.SQLtmp.SQL.Add('insert into  Wydruki (Nazwa,Operator,wydruk,opis,typ,rodzaj,podmiot,typsplaty,grupa,podgrupa)');
        dane.Sqltmp.SQL.Add('VALUES (:d0,:d1,:d2,:d3,:d4,:d5,:d6,:d7,:d8,:d9)');

dane.SQLtmp.Params[0].AsString:=NazwaPliku; //File name
dane.SQLtmp.Params[1].AsInteger:=glowny.ID_operator;

    t:=TMemoryStream.Create;
      t.Position:=0;
      t.LoadFromFile(OpenFile.FileName);

      t.Position:=0;

dane.sqltmp.Params[2].LoadFromStream(t,ftBlob);
dane.SQLtmp.Params[3].AsString:=opis;
dane.SQLtmp.Params[4].AsString:=typ;      // file type
// .
// .
// .
dane.SQLtmp.ExecSQL;
{code}

This is how i read blobfield

{code}
dane.SQLtmp.Close;
 dane.SQLtmp.SQL.Clear;
 dane.SQLtmp.SQL.Add('select wydruk,typ,IdWydruku from wydruki where nazwa=:d0');
 dane.SQLtmp.Params[0].AsString:=name;
 dane.SQLtmp.Open;

 if dane.SQLtmp.RecordCount> 0 then
begin

t:=TMemoryStream.Create;
t.Position:=0;

 TblobField(dane.sqltmp.FieldByName('wydruk')).saveToStream(T);
 T.SaveToFile('C:\FILE'+filetpe);
 t.Free;
end;
{code}

In Delphi Xe2 i get access denied on this line
{code}
 TblobField(dane.sqltmp.FieldByName('wydruk')).saveToStream(T);
{code}

or my file are in strange ecoding and have for example 1kb size

I use Interbase component like TIBDatabse, TIbQuery.

Maybe I should change something ?
Please Help. This Is very important to me

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 23-Dec-2014, at 12:58 AM EST
From: Sebastian Kumor
 
Re: TBlobField Delphi 2010 and XE2 (migration)  
News Group: embarcadero.public.delphi.database.interbase_express
Sebastian Kumor wrote:
> Hi everybody. I have problem with blobfields in Delphi Xe2. In Delphi 2010 this code works great. 
> This is how i saved to blobfield
> {code}
>     dane.SQLtmp.Close;
>         dane.SQLtmp.SQL.Clear;
>         dane.SQLtmp.SQL.Add('insert into  Wydruki (Nazwa,Operator,wydruk,opis,typ,rodzaj,podmiot,typsplaty,grupa,podgrupa)');
>         dane.Sqltmp.SQL.Add('VALUES (:d0,:d1,:d2,:d3,:d4,:d5,:d6,:d7,:d8,:d9)');
> 
> dane.SQLtmp.Params[0].AsString:=NazwaPliku; //File name
> dane.SQLtmp.Params[1].AsInteger:=glowny.ID_operator;
> 
>     t:=TMemoryStream.Create;
>       t.Position:=0;
>       t.LoadFromFile(OpenFile.FileName);
> 
>       t.Position:=0;
> 
> dane.sqltmp.Params[2].LoadFromStream(t,ftBlob);
> dane.SQLtmp.Params[3].AsString:=opis;
> dane.SQLtmp.Params[4].AsString:=typ;      // file type
> // .
> // .
> // .
> dane.SQLtmp.ExecSQL;
> {code}
> 
> This is how i read blobfield
> 
> {code}
> dane.SQLtmp.Close;
>  dane.SQLtmp.SQL.Clear;
>  dane.SQLtmp.SQL.Add('select wydruk,typ,IdWydruku from wydruki where nazwa=:d0');
>  dane.SQLtmp.Params[0].AsString:=name;
>  dane.SQLtmp.Open;
> 
>  if dane.SQLtmp.RecordCount> 0 then
> begin
> 
> t:=TMemoryStream.Create;
> t.Position:=0;
> 
>  TblobField(dane.sqltmp.FieldByName('wydruk')).saveToStream(T);
>  T.SaveToFile('C:\FILE'+filetpe);
>  t.Free;
> end;
> {code}
> 
> In Delphi Xe2 i get access denied on this line
> {code}
>  TblobField(dane.sqltmp.FieldByName('wydruk')).saveToStream(T);
> {code}
> 
> or my file are in strange ecoding and have for example 1kb size
> 
> I use Interbase component like TIBDatabse, TIbQuery.
> 
> Maybe I should change something ?
> Please Help. This Is very important to me

Why the extra moves in and out of the TMemoryStream?  Just create a BlobStrema 
from the field and call its LoadFromFile and SaveTofile.  You mentioned 
encoding, why would you do LoadFromStream with ftBlob which tells IBX there is 
no encoding.

   stream := dane.CreateBlobStream(dane.sqltmp.FieldByName('wydruk'), bmReadWrite);

What line does the access denied happen on.  Not your code, the DB code 
(doubtful this is happening at the IBX level but higher in the DB.pas level). 
If you don't already turn on use debug dcu's to be able to see into the VCL one 
exceptions like that.

-- 
Jeff Overcash (TeamB)
       (Please do not email me directly unless  asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted  corridors of Whitehall.
              (Fish)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 23-Dec-2014, at 8:27 AM EST
From: Jeff Overcash (TeamB)