Solved

How to work with blob field

Posted on 2003-10-23
5
887 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

20 Experts available now in Live!

Get 1:1 Help Now