lunarmodules / luasql

LuaSQL is a simple interface from Lua to a DBMS.
http://lunarmodules.github.io/luasql
539 stars 191 forks source link

NULL fields generate no column name with fetch "a"? #66

Closed speeder closed 7 years ago

speeder commented 7 years ago

The program here uses "a" setting on fetching to get column names to put stuff inside (example: as it loops through rows, it can go adding things to each column, or it can use column names to dynamically print a page that dumps all columns).

But if the contents of the field on the first row is null, it doesn't return the columns either, breaking stuff. (for example by creating a webpage that has columns than needed when dumping data if by bad luck several of the first fetched data had NULLs in those columns in first place).

tomasguisasola commented 7 years ago

Hi speeder

Yes, that is the expected behavior: the database NULL value is always converted to Lua as a nil. Note the last sentence in the docs:

http://keplerproject.github.io/luasql/manual.html#cur_fetch

If you want to know the names of the columns, you should use the appropriate cursor method:

http://keplerproject.github.io/luasql/manual.html#cur_colnames

Also note that some drivers offers additional methods that could be useful.

Regards, Tomás

On 2016-12-15 21:52, speeder wrote:

The program here uses "a" setting on fetching to get column names to put stuff inside (example: as it loops through rows, it can go adding things to each column, or it can use column names to dynamically print a page that dumps all columns).

But if the contents of the field on the first row is null, it doesn't return the columns either, breaking stuff. (for example by creating a webpage that has columns than needed when dumping data if by bad luck several of the first fetched data had NULLs in those columns in first place).

-- You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub [1], or mute the thread [2].

*

Links:

[1] https://github.com/keplerproject/luasql/issues/66 [2] https://github.com/notifications/unsubscribe-auth/AAIA7ZUxtzefc4OKW6TXRWD5xOh2hrF1ks5rIdK0gaJpZM4LOtEM

speeder commented 7 years ago

Thanks!

This actually worked just fine, its behavior, including how it order the columns, is perfect, the coder using sqlLua (not me) is very happy and asked me to be clear he was happy with it.

Sorry for the useless issue, I wrote it on behalf of my father, that doesn't speak english, and is struggling with this (also I noticed you DO have Brazillian documentation, but seemly it wasn't updated in the last 2 years, so he insists in using the english one google translated to portuguese).

tomasguisasola commented 7 years ago

Hi speeder

I'm glad the code is being useful! And your question is not useless. A chance for clarifying things :-) I'll take a look at the portuguese docs. Anyway, you or your father can contact me in private (I don't know how to do it since I cannot find your actual e-mail; mine is @gmail.com) and we could speak in portuguese :-)

Regards, Tomás

On 2016-12-16 16:11, speeder wrote:

Thanks!

This actually worked just fine, its behavior, including how it order the columns, is perfect, the coder using sqlLua (not me) is very happy and asked me to be clear he was happy with it.

Sorry for the useless issue, I wrote it on behalf of my father, that doesn't speak english, and is struggling with this (also I noticed you DO have Brazillian documentation, but seemly it wasn't updated in the last 2 years, so he insists in using the english one google translated to portuguese).

-- You are receiving this because you commented. Reply to this email directly, view it on GitHub [1], or mute the thread [2].

*

Links:

[1] https://github.com/keplerproject/luasql/issues/66#issuecomment-267659081 [2] https://github.com/notifications/unsubscribe-auth/AAIA7XvbVOPM4BkUID4tWKmrcqR7iBPJks5rItRkgaJpZM4LOtEM