Facepunch / garrysmod-issues

Garry's Mod issue tracker
147 stars 56 forks source link

SQLite NULL values are strings in lua #5105

Open Srlion opened 2 years ago

Srlion commented 2 years ago

Details

SQLite NULL values are returned as strings in lua.

Steps to reproduce

local res = sql.Query("SELECT NULL AS umm")[1]
print(res.umm, type(res.umm)) -- NULL    string
GitSparTV commented 2 years ago

I think this is intended because Lua doesn't have NULL.

But this could be fixed, i see a possible problem with backwards compatibility.

We could have sql.NULL light userdata or table object to indicate NULL, or just nil, but that might be ambiguous

GitSparTV commented 2 years ago

Or just _G.NULL lol

Srlion commented 2 years ago

mysqloo returns them as nil and tbh that's what sqlite should do too

GitSparTV commented 2 years ago

I wonder how people avoided this problem so we can find non-breaking solution. I remember I used val and SQLStr(val) or "NULL"