About boss_db:execute

149 views
Skip to first unread message

夜帝

unread,
Apr 16, 2012, 3:09:23 AM4/16/12
to chica...@googlegroups.com
If use boss_db:execute("select * from tablename") to query the tablename ,how to get the every field value from the query result?

--
我踏月色而来!

Evan Miller

unread,
Apr 16, 2012, 9:36:16 AM4/16/12
to chica...@googlegroups.com
The return value of "execute" depends on the behavior the individual
adapter. In the case of the MySQL adapter you'll get {data, Result},
then you need to call mysql:get_result_rows(Result).

--
Evan Miller
http://www.evanmiller.org/

郎咸武

unread,
Apr 23, 2012, 2:45:04 AM4/23/12
to chica...@googlegroups.com
You can using the following
" select id, good_name, img_url, click_url, price, collection_count from goods ...
Fields = [id, good_name, img_url, click_url, price, collection_count],
---
162                {data,{mysql_result, _, L, 0, 0, []}} ->
163                    Goods = util:get_json({L, "good-", msg_pic}, Fields),
---

2012/4/16 Evan Miller <emmi...@gmail.com>



--
只为成功找方法,不为失败找理由

夜帝

unread,
Apr 23, 2012, 10:47:16 AM4/23/12
to chica...@googlegroups.com
My database is Postgresql
--
我踏月色而来!

jiale.chan

unread,
Feb 12, 2014, 10:39:07 PM2/12/14
to chica...@googlegroups.com
test('GET', []) ->
        SQL = "select id, greeting_text from greetings",
        Result = get_Data(boss_db:execute(SQL)),
        {ok, [{result, Result}]}.
       
get_Data({data, {mysql_result, FieldsData, ValuesData, 0, 0, []}}) ->
        Fields = [Field || {_, Field, _, _}  <- FieldsData],
        [lists:zip(Fields, Value) || Value <- ValuesData].

--------------------------------

{% for item in result  %}
        <b>{{ item.id  }} --- {{ item.greeting_text }}</b><br/>
{% endfor %}

here is some code work for mysql.
wish that help you

在 2012年4月16日星期一UTC+8下午3时09分23秒,9527写道:
Reply all
Reply to author
Forward
0 new messages