> Angus,
>
> On Fri, Dec 26, 2003 at 08:26:38PM -0500, Angus March wrote:
> > I'm trying to use the API to write to a MEDIUMBLOB, but I'm getting a
very
> > vague error: something about a problem "near '' on line 1". I'm
forumating
> > the query string w/
> >
> > sprintf(query, "INSERT INTO support_files
(session_id,file_type,file_body)
> > VALUES (%ld,%ld,", sessionID,fileType);
> >
> > Then w/calls to things like memcpy, and unformatted reads from a stream,
I
> > append the blob to the end of that, and finalize it w/a ')'. I'm very
>
> Well, your blob data may contain a NUL character, which will end your
> query string. It may contain quotes, a comma, ')' and other nasty stuff.
> You can't expect the MySQL parser to understand when these characters
> are part of your blob data and when they are meant to end your query or
> separate your query parameters. It is all just one single (long) query
> string that the parser needs to work with.
>
> So you will need to escape at least the following in your blob data:
>
> NUL because it is a C string terminator
> '   because it would terminate your blob 'string'
>
[snip]

Are you sure this is how it works? If you need to escape stuff, you aren't
dealing with binary data, you are dealing with a character string. The first
part starts off as a character string (with the "INSERT" and everything) but
the manual explicitly calls blob data in a query "binary". Furthermore, it
acknowledges the presence of string-unfriendly characters; specifically, the
'\0'. Check out:
http://www.mysql.com/documentation/mysql/bychapter/manual_Clients.html#mysql_real_query
The quote I'm thinking of is:
 You must use mysql_real_query() rather than mysql_query() for queries that
contain binary data, because binary data may contain the `\0' character


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to