Formatting fixed
This commit is contained in:
123
src/sqlite3.erl
123
src/sqlite3.erl
@@ -53,8 +53,9 @@
|
|||||||
%% To open multiple dbases on the same node use open/1 or open/2.
|
%% To open multiple dbases on the same node use open/1 or open/2.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-type(result() :: {'ok', pid()} | 'ignore' | {'error', any()}).
|
-type result() :: {'ok', pid()} | 'ignore' | {'error', any()}.
|
||||||
-spec(start_link/1::(atom()) -> result()).
|
|
||||||
|
-spec start_link(atom()) -> result().
|
||||||
|
|
||||||
start_link(Db) ->
|
start_link(Db) ->
|
||||||
?MODULE:open(Db, [{db, "./" ++ atom_to_list(Db) ++ ".db"}]).
|
?MODULE:open(Db, [{db, "./" ++ atom_to_list(Db) ++ ".db"}]).
|
||||||
@@ -74,7 +75,7 @@ start_link(Db) ->
|
|||||||
%% To open multiple dbases on the same node use open/1 or open/2.
|
%% To open multiple dbases on the same node use open/1 or open/2.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(start_link/2::(atom(), [{atom(), any()}]) -> result()).
|
-spec start_link(atom(), [{atom(), any()}]) -> result().
|
||||||
start_link(Db, Options) ->
|
start_link(Db, Options) ->
|
||||||
Opts = case proplists:get_value(db, Options) of
|
Opts = case proplists:get_value(db, Options) of
|
||||||
undefined -> [{db, "./" ++ atom_to_list(Db) ++ ".db"} | Options];
|
undefined -> [{db, "./" ++ atom_to_list(Db) ++ ".db"} | Options];
|
||||||
@@ -92,7 +93,7 @@ start_link(Db, Options) ->
|
|||||||
%% and drop_table/2.
|
%% and drop_table/2.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(open/1::(atom()) -> result()).
|
-spec open(atom()) -> result().
|
||||||
open(Db) ->
|
open(Db) ->
|
||||||
?MODULE:open(Db, [{db, "./" ++ atom_to_list(Db) ++ ".db"}]).
|
?MODULE:open(Db, [{db, "./" ++ atom_to_list(Db) ++ ".db"}]).
|
||||||
|
|
||||||
@@ -108,7 +109,7 @@ open(Db) ->
|
|||||||
%% and drop_table/2.
|
%% and drop_table/2.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(open/2::(atom(), [{atom(), any()}]) -> result()).
|
-spec open(atom(), [{atom(), any()}]) -> result().
|
||||||
open(Db, Options) ->
|
open(Db, Options) ->
|
||||||
gen_server:start_link({local, Db}, ?MODULE, Options, []).
|
gen_server:start_link({local, Db}, ?MODULE, Options, []).
|
||||||
|
|
||||||
@@ -118,7 +119,7 @@ open(Db, Options) ->
|
|||||||
%% Closes the Db sqlite3 dbase.
|
%% Closes the Db sqlite3 dbase.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(close/1::(atom()) -> 'ok').
|
-spec close(atom()) -> 'ok'.
|
||||||
close(Db) ->
|
close(Db) ->
|
||||||
gen_server:call(Db, close).
|
gen_server:call(Db, close).
|
||||||
|
|
||||||
@@ -128,7 +129,7 @@ close(Db) ->
|
|||||||
%% Closes the sqlite3 dbase.
|
%% Closes the sqlite3 dbase.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(stop/0::() -> 'ok').
|
-spec stop() -> 'ok'.
|
||||||
stop() ->
|
stop() ->
|
||||||
?MODULE:close(?MODULE).
|
?MODULE:close(?MODULE).
|
||||||
|
|
||||||
@@ -138,7 +139,7 @@ stop() ->
|
|||||||
%% Executes the Sql statement directly.
|
%% Executes the Sql statement directly.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(sql_exec/1::(string()) -> any()).
|
-spec sql_exec(string()) -> any().
|
||||||
sql_exec(SQL) ->
|
sql_exec(SQL) ->
|
||||||
?MODULE:sql_exec(?MODULE, SQL).
|
?MODULE:sql_exec(?MODULE, SQL).
|
||||||
|
|
||||||
@@ -149,7 +150,7 @@ sql_exec(SQL) ->
|
|||||||
%% result of the Sql call.
|
%% result of the Sql call.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(sql_exec/2::(atom(), string()) -> any()).
|
-spec sql_exec(atom(), string()) -> any().
|
||||||
sql_exec(Db, SQL) ->
|
sql_exec(Db, SQL) ->
|
||||||
gen_server:call(Db, {sql_exec, SQL}).
|
gen_server:call(Db, {sql_exec, SQL}).
|
||||||
|
|
||||||
@@ -163,7 +164,7 @@ sql_exec(Db, SQL) ->
|
|||||||
%% Returns the result of the create table call.
|
%% Returns the result of the create table call.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(create_table/2::(atom(), [tuple()]) -> any()).
|
-spec create_table(atom(), [tuple()]) -> any().
|
||||||
create_table(Tbl, Options) ->
|
create_table(Tbl, Options) ->
|
||||||
?MODULE:create_table(?MODULE, Tbl, Options).
|
?MODULE:create_table(?MODULE, Tbl, Options).
|
||||||
|
|
||||||
@@ -177,7 +178,7 @@ create_table(Tbl, Options) ->
|
|||||||
%% Returns the result of the create table call.
|
%% Returns the result of the create table call.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(create_table/3::(atom(), atom(), [{atom(), any()}]) -> any()).
|
-spec create_table(atom(), atom(), [{atom(), any()}]) -> any().
|
||||||
create_table(Db, Tbl, Options) ->
|
create_table(Db, Tbl, Options) ->
|
||||||
gen_server:call(Db, {create_table, Tbl, Options}).
|
gen_server:call(Db, {create_table, Tbl, Options}).
|
||||||
|
|
||||||
@@ -187,7 +188,7 @@ create_table(Db, Tbl, Options) ->
|
|||||||
%% Returns a list of tables.
|
%% Returns a list of tables.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(list_tables/0::() -> [atom()]).
|
-spec list_tables() -> [atom()].
|
||||||
list_tables() ->
|
list_tables() ->
|
||||||
?MODULE:list_tables(?MODULE).
|
?MODULE:list_tables(?MODULE).
|
||||||
|
|
||||||
@@ -197,7 +198,7 @@ list_tables() ->
|
|||||||
%% Returns a list of tables for Db.
|
%% Returns a list of tables for Db.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(list_tables/1::(atom()) -> [atom()]).
|
-spec list_tables(atom()) -> [atom()].
|
||||||
list_tables(Db) ->
|
list_tables(Db) ->
|
||||||
gen_server:call(Db, list_tables).
|
gen_server:call(Db, list_tables).
|
||||||
|
|
||||||
@@ -207,7 +208,7 @@ list_tables(Db) ->
|
|||||||
%% Returns table schema for Tbl.
|
%% Returns table schema for Tbl.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(table_info/1::(atom()) -> [any()]).
|
-spec table_info(atom()) -> [any()].
|
||||||
table_info(Tbl) ->
|
table_info(Tbl) ->
|
||||||
?MODULE:table_info(?MODULE, Tbl).
|
?MODULE:table_info(?MODULE, Tbl).
|
||||||
|
|
||||||
@@ -217,7 +218,7 @@ table_info(Tbl) ->
|
|||||||
%% Returns table schema for Tbl in Db.
|
%% Returns table schema for Tbl in Db.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(table_info/2::(atom(), atom()) -> [any()]).
|
-spec table_info(atom(), atom()) -> [any()].
|
||||||
table_info(Db, Tbl) ->
|
table_info(Db, Tbl) ->
|
||||||
gen_server:call(Db, {table_info, Tbl}).
|
gen_server:call(Db, {table_info, Tbl}).
|
||||||
|
|
||||||
@@ -229,7 +230,7 @@ table_info(Db, Tbl) ->
|
|||||||
%% determined from table_info/2.
|
%% determined from table_info/2.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(write/2::(atom(), [{atom(), any()}]) -> any()).
|
-spec write(atom(), [{atom(), any()}]) -> any().
|
||||||
write(Tbl, Data) ->
|
write(Tbl, Data) ->
|
||||||
?MODULE:write(?MODULE, Tbl, Data).
|
?MODULE:write(?MODULE, Tbl, Data).
|
||||||
|
|
||||||
@@ -241,38 +242,38 @@ write(Tbl, Data) ->
|
|||||||
%% same type as determined from table_info/3.
|
%% same type as determined from table_info/3.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(write/3::(atom(), atom(), [{atom(), any()}]) -> any()).
|
-spec write(atom(), atom(), [{atom(), any()}]) -> any().
|
||||||
write(Db, Tbl, Data) ->
|
write(Db, Tbl, Data) ->
|
||||||
gen_server:call(Db, {write, Tbl, Data}).
|
gen_server:call(Db, {write, Tbl, Data}).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @spec update (Tbl::atom (), Key::atom (), Value, Data) -> Result
|
%% @spec update(Tbl :: atom(), Key :: atom(), Value, Data) -> Result
|
||||||
%% Value = any ()
|
%% Value = any()
|
||||||
%% Data = [{Column::atom (), Value::string () | integer () | float ()}]
|
%% Data = [{Column :: atom(), Value :: string() | integer() | float()}]
|
||||||
%% Result = {ok, ID} | Unknown
|
%% Result = {ok, ID} | Unknown
|
||||||
%% Unknown = term ()
|
%% Unknown = term()
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Updates rows into Tbl table such that the Value matches the
|
%% Updates rows into Tbl table such that the Value matches the
|
||||||
%% value in Key with Data. Returns ID of the first updated
|
%% value in Key with Data. Returns ID of the first updated
|
||||||
%% record.
|
%% record.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
update (Tbl, Key, Value, Data) ->
|
update(Tbl, Key, Value, Data) ->
|
||||||
?MODULE:update(?MODULE, Tbl, Key, Value, Data).
|
?MODULE:update(?MODULE, Tbl, Key, Value, Data).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @spec update (Db::atom (), Tbl::atom (), Key::atom (), Value, Data) -> Result
|
%% @spec update(Db::atom(), Tbl::atom(), Key::atom(), Value, Data) -> Result
|
||||||
%% Value = any ()
|
%% Value = any()
|
||||||
%% Data = [{Column::atom (), Value::string () | integer () | float ()}]
|
%% Data = [{Column::atom(), Value::string() | integer() | float()}]
|
||||||
%% Result = {ok, ID} | Unknown
|
%% Result = {ok, ID} | Unknown
|
||||||
%% Unknown = term ()
|
%% Unknown = term()
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Updates rows into Tbl table in Db dbase such that the Value
|
%% Updates rows into Tbl table in Db dbase such that the Value
|
||||||
%% matches the value in Key with Data. Returns ID of the first
|
%% matches the value in Key with Data. Returns ID of the first
|
||||||
%% updated record.
|
%% updated record.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
update (Db, Tbl, Key, Value, Data) ->
|
update(Db, Tbl, Key, Value, Data) ->
|
||||||
gen_server:call(Db, {update, Tbl, Key, Value, Data}).
|
gen_server:call(Db, {update, Tbl, Key, Value, Data}).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
@@ -284,7 +285,7 @@ update (Db, Tbl, Key, Value, Data) ->
|
|||||||
%% have the same type as determined from table_info/2.
|
%% have the same type as determined from table_info/2.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(read/2::(atom(), {atom(), any()}) -> any()).
|
-spec read(atom(), {atom(), any()}) -> any().
|
||||||
read(Tbl, Key) ->
|
read(Tbl, Key) ->
|
||||||
?MODULE:read(?MODULE, Tbl, Key).
|
?MODULE:read(?MODULE, Tbl, Key).
|
||||||
|
|
||||||
@@ -297,16 +298,16 @@ read(Tbl, Key) ->
|
|||||||
%% ColValue must have the same type as determined from table_info/3.
|
%% ColValue must have the same type as determined from table_info/3.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(read/3::(atom(), atom(), {atom(), any()}) -> any()).
|
-spec read(atom(), atom(), {atom(), any()}) -> any().
|
||||||
read(Db, Tbl, Key) ->
|
read(Db, Tbl, Key) ->
|
||||||
gen_server:call(Db, {read, Tbl, Key}).
|
gen_server:call(Db, {read, Tbl, Key}).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @spec read (Db, Tbl, Key, Columns) -> [term ()]
|
%% @spec read(Db, Tbl, Key, Columns) -> [term()]
|
||||||
%% Db = atom ()
|
%% Db = atom()
|
||||||
%% Tbl = atom ()
|
%% Tbl = atom()
|
||||||
%% Key = {Column::atom (), Value::term ()}
|
%% Key = {Column::atom(), Value::term()}
|
||||||
%% Columns = [atom ()]
|
%% Columns = [atom()]
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Reads a row from Tbl table in Db dbase such that the Value
|
%% Reads a row from Tbl table in Db dbase such that the Value
|
||||||
%% matches the value in Column. Returns columns Columns only for
|
%% matches the value in Column. Returns columns Columns only for
|
||||||
@@ -314,7 +315,7 @@ read(Db, Tbl, Key) ->
|
|||||||
%% from table_info/3.
|
%% from table_info/3.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
read (Db, Tbl, Key, Columns) ->
|
read(Db, Tbl, Key, Columns) ->
|
||||||
gen_server:call(Db, {read, Tbl, Key, Columns}).
|
gen_server:call(Db, {read, Tbl, Key, Columns}).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
@@ -326,7 +327,7 @@ read (Db, Tbl, Key, Columns) ->
|
|||||||
%% ColValue must have the same type as determined from table_info/3.
|
%% ColValue must have the same type as determined from table_info/3.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(delete/2::(atom(), {atom(), any()}) -> any()).
|
-spec delete(atom(), {atom(), any()}) -> any().
|
||||||
delete(Tbl, Key) ->
|
delete(Tbl, Key) ->
|
||||||
?MODULE:delete(?MODULE, Tbl, Key).
|
?MODULE:delete(?MODULE, Tbl, Key).
|
||||||
|
|
||||||
@@ -339,7 +340,7 @@ delete(Tbl, Key) ->
|
|||||||
%% ColValue must have the same type as determined from table_info/3.
|
%% ColValue must have the same type as determined from table_info/3.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(delete/3::(atom(), atom(), {atom(), any()}) -> any()).
|
-spec delete(atom(), atom(), {atom(), any()}) -> any().
|
||||||
delete(Db, Tbl, Key) ->
|
delete(Db, Tbl, Key) ->
|
||||||
gen_server:call(Db, {delete, Tbl, Key}).
|
gen_server:call(Db, {delete, Tbl, Key}).
|
||||||
|
|
||||||
@@ -349,7 +350,7 @@ delete(Db, Tbl, Key) ->
|
|||||||
%% Drop the table Tbl.
|
%% Drop the table Tbl.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(drop_table/1::(atom()) -> any()).
|
-spec drop_table(atom()) -> any().
|
||||||
drop_table(Tbl) ->
|
drop_table(Tbl) ->
|
||||||
?MODULE:drop_table(?MODULE, Tbl).
|
?MODULE:drop_table(?MODULE, Tbl).
|
||||||
|
|
||||||
@@ -359,7 +360,7 @@ drop_table(Tbl) ->
|
|||||||
%% Drop the table Tbl from Db dbase.
|
%% Drop the table Tbl from Db dbase.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(drop_table/2::(atom(), atom()) -> any()).
|
-spec drop_table(atom(), atom()) -> any().
|
||||||
drop_table(Db, Tbl) ->
|
drop_table(Db, Tbl) ->
|
||||||
gen_server:call(Db, {drop_table, Tbl}).
|
gen_server:call(Db, {drop_table, Tbl}).
|
||||||
|
|
||||||
@@ -371,7 +372,7 @@ drop_table(Db, Tbl) ->
|
|||||||
%%
|
%%
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(create_function/3::(atom(), atom(), function()) -> any()).
|
-spec create_function(atom(), atom(), function()) -> any().
|
||||||
create_function(Db, FunctionName, Function) ->
|
create_function(Db, FunctionName, Function) ->
|
||||||
gen_server:call(Db, {create_function, FunctionName, Function}).
|
gen_server:call(Db, {create_function, FunctionName, Function}).
|
||||||
|
|
||||||
@@ -390,7 +391,7 @@ create_function(Db, FunctionName, Function) ->
|
|||||||
%% Reexported from sqlite3_lib:value_to_sql/1 for user convenience.
|
%% Reexported from sqlite3_lib:value_to_sql/1 for user convenience.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(value_to_sql_unsafe/1::(sql_value()) -> iodata()).
|
-spec value_to_sql_unsafe(sql_value()) -> iodata().
|
||||||
value_to_sql_unsafe(X) -> sqlite3_lib:value_to_sql_unsafe(X).
|
value_to_sql_unsafe(X) -> sqlite3_lib:value_to_sql_unsafe(X).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
@@ -405,7 +406,7 @@ value_to_sql_unsafe(X) -> sqlite3_lib:value_to_sql_unsafe(X).
|
|||||||
%% Reexported from sqlite3_lib:value_to_sql/1 for user convenience.
|
%% Reexported from sqlite3_lib:value_to_sql/1 for user convenience.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(value_to_sql/1::(sql_value()) -> iolist()).
|
-spec value_to_sql(sql_value()) -> iolist().
|
||||||
value_to_sql(X) -> sqlite3_lib:value_to_sql(X).
|
value_to_sql(X) -> sqlite3_lib:value_to_sql(X).
|
||||||
|
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
@@ -421,19 +422,19 @@ value_to_sql(X) -> sqlite3_lib:value_to_sql(X).
|
|||||||
%% @end
|
%% @end
|
||||||
%% @hidden
|
%% @hidden
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-type(init_return() :: {'ok', tuple()} | {'ok', tuple(), integer()} | 'ignore' | {'stop', any()}).
|
-type init_return() :: {'ok', tuple()} | {'ok', tuple(), integer()} | 'ignore' | {'stop', any()}.
|
||||||
-spec(init/1::([any()]) -> init_return()).
|
-spec init([any()]) -> init_return().
|
||||||
init(Options) ->
|
init(Options) ->
|
||||||
Dbase = proplists:get_value(db, Options),
|
Dbase = proplists:get_value(db, Options),
|
||||||
{?MODULE, _, FileName} = code:get_object_code(?MODULE),
|
{?MODULE, _, FileName} = code:get_object_code(?MODULE),
|
||||||
SearchDir = filename:dirname(FileName),
|
SearchDir = filename:dirname(FileName),
|
||||||
case erl_ddll:load(SearchDir, atom_to_list(?DRIVER_NAME)) of
|
case erl_ddll:load(SearchDir, atom_to_list(?DRIVER_NAME)) of
|
||||||
ok ->
|
ok ->
|
||||||
Port = open_port({spawn, string:join ([atom_to_list (?DRIVER_NAME), Dbase], " ")}, [binary]),
|
Port = open_port({spawn, string:join([atom_to_list(?DRIVER_NAME), Dbase], " ")}, [binary]),
|
||||||
{ok, #state{port = Port, ops = Options}};
|
{ok, #state{port = Port, ops = Options}};
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
Msg = io_lib:format("Error loading ~p: ~p", [?DRIVER_NAME, erl_ddll:format_error(Error)]),
|
Msg = io_lib:format("Error loading ~p: ~p", [?DRIVER_NAME, erl_ddll:format_error(Error)]),
|
||||||
{stop, lists:flatten (Msg)}
|
{stop, lists:flatten(Msg)}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
@@ -447,10 +448,10 @@ init(Options) ->
|
|||||||
%% @end
|
%% @end
|
||||||
%% @hidden
|
%% @hidden
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-type(handle_call_return() :: {reply, any(), tuple()} | {reply, any(), tuple(), integer()} |
|
-type handle_call_return() :: {reply, any(), tuple()} | {reply, any(), tuple(), integer()} |
|
||||||
{noreply, tuple()} | {noreply, tuple(), integer()} |
|
{noreply, tuple()} | {noreply, tuple(), integer()} |
|
||||||
{stop, any(), any(), tuple()} | {stop, any(), tuple()}).
|
{stop, any(), any(), tuple()} | {stop, any(), tuple()}.
|
||||||
-spec(handle_call/3::(any(), pid(), tuple()) -> handle_call_return()).
|
-spec handle_call(any(), pid(), tuple()) -> handle_call_return().
|
||||||
handle_call(close, _From, State) ->
|
handle_call(close, _From, State) ->
|
||||||
Reply = ok,
|
Reply = ok,
|
||||||
{stop, normal, Reply, State};
|
{stop, normal, Reply, State};
|
||||||
@@ -460,7 +461,7 @@ handle_call({sql_exec, SQL}, _From, #state{port = Port} = State) ->
|
|||||||
handle_call(list_tables, _From, #state{port = Port} = State) ->
|
handle_call(list_tables, _From, #state{port = Port} = State) ->
|
||||||
Reply = exec(Port, {sql_exec, "select name from sqlite_master where type='table';"}),
|
Reply = exec(Port, {sql_exec, "select name from sqlite_master where type='table';"}),
|
||||||
TableList = proplists:get_value(rows, Reply),
|
TableList = proplists:get_value(rows, Reply),
|
||||||
TableNames = [erlang:list_to_atom (erlang:binary_to_list (Name)) || {Name} <- TableList],
|
TableNames = [erlang:list_to_atom(erlang:binary_to_list(Name)) || {Name} <- TableList],
|
||||||
{reply, TableNames, State};
|
{reply, TableNames, State};
|
||||||
handle_call({table_info, Tbl}, _From, #state{port = Port} = State) ->
|
handle_call({table_info, Tbl}, _From, #state{port = Port} = State) ->
|
||||||
% make sure we only get table info.
|
% make sure we only get table info.
|
||||||
@@ -481,8 +482,8 @@ handle_call({create_table, Tbl, Options}, _From, #state{port = Port} = State) ->
|
|||||||
Cmd = {sql_exec, SQL},
|
Cmd = {sql_exec, SQL},
|
||||||
Reply = exec(Port, Cmd),
|
Reply = exec(Port, Cmd),
|
||||||
{reply, Reply, State};
|
{reply, Reply, State};
|
||||||
handle_call ({update, Tbl, Key, Value, Data}, _From, #state{port = Port} = State)->
|
handle_call({update, Tbl, Key, Value, Data}, _From, #state{port = Port} = State)->
|
||||||
Reply = exec (Port, {sql_exec, sqlite3_lib:update_sql (Tbl, Key, Value, Data)}),
|
Reply = exec(Port, {sql_exec, sqlite3_lib:update_sql(Tbl, Key, Value, Data)}),
|
||||||
{reply, Reply, State};
|
{reply, Reply, State};
|
||||||
handle_call({write, Tbl, Data}, _From, #state{port = Port} = State) ->
|
handle_call({write, Tbl, Data}, _From, #state{port = Port} = State) ->
|
||||||
% insert into t1 (data,num) values ('This is sample data',3);
|
% insert into t1 (data,num) values ('This is sample data',3);
|
||||||
@@ -492,8 +493,8 @@ handle_call({read, Tbl, {Key, Value}}, _From, #state{port = Port} = State) ->
|
|||||||
% select * from Tbl where Key = Value;
|
% select * from Tbl where Key = Value;
|
||||||
Reply = exec(Port, {sql_exec, sqlite3_lib:read_sql(Tbl, Key, Value)}),
|
Reply = exec(Port, {sql_exec, sqlite3_lib:read_sql(Tbl, Key, Value)}),
|
||||||
{reply, Reply, State};
|
{reply, Reply, State};
|
||||||
handle_call ({read, Tbl, {Key, Value}, Columns}, _From, #state{port = Port} = State) ->
|
handle_call({read, Tbl, {Key, Value}, Columns}, _From, #state{port = Port} = State) ->
|
||||||
Reply = exec (Port, {sql_exec, sqlite3_lib:read_sql (Tbl, Key, Value, Columns)}),
|
Reply = exec(Port, {sql_exec, sqlite3_lib:read_sql(Tbl, Key, Value, Columns)}),
|
||||||
{reply, Reply, State};
|
{reply, Reply, State};
|
||||||
handle_call({delete, Tbl, {Key, Value}}, _From, #state{port = Port} = State) ->
|
handle_call({delete, Tbl, {Key, Value}}, _From, #state{port = Port} = State) ->
|
||||||
% delete from Tbl where Key = Value;
|
% delete from Tbl where Key = Value;
|
||||||
@@ -514,9 +515,9 @@ handle_call(_Request, _From, State) ->
|
|||||||
%% @end
|
%% @end
|
||||||
%% @hidden
|
%% @hidden
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-type(handle_cast_return() :: {noreply, tuple()} | {noreply, tuple(), integer()} |
|
-type handle_cast_return() :: {noreply, tuple()} | {noreply, tuple(), integer()} |
|
||||||
{stop, any(), tuple()}).
|
{stop, any(), tuple()}.
|
||||||
-spec(handle_cast/2::(any(), tuple()) -> handle_cast_return()).
|
-spec handle_cast(any(), tuple()) -> handle_cast_return().
|
||||||
handle_cast(_Msg, State) ->
|
handle_cast(_Msg, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
@@ -528,7 +529,7 @@ handle_cast(_Msg, State) ->
|
|||||||
%% @end
|
%% @end
|
||||||
%% @hidden
|
%% @hidden
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(handle_info/2::(any(), tuple()) -> handle_cast_return()).
|
-spec handle_info(any(), tuple()) -> handle_cast_return().
|
||||||
handle_info(_Info, State) ->
|
handle_info(_Info, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
@@ -541,7 +542,7 @@ handle_info(_Info, State) ->
|
|||||||
%% @end
|
%% @end
|
||||||
%% @hidden
|
%% @hidden
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(terminate/2::(atom(), tuple()) -> atom()).
|
-spec terminate(atom(), tuple()) -> atom().
|
||||||
terminate(normal, #state{port = Port}) ->
|
terminate(normal, #state{port = Port}) ->
|
||||||
port_command(Port, term_to_binary({close, nop})),
|
port_command(Port, term_to_binary({close, nop})),
|
||||||
port_close(Port),
|
port_close(Port),
|
||||||
@@ -582,7 +583,7 @@ wait_result(Port) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
exec(_Port, {create_function, _FunctionName, _Function}) ->
|
exec(_Port, {create_function, _FunctionName, _Function}) ->
|
||||||
error_logger:error_report ([{application, sqlite3}, "NOT IMPL YET"]);
|
error_logger:error_report([{application, sqlite3}, "NOT IMPL YET"]);
|
||||||
%port_control(Port, ?SQL_CREATE_FUNCTION, list_to_binary(Cmd)),
|
%port_control(Port, ?SQL_CREATE_FUNCTION, list_to_binary(Cmd)),
|
||||||
%wait_result(Port);
|
%wait_result(Port);
|
||||||
|
|
||||||
@@ -604,5 +605,5 @@ build_table_info([], Acc) ->
|
|||||||
build_table_info([[ColName, ColType] | Tl], Acc) ->
|
build_table_info([[ColName, ColType] | Tl], Acc) ->
|
||||||
build_table_info(Tl, [{list_to_atom(ColName), sqlite3_lib:col_type_to_atom(ColType)}| Acc]);
|
build_table_info(Tl, [{list_to_atom(ColName), sqlite3_lib:col_type_to_atom(ColType)}| Acc]);
|
||||||
build_table_info([[ColName, ColType, "PRIMARY", "KEY"] | Tl], Acc) ->
|
build_table_info([[ColName, ColType, "PRIMARY", "KEY"] | Tl], Acc) ->
|
||||||
build_table_info(Tl, [{list_to_atom(ColName), primary_key}| Acc]).
|
build_table_info(Tl, [{list_to_atom(ColName), primary_key} | Acc]).
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
%% @doc Maps sqlite3 column type.
|
%% @doc Maps sqlite3 column type.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(col_type_to_string/1::(atom()) -> string()).
|
-spec col_type_to_string(atom()) -> string().
|
||||||
col_type_to_string(integer) ->
|
col_type_to_string(integer) ->
|
||||||
"INTEGER";
|
"INTEGER";
|
||||||
col_type_to_string(text) ->
|
col_type_to_string(text) ->
|
||||||
@@ -40,7 +40,7 @@ col_type_to_string(real) ->
|
|||||||
%% @doc Maps sqlite3 column type.
|
%% @doc Maps sqlite3 column type.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(col_type_to_atom/1::(string()) -> atom()).
|
-spec col_type_to_atom(string()) -> atom().
|
||||||
col_type_to_atom("INTEGER") ->
|
col_type_to_atom("INTEGER") ->
|
||||||
integer;
|
integer;
|
||||||
col_type_to_atom("TEXT") ->
|
col_type_to_atom("TEXT") ->
|
||||||
@@ -61,7 +61,7 @@ col_type_to_atom("REAL") ->
|
|||||||
%% single quotes (e.g. can be entered by users).
|
%% single quotes (e.g. can be entered by users).
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(value_to_sql_unsafe/1::(sql_value()) -> iodata()).
|
-spec value_to_sql_unsafe(sql_value()) -> iodata().
|
||||||
value_to_sql_unsafe(X) ->
|
value_to_sql_unsafe(X) ->
|
||||||
if
|
if
|
||||||
is_integer(X) -> integer_to_list(X);
|
is_integer(X) -> integer_to_list(X);
|
||||||
@@ -80,7 +80,7 @@ value_to_sql_unsafe(X) ->
|
|||||||
%% All single quotes (') will be replaced with ''.
|
%% All single quotes (') will be replaced with ''.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(value_to_sql/1::(sql_value()) -> iolist()).
|
-spec value_to_sql(sql_value()) -> iolist().
|
||||||
value_to_sql(X) ->
|
value_to_sql(X) ->
|
||||||
if
|
if
|
||||||
is_integer(X) -> integer_to_list(X);
|
is_integer(X) -> integer_to_list(X);
|
||||||
@@ -95,7 +95,7 @@ value_to_sql(X) ->
|
|||||||
%% Creates the values portion of the sql stmt.
|
%% Creates the values portion of the sql stmt.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(write_value_sql/1::(any()) -> string()).
|
-spec write_value_sql(any()) -> string().
|
||||||
write_value_sql(Values) ->
|
write_value_sql(Values) ->
|
||||||
map_intersperse(fun value_to_sql/1, Values, ",").
|
map_intersperse(fun value_to_sql/1, Values, ",").
|
||||||
|
|
||||||
@@ -104,17 +104,17 @@ write_value_sql(Values) ->
|
|||||||
%% @doc Creates the column/data stmt for SQL.
|
%% @doc Creates the column/data stmt for SQL.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(write_col_sql/1::([atom()]) -> string()).
|
-spec write_col_sql([atom()]) -> string().
|
||||||
write_col_sql(Cols) ->
|
write_col_sql(Cols) ->
|
||||||
map_intersperse(fun atom_to_list/1, Cols, ",").
|
map_intersperse(fun atom_to_list/1, Cols, ",").
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @spec replace (String) -> string ()
|
%% @spec replace(String) -> string()
|
||||||
%% String = string ()
|
%% String = string()
|
||||||
%% @doc Returns copy of String for which \" replaced with '
|
%% @doc Returns copy of String for which \" replaced with '
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec (replace/1::(string ()) -> string ()).
|
-spec replace(string()) -> string().
|
||||||
replace([]) -> [];
|
replace([]) -> [];
|
||||||
replace([$" | T]) ->
|
replace([$" | T]) ->
|
||||||
[$' | replace(T)];
|
[$' | replace(T)];
|
||||||
@@ -127,35 +127,35 @@ replace([H | T]) ->
|
|||||||
%% @doc Returns copy of IoData with all ' replaced by ''
|
%% @doc Returns copy of IoData with all ' replaced by ''
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(escape/1::(iodata()) -> iodata()).
|
-spec escape(iodata()) -> iodata().
|
||||||
escape(IoData) -> re:replace(IoData, "'", "''", [global]).
|
escape(IoData) -> re:replace(IoData, "'", "''", [global]).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @spec update_set_sql ([{Col, Value}]) -> string ()
|
%% @spec update_set_sql([{Col, Value}]) -> string()
|
||||||
%% Col = atom ()
|
%% Col = atom()
|
||||||
%% Value = number () | atom () | string ()
|
%% Value = number() | atom() | string()
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Creates update set stmt.
|
%% Creates update set stmt.
|
||||||
%% Currently supports integer, double/float and strings.
|
%% Currently supports integer, double/float and strings.
|
||||||
%% For strings \" replaced with '.
|
%% For strings \" replaced with '.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec (update_set_sql/1::(any ()) -> string ()).
|
-spec update_set_sql(any()) -> string().
|
||||||
update_set_sql (Data) ->
|
update_set_sql(Data) ->
|
||||||
ColValueToSqlFun =
|
ColValueToSqlFun =
|
||||||
fun({Col, Value}) ->
|
fun({Col, Value}) ->
|
||||||
[atom_to_list (Col), " = ", value_to_sql(Value)]
|
[atom_to_list(Col), " = ", value_to_sql(Value)]
|
||||||
end,
|
end,
|
||||||
map_intersperse(ColValueToSqlFun, Data, ", ").
|
map_intersperse(ColValueToSqlFun, Data, ", ").
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @spec read_cols_sql (Columns::[atom ()]) -> string ()
|
%% @spec read_cols_sql(Columns::[atom()]) -> string()
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Creates list of columns for select stmt.
|
%% Creates list of columns for select stmt.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec (read_cols_sql/1::([atom ()]) -> string ()).
|
-spec read_cols_sql([atom()]) -> string().
|
||||||
read_cols_sql (Columns) ->
|
read_cols_sql(Columns) ->
|
||||||
map_intersperse(fun atom_to_list/1, Columns, ", ").
|
map_intersperse(fun atom_to_list/1, Columns, ", ").
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
@@ -167,7 +167,7 @@ read_cols_sql (Columns) ->
|
|||||||
%% First column listed is considered the primary key.
|
%% First column listed is considered the primary key.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(create_table_sql/2::(atom(), [{atom(), string()}]) -> string()).
|
-spec create_table_sql(atom(), [{atom(), string()}]) -> string().
|
||||||
create_table_sql(Tbl, [{ColName, Type} | Tl]) ->
|
create_table_sql(Tbl, [{ColName, Type} | Tl]) ->
|
||||||
CT = ["CREATE TABLE ", atom_to_list(Tbl), " "],
|
CT = ["CREATE TABLE ", atom_to_list(Tbl), " "],
|
||||||
Start = ["(", atom_to_list(ColName), " ", col_type_to_string(Type), " PRIMARY KEY, "],
|
Start = ["(", atom_to_list(ColName), " ", col_type_to_string(Type), " PRIMARY KEY, "],
|
||||||
@@ -178,19 +178,19 @@ create_table_sql(Tbl, [{ColName, Type} | Tl]) ->
|
|||||||
[CT, Start, End].
|
[CT, Start, End].
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @spec update_sql (Tbl, Key, Value, Data) -> string ()
|
%% @spec update_sql(Tbl, Key, Value, Data) -> string()
|
||||||
%% Tbl = atom ()
|
%% Tbl = atom()
|
||||||
%% Key = atom ()
|
%% Key = atom()
|
||||||
%% Value = atom ()
|
%% Value = atom()
|
||||||
%% Data = [{ColName :: atom (), Value :: string () | integer () | float ()}]
|
%% Data = [{ColName :: atom(), Value :: string() | integer() | float()}]
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Using Key as the column name and Data as list of column names
|
%% Using Key as the column name and Data as list of column names
|
||||||
%% and values pairs it creates the proper update SQL stmt for the
|
%% and values pairs it creates the proper update SQL stmt for the
|
||||||
%% record with matching Value.
|
%% record with matching Value.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec (update_sql/4::(atom (), atom (), atom (), [{atom (), sql_value ()}]) -> string ()).
|
-spec update_sql(atom(), atom(), atom(), [{atom(), sql_value()}]) -> string().
|
||||||
update_sql (Tbl, Key, Value, Data) ->
|
update_sql(Tbl, Key, Value, Data) ->
|
||||||
["UPDATE ", atom_to_list(Tbl), " SET ", update_set_sql(Data),
|
["UPDATE ", atom_to_list(Tbl), " SET ", update_set_sql(Data),
|
||||||
" WHERE ", atom_to_list(Key), " = ", value_to_sql(Value), ";"].
|
" WHERE ", atom_to_list(Key), " = ", value_to_sql(Value), ";"].
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ update_sql (Tbl, Key, Value, Data) ->
|
|||||||
%% proper insertion SQL stmt.
|
%% proper insertion SQL stmt.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(write_sql/2::(atom(), [{atom(), sql_value()}]) -> string()).
|
-spec write_sql(atom(), [{atom(), sql_value()}]) -> string().
|
||||||
write_sql(Tbl, Data) ->
|
write_sql(Tbl, Data) ->
|
||||||
{Cols, Values} = lists:unzip(Data),
|
{Cols, Values} = lists:unzip(Data),
|
||||||
["INSERT INTO ", atom_to_list(Tbl), " (", sqlite3_lib:write_col_sql(Cols),
|
["INSERT INTO ", atom_to_list(Tbl), " (", sqlite3_lib:write_col_sql(Cols),
|
||||||
@@ -217,24 +217,24 @@ write_sql(Tbl, Data) ->
|
|||||||
%% matching Value.
|
%% matching Value.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(read_sql/3::(atom(), atom(), sql_value()) -> string()).
|
-spec read_sql(atom(), atom(), sql_value()) -> string().
|
||||||
read_sql(Tbl, Key, Value) ->
|
read_sql(Tbl, Key, Value) ->
|
||||||
["SELECT * FROM ", atom_to_list(Tbl), " WHERE ", atom_to_list(Key),
|
["SELECT * FROM ", atom_to_list(Tbl), " WHERE ", atom_to_list(Key),
|
||||||
" = ", value_to_sql(Value), ";"].
|
" = ", value_to_sql(Value), ";"].
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @spec read_sql (Tbl, Key, Value, Columns) -> string ()
|
%% @spec read_sql(Tbl, Key, Value, Columns) -> string()
|
||||||
%% Tbl = atom ()
|
%% Tbl = atom()
|
||||||
%% Key = atom ()
|
%% Key = atom()
|
||||||
%% Value = string () | integer () | float ()
|
%% Value = string() | integer() | float()
|
||||||
%% Columns = [atom ()]
|
%% Columns = [atom()]
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Using Key as the column name searhces for the record with
|
%% Using Key as the column name searhces for the record with
|
||||||
%% matching Value and returns only specified columns Columns.
|
%% matching Value and returns only specified columns Columns.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec (read_sql/4::(atom (), atom (), sql_value (), [atom ()]) -> string ()).
|
-spec read_sql(atom(), atom(), sql_value(), [atom()]) -> string().
|
||||||
read_sql (Tbl, Key, Value, Columns) ->
|
read_sql(Tbl, Key, Value, Columns) ->
|
||||||
["SELECT ", sqlite3_lib:read_cols_sql(Columns), " FROM ",
|
["SELECT ", sqlite3_lib:read_cols_sql(Columns), " FROM ",
|
||||||
atom_to_list(Tbl), " WHERE ", atom_to_list(Key), " = ",
|
atom_to_list(Tbl), " WHERE ", atom_to_list(Key), " = ",
|
||||||
value_to_sql(Value), ";"].
|
value_to_sql(Value), ";"].
|
||||||
@@ -248,7 +248,7 @@ read_sql (Tbl, Key, Value, Columns) ->
|
|||||||
%% matching Value then deletes that record.
|
%% matching Value then deletes that record.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(delete_sql/3::(atom(), atom(), sql_value()) -> string()).
|
-spec delete_sql(atom(), atom(), sql_value()) -> string().
|
||||||
delete_sql(Tbl, Key, Value) ->
|
delete_sql(Tbl, Key, Value) ->
|
||||||
["DELETE FROM ", atom_to_list(Tbl), " WHERE ", atom_to_list(Key),
|
["DELETE FROM ", atom_to_list(Tbl), " WHERE ", atom_to_list(Key),
|
||||||
" = ", value_to_sql(Value), ";"].
|
" = ", value_to_sql(Value), ";"].
|
||||||
@@ -259,7 +259,7 @@ delete_sql(Tbl, Key, Value) ->
|
|||||||
%% @doc Drop the table Tbl from the database
|
%% @doc Drop the table Tbl from the database
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(drop_table/1::(atom()) -> string()).
|
-spec drop_table(atom()) -> string().
|
||||||
drop_table(Tbl) ->
|
drop_table(Tbl) ->
|
||||||
["DROP TABLE ", atom_to_list(Tbl), ";"].
|
["DROP TABLE ", atom_to_list(Tbl), ";"].
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user