This question pops up often, but the solution is not specific to MyComponents, and will work in and with any Borland dataset component (in fact, this is how you are suppose to do it in Delphi/Kylix):
File or Stream:
Code:
TBlobField(MySQLQuery1.FieldByName('MyBlob')).LoadFromFile('MyBlobContents.doc');
the following of course also works:
TBlobField(MySQLQuery1.FieldByName('MyBlob')).SaveToFile('MyBlobContents.doc');
or you can also use the LoadFromStream and SaveToStream methods.
NOTE: If you post blobs to a table in MySQL you should keep a couple of things in mind:
1. The blob value is sent to the MySQL using a standard SQL statement. For this purpose, the value is hexed by the dataset and thus 2 SQL characters=1 blob byte.
2. Most MySQL servers' "max_allowed_packet" variable is set to a default value of less than 1Mb and a single sql statement must fit within one packet and thus within this variable's value. Thus if you submit a 1Mb blob then this variable needs to be at least 2Mb in size else you will get a 2006 - "MySQL server has gone away" or 2013 - "Lost connection to mysql server " error.
Own SQLOf course, if you wish to compile your own SQL to insert or update a BLOB column, should you utilize the Dataset.EscStr or MySQLServer.EscapeStr methods at the very minimum to correctly escape any clashing embedded values inside the value. Best method, however, is to use Dataset.HexStr to convert your blob value to the hexed equavalent, ex:
Code:
Dataset.ExecSQL('insert into myblobtable set BlobField="'+Dataset.EscStr(Memo.Lines.Text)+'"');
Dataset.ExecSQL('insert into myblobtable set BlobField='+Dataset.HexStr(Memo.Lines.Text));
Using TField or a MacroWhen you use the default TField or dataset macros are blob values automatically handled for you, ex:
Code:
TBlobField(Dataset.FieldByName('BlobField')).AsString := Memo.Lines.Text;
Dataset.MacroByName('BlobValueMacro').AsString := Memo.Lines.Text;
Hope this helps. For further information on this and related issues:
http://dev.mysql.com/doc/refman/5.0/en/ ... large.html
Best wishes, Support