3

I am using Delphi 7 with the FibPlus components . One of them being TpFIBQuery.

I am loading data from a table with the generic

select * from TableName where Key = 1

One of the fields returned is of type BLOB(Text).

I can't seem to get the value into a string list informatie using either of the following 3 ways :

Informatie.Text := FieldByName('Informatie').AsString  // Returns the string 'BLOB'
Informatie.Text := BlobAsString('Informatie')          // Returns ''
BlobToStrings('Informatie',Informatie)                 // Returns ''

I have confirmed using Database Workbench that the field in the table indeed contains the saved text.

Anyone ?

Edelcom
  • 5,038
  • 8
  • 44
  • 61

2 Answers2

2

usualy, i do like this

var 
   sl: TStrings; // blob IS NOT string!
   ms: TMemoryStream;
begin
   sl := TStringList.Create;
   ms := TMemoryStream.Create;
   try
     q.FieldByName('x').SaveToStream(ms);
     ms.Position := 0;
     sl.LoadFromStream(ms);
     // do what ever you want with sl here
     // and here too
   finally
     sl.Free;
     ms.Free;
   end; // try..finally
end;

note that q is your TpFibQuery object. also select * from table is bad bad practice. that habit eventually will lead you continuous headache.

jiang
  • 21
  • 1
  • Your problem produces the same as the ...AsString method. I have found the error though , see my answer . And oh yes, I do not actually use the `select * from ...` query, but in stead use a `select field, field2 ...`. This was just used to shorten the original question. – Edelcom Mar 24 '12 at 06:30
2

After trying the solution of @jiang, which produced the same error, I finally have found the culprit.

Turns out it was an error due to my part ( it usually is, you just have to find it ).

Turns out I had set the read transaction to False sometime during the processing/reading of the fields of the original query.

  • I perform a lookup in another table to get the description of a integer value in the query.
  • This lookup query uses the same read transaction , and sets this transaction to False after looking up the description.
  • AFter returning to the original query, reading integer and string fields pose no problem (although the read transaction has been set to False), but reading a BLOB field into a string with the ...AsString method produces an error or returns 'BLOB'.

Obviously I need to set the read transaction to True at the start of the read actions and set it to False after ALL read transactions. This is the major change when you convert a Paradox BDE application to a Firebird of Sqlserver application.


Anyway, I am glad I have found the solution. Hopefully it will help others too.

Edelcom
  • 5,038
  • 8
  • 44
  • 61