SQLBinary
SQLBinary[data]
represents raw binary data that can be stored in a database.
更多信息和选项
范例
基本范例
参见
技术笔记
相关指南
DatabaseLink`
DatabaseLink`
SQLBinary
SQLBinary[data]
represents raw binary data that can be stored in a database.
更多信息和选项
- To use SQLBinary, you first need to load DatabaseLink using Needs["DatabaseLink`"].
范例
基本范例 (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];