Added test and fixed documentation for update/3,4
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
-export([create_table/2, create_table/3, create_table/4]).
|
-export([create_table/2, create_table/3, create_table/4]).
|
||||||
-export([list_tables/0, list_tables/1, table_info/1, table_info/2]).
|
-export([list_tables/0, list_tables/1, table_info/1, table_info/2]).
|
||||||
-export([write/2, write/3, write_many/2, write_many/3]).
|
-export([write/2, write/3, write_many/2, write_many/3]).
|
||||||
-export([update/4, update/5]).
|
-export([update/3, update/4]).
|
||||||
-export([read_all/2, read_all/3, read/2, read/3, read/4]).
|
-export([read_all/2, read_all/3, read/2, read/3, read/4]).
|
||||||
-export([delete/2, delete/3]).
|
-export([delete/2, delete/3]).
|
||||||
-export([drop_table/1, drop_table/2]).
|
-export([drop_table/1, drop_table/2]).
|
||||||
@@ -304,33 +304,31 @@ write_many(Db, Tbl, Data) ->
|
|||||||
gen_server:call(Db, {write_many, Tbl, Data}).
|
gen_server:call(Db, {write_many, Tbl, Data}).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @spec update(Tbl :: atom(), Key :: atom(), Value, Data) -> Result
|
%% @spec update(Tbl :: atom(), Key :: atom(), Value, Data) -> sql_non_query_result()
|
||||||
%% Value = any()
|
%% Value = any()
|
||||||
%% Data = [{Column :: atom(), Value :: sql_value()}]
|
%% Data = [{Column :: atom(), Value :: sql_value()}]
|
||||||
%% Result = {ok, RowID} | Unknown
|
|
||||||
%% 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 RowID of the first updated
|
%% value in Key with Data. Returns RowID of the first updated
|
||||||
%% record.
|
%% record.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
update(Tbl, Key, Value, Data) ->
|
-spec update(atom(), {atom(), sql_value()}, [{atom(), sql_value()}]) -> sql_non_query_result().
|
||||||
update(?MODULE, Tbl, Key, Value, Data).
|
update(Tbl, {Key, Value}, Data) ->
|
||||||
|
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) -> sql_non_query_result()
|
||||||
%% Value = sql_value()
|
%% Value = sql_value()
|
||||||
%% Data = [{Column :: atom(), Value :: sql_value()}]
|
%% Data = [{Column :: atom(), Value :: sql_value()}]
|
||||||
%% Result = {ok, ID} | Unknown
|
|
||||||
%% Unknown = term()
|
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Updates rows into Tbl table in Db database such that the Value
|
%% Updates rows into Tbl table in Db database 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) ->
|
-spec update(atom(), atom(), {atom(), sql_value()}, [{atom(), sql_value()}]) -> sql_non_query_result().
|
||||||
|
update(Db, Tbl, {Key, Value}, Data) ->
|
||||||
gen_server:call(Db, {update, Tbl, Key, Value, Data}).
|
gen_server:call(Db, {update, Tbl, Key, Value, Data}).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|||||||
@@ -99,7 +99,10 @@ basic_functionality() ->
|
|||||||
ok,
|
ok,
|
||||||
sqlite3:delete(ct, user, {name, "marge"})),
|
sqlite3:delete(ct, user, {name, "marge"})),
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
[{columns, Columns}, {rows, AbbyOnly}],
|
ok,
|
||||||
|
sqlite3:update(ct, user, {name, "abby"}, [{wage, 3000}])),
|
||||||
|
?assertEqual(
|
||||||
|
[{columns, Columns}, {rows, [{1, <<"abby">>, 20, 3000}]}],
|
||||||
sqlite3:sql_exec(ct, "select * from user;")),
|
sqlite3:sql_exec(ct, "select * from user;")),
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
ok,
|
ok,
|
||||||
|
|||||||
Reference in New Issue
Block a user