Erlang : SQLite data record manipulation

-module(sqlite_3).
-export([test/0]).

rec([]) ->
        empty;
rec([H|T]) ->
        {Dst, Msg} = H,
        io:fwrite("DST : ~p~n", [binary_to_list(Dst)]),
        io:fwrite("MSG : ~p~n~n", [binary_to_list(Msg)]),
        rec(T).

test() ->
        % substitute for SQLite data record
        Record = [
                {columns,[dst,msg]},
                {rows,
                        [{<<"94770000000">>,<<"msg 1">>},
                        {<<"94770000001">>,<<"msg 2">>}]
                }
                ],      
        [{columns, Columns} , {rows, Rows}]  = Record,
        rec(Rows).

Sample output

[root@sam test]# erl
Erlang R14B (erts-5.8.1)  [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.8.1  (abort with ^G)
1> c(sqlite_3).
./t.erl:21: Warning: variable 'Columns' is unused
{ok,sqlite_3}
2> sqlite_3:test().
DST : "94770000000"
MSG : "msg 1"

DST : "94770000001"
MSG : "msg 2"

empty
3> 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: