Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to work with blob field

Posted on 2003-10-23
5
Medium Priority
?
895 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Accepted Solution

by:
vk33 earned 136 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 132 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 132 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

597 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