1.6 An Important Note on BLOBs

Binary data can be sent to the MySQL server using either a normal (string-based) query or via a prepared statement. In the former case, the format-sql procedure, exported by format.ss, is helpful to ensure proper encoding and escaping. In particular, because the character encoding of the connection is ignored by the server for the purpose of decoding data destined for binary storage, MySQL query strings, in their full generality, aren’t really strings (in the Scheme sense), at all. They’re binary data. In order to treat them as strings (for ease of use), the format-sql procedure will hex encode byte strings, using the MySQL syntax. Note that hex encoding data doubles its original size, so if you plan to send large amounts of data to the server, it is best to use prepared statements.

With prepared statements, you can use virtually any kind of Scheme data you want as your parameter argument. However, the only sensible choices for binary data are byte strings and input ports. Input ports may be preferable for sending large amounts of data that does not all need to be kept in RAM at once. The client library will only read about 1MB of data at a time from an input port.

The library will treat input port arguments to prepared statements as "long data" (see MySQL Internals: Client/Server Protocol, but don’t take it too seriously, since the description of the packet is incorrect), which is sent to the server separately from the main execution packet and may be broken up into multiple packets, if necessary.