Closed GoogleCodeExporter closed 8 years ago
Hi golgote, you can retrieve column names from a select by passing true as a
parameter to the 'fetch' or 'rows' method of a statement handle. By default
'fetch'
or 'rows' returns a numerically index table (AKA an array), but by passing true
to
these methods the result is return as a table indexed by column names.
See the examples on http://code.google.com/p/luadbi/wiki/DBDDriverStatement for
more
details.
Original comment by nr...@ii.net
on 5 Apr 2009 at 5:14
Yes, I noticed that, but columns in the table can be in any order (since that's
the way tables work in Lua). To
build specific functions like "getAssoc" (and some others for my ORM), I need
to know in which order the
columns were fetched, that's why a function to get the column names is useful.
Thanks for your reply :)
Original comment by golg...@gmail.com
on 6 Apr 2009 at 10:26
I've had a look at the source code, and the functionality should be relatively
easy
to add. The implementation will look something like:
local sth = dbh:prepare('SELECT id,num,timestamp FROM sometable')
sth:execute()
-- fields will be equal to {'id','num','timestamp'}
local fields = sth:columns()
I'll look at adding this in the next week.
Original comment by nr...@ii.net
on 9 Apr 2009 at 12:48
I've committed changes to implement the 'columns' method for statement handles
into
SVN. I'll be uploading a new release source package shortly.
Original comment by nr...@ii.net
on 17 Apr 2009 at 11:49
Thank you Neil :)
Original comment by golg...@gmail.com
on 19 Apr 2009 at 8:45
Original issue reported on code.google.com by
golg...@gmail.com
on 7 Mar 2009 at 8:15