SciBit

Forums
It is currently Mon Dec 22, 2014 9:06 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Fri Feb 18, 2005 6:25 am 
Site Admin

Joined: Wed May 21, 2003 7:41 am
Posts: 951
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 SQL
Of 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 Macro
When 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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group