I have the following code for a simple key value store for binary data:
BeginPackage["keyValueStore`"];
{open, insert, get, close};
Begin["`Private`"];
Needs["DatabaseLink`"];
open[] := (
$connection = OpenSQLConnection[JDBC["SQLite(Memory)",""]];
SQLCreateTable[$connection, SQLTable["data"], {
SQLColumn["key", "DataTypeName" -> "TEXT"],
SQLColumn["value", "DataTypeName" -> "BLOB", "Nullable" -> True]
}];
);
insert[key_, data_] := SQLInsert[$connection,
"data", {"key", "value"}, {key, SQLBinary[data]}];
get[key_] := Replace[
SQLSelect[$connection, "data", "value", SQLColumn["key"] == key],
{{SQLBinary[data_]}} :> data
];
close[] := CloseSQLConnection[$connection];
End[];
EndPackage[];
which one could use like this:
open[];
insert["one", {1, 2, 3}]
get["one"]
close[];
if you try this, you will find that inserting data will not work but throw a message like:
DatabaseLink`JDBC::error: "Illegal value: DatabaseLink`SQLBinary[{1, 2, 3}]"
now I can repair that by either doing:
BeginPackage["keyValueStore`",{"DatabaseLink`"}]
(which I don't want) or by replacing SQLBinary
with Symbol["SQLBinary"]
in the code. Both seem to repair a behavior considering the context of SQLBinary
that I would consider a bug, but maybe just don't understand correctly what is going on. Would anyone agree that this is not as one would expect and should be repaired? Or can someone enlighten me why this is what I should expect?
Needs
to before theBegin
? $\endgroup$DatabaseLink`SQLBinary[{1, 2, 3}]
illegal or what? What should be the context ofSQLBinary
? $\endgroup$Databaselink`
is on$ContextPath
or thatSQLBinary
is created in the current$Context
... $\endgroup$$ContextPath
. The reason could be that there's some string-to-code translation somewhere in the package. Maybe through J/Link? A workaround could be to temporarily add"DatabaseLink`"
to the context path while your functions is being evaluated (usingInheritedBlock
). But this still bothers me ... $\endgroup$