Solved

How to work with blob field

Posted on 2003-10-23
5
886 Views
Last Modified: 2008-03-03
Hello !
Plese guide me how to work (update, insert) with blob field in mysql. I do like to use mysql api, because its
platform independence.
thankyou very much
0
Comment
Question by:DavidThanh
5 Comments
 
LVL 4

Accepted Solution

by:
vk33 earned 34 total points
ID: 9612309
Have a look here for a quickstart:
http://www.mysql.com/doc/en/BLOB.html

If you have some specific questions - feel free to ask.

Regards!
0
 
LVL 17

Assisted Solution

by:Squeebee
Squeebee earned 33 total points
ID: 9613839
I wrote up blob handling for vb at www.vbmysql.com/articles/blobaccessvb.html
It's won't help with the API, but it will help with some blob handling principles.
0
 
LVL 7

Assisted Solution

by:jconde
jconde earned 33 total points
ID: 9720867
mysql blob fields are very easy to handle.

What you need to be sure of is you make use of mysql_real_escape before you insert any data into your blob field!

In order to retrieve data from the blob field, make sure you use mysql_fetch_lengths as that will give you the right size of the data stored in the blob field (unlike mysql_res->length which returns the max column length).  Calling strlen(mysqlRow[index]) will fail if your BLOB field contains binary data because you might have a NULL character somewhere.

ohh, also ... when you insert binary data into a blob field, make sure you use mysql_real_query() because as stated above, your blob data might contain a NULL characters and still be part of the data.  That's why you'll need to provide a length parameter to mysql_real_query().

here's a C example of how to do what I mentioned above ...

char query[1000],*end;

end = strmov(query,"INSERT INTO test_table values(");
*end++ = '\'';
end += mysql_real_escape_string(&mysql, end,"What's this",11);
*end++ = '\'';
*end++ = ',';
*end++ = '\'';
end += mysql_real_escape_string(&mysql, end,"binary data: \0\r\n",16);
*end++ = '\'';
*end++ = ')';

if (mysql_real_query(&mysql,query,(unsigned int) (end - query)))
{
   fprintf(stderr, "Failed to insert row, Error: %s\n",
           mysql_error(&mysql));
}
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now