Solved

How to work with blob field

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

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

724 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