Page 1 of 1

ParamByName in MySql5

Posted: 13.07.2010, 14:09
by trob
Hello

I want to set a MediumBlob field in a MySQL5 db. I use this code:

Code: Select all

ZQuery1.SQL.Text:='UPDATE table SET photo=:pic WHERE key=123';
ZQuery1.Params.ParamByName('pic').Assign(Image1.Picture.Graphic);
ZQuery1.ExecSQL;
Now, in Zeos7 i get an error message:
Unsupported data type.

In the log of MySQL:
UPDATE table SET photo=? WHERE key=123


It seems like if adding parameters does not work. I tried it with a simple string field too, and i get the same errors.


Could you help me?

Posted: 17.07.2010, 21:26
by trob
somebody?

Posted: 18.07.2010, 16:11
by trob
Or anyway, how could i save a picture to db?

Posted: 19.07.2010, 12:33
by guidoaerts
This works with Firebird...

begin
TBlobField(fieldbyname('foto')).Clear;
TBlobField(fieldbyname('foto')).LoadFromFile(OpenPictureDialog.FileName);
end;

Guido

Posted: 19.07.2010, 15:02
by Wild_Pointer
For postgresql:

Code: Select all

var j : TJpegImage;
begin
  
  if not od.Execute then
    Exit;
  j := TJpegImage.Create;
  try
    j.LoadFromFile(od.FileName);
    if not (qfoto.State in [dsInsert, dsEdit]) then qFoto.Edit;
    qFotofoto_nuotrauka.Assign(j);
    j.Free;
  except
    ShowMessage(RS_FILE_IS_NOT_JPEG);
  end;
od is opendialog there...

Posted: 29.08.2010, 23:38
by mdaems
trob,

Did the examples from Guido or Wild_Pointer help you?

Mark

Posted: 30.08.2010, 11:46
by trob
I did not try it.

I find what was the problem. In the old version, i just assign the picture data to the param, and it automaticly add escape chacters where it need.

Now, it works if i convert the whole picture to hexadecimal character-pairs, and then assign it to the param or just simple set its value with :=.

In the old method, the data size was about 1.6x of the original data by the escape chars, so the hexa pairs doubling is not so terrible.