Skip to content

Return ffi's NULL instead of nil from lua_mysql_pushresult() #8

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

Merged
merged 1 commit into from
Jan 14, 2021

Conversation

darkwrat
Copy link
Contributor

@darkwrat darkwrat commented Apr 1, 2016

Before patch:

tarantool> rows = conn:execute('select rand() as w, NULL as x')

---
...

tarantool> rows

---
- - w: 0.81680908595846
...

tarantool> json.encode(rows)

---
- '[{"w":0.81680908595846}]'
...


After patch:

tarantool> rows = conn:execute('select rand() as w, NULL as x')

---
...

tarantool> rows

---
- - x: null
    w: 0.28386442669096
...

tarantool> json.encode(rows)

---
- '[{"x":null,"w":0.28386442669096}]'
...

* @param L stack
*/
static inline void
luaL_pushnull(struct lua_State *L)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is actually a copy-paste from tarantool/src/lua/utils.h.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

luaL_pushnull must be imported to public API, you're right

@GeorgyKirichenko
Copy link
Contributor

May be adding some sql meta info to returning tables (for example, field names with its native sql types) should be a better solution?

@darkwrat darkwrat force-pushed the pushnull branch 4 times, most recently from 1a19b97 to d446fdf Compare April 29, 2016 20:40
GeorgyKirichenko pushed a commit that referenced this pull request May 11, 2016
More signcode fixes (windows msi)
@Totktonada
Copy link
Member

The proposed change may be considered as backward incompatible, however I don't mind to enable this behaviour under an option like keep_null.

May be adding some sql meta info to returning tables (for example, field names with its native sql types) should be a better solution?

The metadata is returned now when the use_numeric_result option is set (introduced in PR #25):

{
    { -- result set
        rows = {
            {r1c1val, r1c2val, ...}, -- row
            {r2c1val, r2c2val, ...}, -- row
            ...
        },
        metadata = {
            {type = 'long', name = 'col1'}, -- column meta
            {type = 'long', name = 'col2'}, -- column meta
            ...
        },
    },
    ...
}

@darkwrat
Copy link
Contributor Author

darkwrat commented Nov 9, 2020

Please excuse me for the terribly slow response, I think it's time for me to tinker with some notification settings :)

The proposed change may be considered as backward incompatible, however I don't mind to enable this behaviour under an option like keep_null.

Sounds great, I will update the changeset and README accordingly.

The metadata is returned now when the use_numeric_result option is set (introduced in PR #25):

In my opinion the metadata table introduces a complication for the particular case of simply packing the response and sending it over the wire. Some effort still must be put on the receiving end to actually discover that a value is NULL.

@darkwrat
Copy link
Contributor Author

darkwrat commented Nov 9, 2020

It looks like CI fails because Tarantool 1.6 (which this change was initally based on) had all non-static symbols visible to ffi (tarantool/tarantool#2971).
So extern int luaL_nil_ref shenanigans are not viable anymore, and as @bigbes pointed out luaL_pushnull must be exported to the public API first (as well as luaL_nil_ref?).

As I see this, it means that the change may not be introduced without breaking compatibility with all existing tarantool versions out there, and that is quite a bummer.

@Totktonada
Copy link
Member

So extern int luaL_nil_ref shenanigans are not viable anymore, and as @bigbes pointed out luaL_pushnull must be exported to the public API first (as well as luaL_nil_ref?).

You can make the variable static and assign it within the module. See utils.c.

@darkwrat darkwrat marked this pull request as draft November 17, 2020 08:15
@Totktonada
Copy link
Member

So extern int luaL_nil_ref shenanigans are not viable anymore, and as @bigbes pointed out luaL_pushnull must be exported to the public API first (as well as luaL_nil_ref?).

You can make the variable static and assign it within the module. See utils.c.

The code now uses CTID_P_VOID, but it is internal contant, which is not guaranteed to be the same in future. I'll look for other approach, which will lean only on public LuaJIT / Tarantool APIs.

@romanhabibov
Copy link
Contributor

romanhabibov commented Dec 2, 2020

@darkwrat, if you are not going to make changes, then let me know I will finish this pull request.

@darkwrat
Copy link
Contributor Author

darkwrat commented Dec 3, 2020

@darkwrat, if you are not going to make changes, then let me know I will finish this pull request.

Please go ahead.

@Totktonada
Copy link
Member

CI fails are expected. See #53 and #54.

Introduce keep_null option to return ffi's NULL instead of nil
in conn:execute().

Co-authored-by: Maxim Galaganov <voltage@lanport.net>

We can specify how lua_mysql_push_value() works with data == NULL and
use this fact to simplify the code.
Copy link
Member

@Totktonada Totktonada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@Totktonada Totktonada marked this pull request as ready for review January 14, 2021 15:18
@Totktonada Totktonada merged commit 979c82c into tarantool:master Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants