-module(sqlite). -compile(export_all). query(Sql, DatabaseName) -> {ok, DB} = esqlite3:open(DatabaseName), Maps = queryFromDb(DB, Sql), esqlite3:close(DB), Maps. execute(Sql1, DatabaseName, SqlFileName) -> MyList = case unicode:characters_to_list(Sql1) of L when is_list(L) -> L; _ -> binary_to_list(Sql1) end, {ok,G} = file:open(SqlFileName,[write,{encoding,utf8}]), io:put_chars(G,MyList), file:close(G), {ok,Sql} = file:read_file(SqlFileName), file:delete(SqlFileName), {ok, DB} = esqlite3:open(DatabaseName), ok = esqlite3:exec(Sql, DB), esqlite3:close(DB). bitStrToStr([]) -> []; bitStrToStr([Value | T]) -> if is_bitstring(Value) == true -> TA = binary:bin_to_list(Value); is_atom(Value) == true -> TA = atomToStr(Value); is_integer(Value) == true -> TA = lists:flatten(io_lib:format("~w", [Value])); true -> TA = lists:flatten(io_lib:format("~w", [Value])) end, [TA | bitStrToStr(T)]. atomToStr(Value) -> ResTmp = lists:flatten(io_lib:format("~w", [Value])), Pos = string:str(ResTmp, "'"), if Pos == 1 -> Res = string:strip(ResTmp, both, $'); true -> Res = ResTmp end, Res. atomListToStrList([]) -> []; atomListToStrList([Value | T]) -> [atomToStr(Value) | atomListToStrList(T)]. rowsToList(Names, Row) -> A = atomListToStrList(tuple_to_list(Names)), B = bitStrToStr(tuple_to_list(Row)), lists:zip(A, B). queryFromDb(DB, Sql) -> AFun = fun(Names, Row) -> rowsToList(Names, Row) end, Maps = esqlite3:map(AFun, Sql, DB), Maps.