Solved

How to work with blob field

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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