Gossamer Forum
Home : General : Databases and SQL :

MySQL C API and Binary Data

Quote Reply
MySQL C API and Binary Data
I am having trouble selecting binary data from a MySQL database using the C API and writing it to a file. I believe I figured out inserting binary data, but I can't verify that until I can select it and write it to a file. Any help or examples would be appreciated. Thanks
Quote Reply
Re: [pstapley] MySQL C API and Binary Data In reply to
What problems are you having exactly?

Last edited by:

Paul: Aug 24, 2002, 6:06 PM
Quote Reply
Re: [Paul] MySQL C API and Binary Data In reply to
What function do I use to read the binary data out of the field? Do I use a strcpy to copy data from row[0]? I guess I am looking for the function to retrieve the data from the row and to copy it into my buffer. I am new to the MySQL C API and this is a tough topic to find even using Google.

Thanks,

Pete
Quote Reply
Re: [pstapley] MySQL C API and Binary Data In reply to
Is this any help?

http://www.ousob.com/miscdocs/mysqlapi.htm
Quote Reply
Re: [Paul] MySQL C API and Binary Data In reply to
I have already looked at that document, thanks though. I guess what I am looking for is the function that will return the binary data after I do a select. All I want to do is get the binary data into a buffer that I have malloced. I can't find any examples of this on the web.
Quote Reply
Re: [pstapley] MySQL C API and Binary Data In reply to
It's been a long time since I've played with the C api but I thought you handled binary data the same way you handled zero padded strings. Just that in this case, you must call mysql_fetch_lengths (as strlen misbehaves) and then do a memcpy into your new struct with the given value.
Quote Reply
Re: [Aki] MySQL C API and Binary Data In reply to
Okay easy enough, do you know what my src would be for the memcpy?
Quote Reply
Re: [pstapley] MySQL C API and Binary Data In reply to
Does this help?

http://www.mkssoftware.com/docs/man3/memcpy.3.asp

Just a note, if this is going to be a public C application, I'd say watch out. You're venturing to the world of buffer overflow attacks and unless you're quite experienced it may be better to do this in something like perl instead.
Quote Reply
Re: [Aki] MySQL C API and Binary Data In reply to
I understand memcpy, I am just wondering what src I am copying from (i.e. where is the binary data I am trying to copy?). memcpy(dst, src????, size). I don't see where I can get access to the binary data to copy it. Maybe I am just not understanding something. No this isn't a public application, just me messing around with the MySQL C API and brushing up on my C skills so it's not a big deal, just doing this for heck of it.
Quote Reply
Re: [pstapley] MySQL C API and Binary Data In reply to
You may want to take a look at the bottom of this document.

http://www.ousob.com/miscdocs/mysqlapi.htm