ParamByName in MySql5

The alpha/beta tester's forum for ZeosLib 7.0.x series

Report problems concerning our Delphi 2009+ version and new Zeoslib 7.0 features here.

This is a forum that will be removed once the 7.X version goes into stable!!

Moderators: gto, EgonHugeist, olehs

Locked
trob
Senior Boarder
Senior Boarder
Posts: 51
Joined: 20.03.2007, 02:24

ParamByName in MySql5

Post 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?
Last edited by trob on 18.07.2010, 17:12, edited 1 time in total.
trob
Senior Boarder
Senior Boarder
Posts: 51
Joined: 20.03.2007, 02:24

Post by trob »

somebody?
trob
Senior Boarder
Senior Boarder
Posts: 51
Joined: 20.03.2007, 02:24

Post by trob »

Or anyway, how could i save a picture to db?
guidoaerts
Senior Boarder
Senior Boarder
Posts: 93
Joined: 01.07.2009, 16:07

Post by guidoaerts »

This works with Firebird...

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

Guido
Wild_Pointer
Expert Boarder
Expert Boarder
Posts: 164
Joined: 18.03.2008, 13:03
Contact:

Post 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...
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

trob,

Did the examples from Guido or Wild_Pointer help you?

Mark
Image
trob
Senior Boarder
Senior Boarder
Posts: 51
Joined: 20.03.2007, 02:24

Post 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.
Locked