Add read operation (with specified columns to read)

This commit is contained in:
sergey-miryanov
2010-01-20 14:46:40 +05:00
parent 2583ec83ee
commit 6a6f663ea2
2 changed files with 53 additions and 0 deletions

View File

@@ -20,6 +20,7 @@
-export([list_tables/0, list_tables/1, table_info/1, table_info/2]).
-export([write/2, write/3]).
-export([update/4, update/5]).
-export([read/4]).
-export([read/2, read/3]).
-export([delete/2, delete/3]).
-export([drop_table/1, drop_table/2]).
@@ -297,6 +298,22 @@ read(Tbl, Key) ->
read(Db, Tbl, Key) ->
gen_server:call(Db, {read, Tbl, Key}).
%%--------------------------------------------------------------------
%% @spec read (Db, Tbl, Key, Columns) -> [term ()]
%% Db = atom ()
%% Tbl = atom ()
%% Key = {Column::atom (), Value::term ()}
%% Columns = [atom ()]
%% @doc
%% Reads a row from Tbl table in Db dbase such that the Value
%% matches the value in Column. Returns columns Columns only for
%% the first match. Value must have the same type as determined
%% from table_info/3.
%% @end
%%--------------------------------------------------------------------
read (Db, Tbl, Key, Columns) ->
gen_server:call (Db, {read, Tbl, Key, Columns}).
%%--------------------------------------------------------------------
%% @spec delete(Tbl::atom(), Key) -> term()
%% Key = {ColName::atom(), ColValue::term()}
@@ -439,6 +456,9 @@ handle_call({read, Tbl, {Key, Value}}, _From, #state{port = Port} = State) ->
% select * from Tbl where Key = Value;
Reply = exec(Port, {sql_exec, sqlite3_lib:read_sql(Tbl, Key, Value)}),
{reply, Reply, 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, Reply, State};
handle_call({delete, Tbl, {Key, Value}}, _From, #state{port = Port} = State) ->
% delete from Tbl where Key = Value;
Reply = exec(Port, {sql_exec, sqlite3_lib:delete_sql(Tbl, Key, Value)}),