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'

And put the whole thing in single quotes.

E.g. if your blob contains the following:

NUL NUL ' a b c LF x

Your query would look something like this:

INSERT INTO support_files (session_id,file_type,file_body) VALUES 
(123,456,'\0\0\'abc\nx');

Or you can get away with leaving the linefeed as it is:

INSERT INTO support_files (session_id,file_type,file_body) VALUES (123,456,'\0\0\'abc
x');

Your mail reader may mess things up, but there is a single line-break in
the example, just after abc.


Regards,

Fred.

-- 
Fred van Engen                              XB Networks B.V.
email: [EMAIL PROTECTED]                Televisieweg 2
tel: +31 36 5462400                         1322 AC  Almere
fax: +31 36 5462424                         The Netherlands

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

Reply via email to