SQLBinary[data]
represents raw binary data that can be stored in a database.
Details and Options
Examples
Basic Examples
See Also
Tech Notes
Related Guides
DatabaseLink`
DatabaseLink`
SQLBinary
SQLBinary[data]
represents raw binary data that can be stored in a database.
Details and Options
- To use SQLBinary, you first need to load DatabaseLink using Needs["DatabaseLink`"].
Examples
Basic Examples (1)
Needs["DatabaseLink`"]If you find that the examples in this section do not work as shown, you may need to install or restore the example database with the "DatabaseLink`DatabaseExamples`" package, as described in Using the Example Databases.
conn = OpenSQLConnection["demo"]Create a table with a column to store binary data:
SQLCreateTable[conn, SQLTable["BINTABLE"], {SQLColumn["BINCOL", "DataTypeName" -> "BINARY", "DataLength" -> 5000]}];plot = Plot[Sin[x], {x, 0, 2 Pi}]Represent the image as a string in GIF format:
gif = ExportString[plot, "GIF"];Display the first few characters of the string:
StringTake[gif, 100]Convert the string into a list of bytes wrapped in SQLBinary:
byteData = SQLBinary[ToCharacterCode[gif]];SQLInsert[conn, "BINTABLE", {"BINCOL"}, {byteData}];data = SQLSelect[conn, "BINTABLE"];Convert the data back into a string:
gifData = FromCharacterCode[ data[[1, 1, 1]] ];ImportString[gifData, "GIF"]SQLDropTable[conn, "BINTABLE"];CloseSQLConnection[conn];