IBX and BLOB update lazarus / 16-Databases ---------------------------------------------------------------------- sydenis · 2021-06-30 17:51 Ubuntu 20.04 + Lazarus 2.0.12 I use the IBSQL component from ibx4lazarus2. 4-0 to access the Firebird 3 database I need to write and read a BLOB field from my database. There are no problems with reading from db: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i IBSQL1.FieldByName('blob').AsBlob.SaveToFile(MyFile);I get the desired file. But writing to db does not work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i IBSQL1.ParamByName('blob').AsBlob.LoadFromFile(MyFile);error - External: SIGSEGV What is the problem? Looking the error it seem that ParamByName ('blob') does not exist? How to do it correctly? ---------------------------------------------------------------------- devEric69 · 2021-07-01 07:48 On one line you used FieldByName to save, but on the other line you wrote ParamByName to load: is this normal? ---------------------------------------------------------------------- sydenis · 2021-07-01 12:20 I guess yes. Here is code sample: read from db: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   with IBSLQ1 do  begin    SQL.Text:='select blob_field from tab1 where id=1;';    Transaction.StartTransaction;    ExecQuery;    FieldByName('blob_field').AsBlob.SaveToFile('image.bin');    .....write to db: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   with IBSQL1 do  begin    SQL.Text:='update tab1 set blob_field=:blob_field where id=1;';    Transaction.StartTransaction;    ParamByName('blob_field').AsBlob.LoadFromFile('image.bin');    ExecQuery;     .....What is wrong? ---------------------------------------------------------------------- tonyw · 2021-07-03 09:28 Quote from: sydenis on June 30, 2021, 07:51:39 pmUbuntu 20.04 + Lazarus 2.0.12 I use the IBSQL component from ibx4lazarus2. 4-0 to access the Firebird 3 database I need to write and read a BLOB field from my database. There are no problems with reading from db: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i IBSQL1.FieldByName('blob').AsBlob.SaveToFile(MyFile);I get the desired file. But writing to db does not work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i IBSQL1.ParamByName('blob').AsBlob.LoadFromFile(MyFile);The problem is that you are using TIBSQL in the way that you would use TIBDataset. However, TIBSQL is working directly with the underlying Firebird interface and that requires a different approach. The call to ParamByName('blob').AsBlob returns the interface IBlob. The input parameter has not yet been set and so this always returns nil - hence the exception. To set the value of the blob, you have to create a TIBBlobstream, load it from a file and assign the IBlob interface returned by TIBBlobStream to the param e.g. var b:TIBBlobStream; begin   b := TIBBlobStream.create;  try    b.Database := IBSQL.Database;   b.Mode := bmWrite;     b.LoadFromFile(...);     IBSQL.ParamByName('blob').asBlob := b.blob;   finally     b.free;   end; ---------------------------------------------------------------------- sydenis · 2021-07-05 13:03 Tony, thank you very much! I used your advice and everything works fine. My self I found a solution through asQuad: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    b.LoadFromFile(...);   b.Finalize;   IBSQL1.ParamByName('blob').AsQuad  := b.BlobID; thank you again ---------------------------------------------------------------------- tonyw · 2021-07-05 13:49 Quote from: sydenis on July 05, 2021, 03:03:41 pmTony, thank you very much! I used your advice and everything works fine. My self I found a solution through asQuad: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    b.LoadFromFile(...);   b.Finalize;   IBSQL1.ParamByName('blob').AsQuad  := b.BlobID; thank you again Yes - that is an equivalent statement.