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

Undefined parameters when sending nil values from Lua #30

Closed
instigate77 opened this issue Sep 24, 2021 · 11 comments
Closed

Undefined parameters when sending nil values from Lua #30

instigate77 opened this issue Sep 24, 2021 · 11 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@instigate77
Copy link

when a variable in LIA has value of nil the sql query throws an error

In this example garage is nil It comes from the DB select as NULL in the table which is the default value
But when it is inserted back it seems to ignore it and causes the undefined object.

[ script:oxmysql] [ERROR] qb-garages was unable to execute a query!
[ script:oxmysql] Undefined object parameter #2
[ script:oxmysql] UPDATE player_vehicles SET state = ?, garage = ?, depotprice = ? WHERE plate = ? {"1":0,"3":0,"4":"3TL036RH"}

Is there a way to have it recognize nil value and insert them as NULL?

@instigate77
Copy link
Author

Seems like the parser sees a null parameter as undefined and throws the error above.
Maybe handle it with this mode? and check if a Lua string is null and change it to '' then insert it back and it will be NULL?

SET sql_mode=EMPTY_STRING_IS_NULL;
SELECT '' IS NULL; -- returns TRUE
INSERT INTO t1 VALUES (''); -- inserts NULL

@darksaid98
Copy link
Contributor

darksaid98 commented Sep 24, 2021

First, no. When using the ? placeholders in a query you can not pass nil in Lua or undefined in Js as parameters.

Dunak has expressed intent to allow passing nil from Lua (undefined from Js) that will be interpreted as NULL. However, it is my understanding that this will only be possible with named parameters.

This is because using ? placeholders expects an ordered array or object for parameters. Inserting nil into an array does nothing since the array can't store nothing.

@thelindat
Copy link
Member

I tested sending nil values through ? but it always resulted in the first value sending as NULL and offsetting the other parameters; worked fine with named placeholders though. I'm not good enough with JS so Dunak would have to look into it.

@ghost
Copy link

ghost commented Sep 28, 2021

I am also having an issue similar to this, not sure if I should open a new issue or just post in this one. getting reports in the fxserver log like this:

[ script:oxmysql] Error: Undefined parameter cid
[ script:oxmysql] at @oxmysql/oxmysql.js:1:326557
[ script:oxmysql] at _ (@oxmysql/oxmysql.js:1:326629)
[ script:oxmysql] at s._resolveNamedPlaceholders (@oxmysql/oxmysql.js:1:113372)
[ script:oxmysql] at s.query (@oxmysql/oxmysql.js:1:113501)
[ script:oxmysql] at @oxmysql/oxmysql.js:1:312976
[ script:oxmysql] at @oxmysql/oxmysql.js:1:311499
[ script:oxmysql] at processTicksAndRejections (internal/process/task_queues.js:75:11)
[ script:oxmysql] at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:62:3)
[ script:oxmysql] at citizen:/scripting/v8/timer.js:227:32

there is a lot of cases where i use a parameter as cid as its the character identifier, but it doesn't state where the error comes from, if possible it would be nice if it could at least say where it's coming from so I can fix it. cheers.

@dunak-debug
Copy link
Member

Use latest version and you will see error

@ghost
Copy link

ghost commented Sep 29, 2021

Use latest version and you will see error

These errors started on latest 1.4.1 , had never seen them before then. I'm already on latest version.

@darksaid98
Copy link
Contributor

Use latest version and you will see error

These errors started on latest 1.4.1 , had never seen them before then. I'm already on latest version.

Like stated before, a fix/change to this is being worked on.

@ghost
Copy link

ghost commented Sep 30, 2021

my bad I misunderstood what he said, thought he was implying to use latest to see where the error was coming from. i understand now

@dunak-debug dunak-debug added bug Something isn't working help wanted Extra attention is needed labels Oct 6, 2021
@thelindat thelindat changed the title Nil values in LUA not handled Undefined parameters when sending nil values from Lua Oct 12, 2021
@thelindat thelindat added enhancement New feature or request and removed help wanted Extra attention is needed labels Oct 12, 2021
@thelindat
Copy link
Member

I have this mostly working at the moment for named and unnamed parameters.

@thelindat
Copy link
Member

Only situation that fails is when sending only nil named parameters

@darksaid98
Copy link
Contributor

Fixed in #51.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants