Adapt for running from escript.
This commit is contained in:
@@ -82,12 +82,33 @@
|
|||||||
|
|
||||||
init() ->
|
init() ->
|
||||||
NifName = "esqlite3_nif",
|
NifName = "esqlite3_nif",
|
||||||
NifFileName = case code:priv_dir(esqlite) of
|
NifFileName = filename:join(get_priv_dir(), NifName),
|
||||||
{error, bad_name} -> filename:join("priv", NifName);
|
|
||||||
Dir -> filename:join(Dir, NifName)
|
|
||||||
end,
|
|
||||||
ok = erlang:load_nif(NifFileName, 0).
|
ok = erlang:load_nif(NifFileName, 0).
|
||||||
|
|
||||||
|
%% @private
|
||||||
|
get_priv_dir() ->
|
||||||
|
case code:priv_dir(esqlite) of
|
||||||
|
{error, bad_name} ->
|
||||||
|
%% application isn't in path, fall back
|
||||||
|
case is_escript() of
|
||||||
|
{true,Escript} ->
|
||||||
|
io:format("Escript = ~p~n", [Escript]),
|
||||||
|
Which = code:which(esqlite),
|
||||||
|
io:format("Which = ~p~n", [Which]),
|
||||||
|
{Pref,Suf} = lists:split(erlang:length(Escript), Which),
|
||||||
|
io:format("Pref = ~p~n", [Pref]),
|
||||||
|
io:format("Suf = ~p~n", [Suf]),
|
||||||
|
RootDir = filename:dirname(filename:dirname(Pref)),
|
||||||
|
AppsDir = filename:join(RootDir, "lib"),
|
||||||
|
io:format("AppsDir = ~p~n", [AppsDir]),
|
||||||
|
SqDir = filename:dirname(filename:dirname(Suf)),
|
||||||
|
filename:join([AppsDir, [$.|SqDir], "priv"]); % prepend "." to suffix that starts with "/"
|
||||||
|
false ->
|
||||||
|
filename:join("priv", NifName)
|
||||||
|
end;
|
||||||
|
Dir ->
|
||||||
|
Dir
|
||||||
|
end.
|
||||||
|
|
||||||
%% @doc Open the specified sqlite3 database.
|
%% @doc Open the specified sqlite3 database.
|
||||||
%% It is possible to use sqlite's uri filenames to open files.
|
%% It is possible to use sqlite's uri filenames to open files.
|
||||||
|
|||||||
Reference in New Issue
Block a user