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
Aug 25, 2002, 12:15 AM
Novice (5 posts)
Aug 25, 2002, 12:15 AM
Post #3 of 10
Views: 13272
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
Thanks,
Pete
Aug 25, 2002, 9:46 AM
Novice (5 posts)
Aug 25, 2002, 9:46 AM
Post #5 of 10
Views: 13195
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.
Aug 25, 2002, 11:27 AM
Staff / Moderator (429 posts)
Aug 25, 2002, 11:27 AM
Post #6 of 10
Views: 13137
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.
Aug 25, 2002, 1:24 PM
Staff / Moderator (429 posts)
Aug 25, 2002, 1:24 PM
Post #8 of 10
Views: 13088
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.
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.
Aug 25, 2002, 1:31 PM
Novice (5 posts)
Aug 25, 2002, 1:31 PM
Post #9 of 10
Views: 13076
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.
Aug 25, 2002, 8:53 PM
Staff / Moderator (429 posts)
Aug 25, 2002, 8:53 PM
Post #10 of 10
Views: 13014
You may want to take a look at the bottom of this document.
http://www.ousob.com/miscdocs/mysqlapi.htm
http://www.ousob.com/miscdocs/mysqlapi.htm