[erlang-questions] Erlang MySQL ODBC Question

Robert Raschke rtrlists@REDACTED
Fri Oct 15 11:32:57 CEST 2010


On Thu, Oct 14, 2010 at 6:39 PM, Phone <phone.bytes@REDACTED> wrote:

> Newbie to Erlang.
>
> I have successfully connected to MySQL using ODBC, successful SELECT
> statement.  Got result set back like this:
>
> {selected,["fieldname1", "fieldname2"],[{"fieldvalue1","fieldvalue2"}]}
>
> Not sure how this result set is stored and how to get access to the
> fieldvalues in my erlang program.
>
> Probably really dumb?
>
> Thanks
>
>
>
Kind of depends on what you want to do with your results. The plain result
simple gives you the list of column names and the list of result set rows,
where each row is a tuple of values.

You can transform this into whatever your app requires by manipulating the
lists. For example if you rather had a list of result set rows, where each
row is a list of name-value pairs:

Eshell V5.6.5  (abort with ^G)
1> RS = {selected,["field1",
"field2"],[{"field1value1","field2value1"},{"field1value2","field2value2"}]}.
{selected,["field1","field2"],
          [{"field1value1","field2value1"},
           {"field1value2","field2value2"}]}
2> {selected, Cols, Rows} = RS.
{selected,["field1","field2"],
          [{"field1value1","field2value1"},
           {"field1value2","field2value2"}]}
3> [ lists:zip(Cols, tuple_to_list(Row)) || Row <- Rows ].
[[{"field1","field1value1"},
  {"field2","field2value1"}],
 [{"field1","field1value2"},
  {"field2","field2value2"}]]
4>

So, it really just depends on what you want to do with your result set.

Hope this helps a bit,
Robby


More information about the erlang-questions mailing list