Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

colnames #1

Closed
GoogleCodeExporter opened this issue Jun 11, 2015 · 5 comments
Closed

colnames #1

GoogleCodeExporter opened this issue Jun 11, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

Hi Neil, this is a feature request. It would be nice to have access to column 
names after a select. 
LuaSQL provides a colnames function IIRC. This is handy for dealing with 
metadata.

Not related, but in the MySQL statement.c, there is this code:

    if (!statement->metadata) {
    luaL_error(L, DBI_ERR_FETCH_NO_EXECUTE);
    return 0;
    }

    if (!statement->metadata) {
    lua_pushnil(L);
    return 1;
    }

I am not sure the second test is needed.

Original issue reported on code.google.com by golg...@gmail.com on 7 Mar 2009 at 8:15

@GoogleCodeExporter
Copy link
Author

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

@GoogleCodeExporter
Copy link
Author

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

@GoogleCodeExporter
Copy link
Author

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

@GoogleCodeExporter
Copy link
Author

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

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Thank you Neil :)

Original comment by golg...@gmail.com on 19 Apr 2009 at 8:45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant