View Issue Details

IDProjectCategoryView StatusLast Update
0008174Multi Theft Auto : San AndreasMulti Theft Auto : San Andreaspublic2014-04-24 02:05
Reporterrafalh Assigned Toccw  
Status resolvedResolutionfixed 
Target Version1.4Fixed in Version1.4 
Summary0008174: [request] nil/false in Lua to NULL in SQL

There is no way to set field value to NULL by using variable placeholders ('?') in dbQuery. Either false or nil doesn't work.
On the other hand it is possible to read NULL fields - MTA converts them to false in Lua.
Responsible functions: InsertQueryArgumentsSqlite, InsertQueryArgumentsMySql

Steps To Reproduce

dbQuery('INSERT INTO tbl (nullableField) VALUES(?)', false/nil)
Parameter false sets field to '0' and parameter nil sets field to '' (empty string).

Additional Information

NULL value can be set by writing SQL query without placeholders ('a=NULL') but it's not a solution.

TagsNo tags attached.



2014-04-14 16:39

manager   ~~0020668

dbExec('INSERT INTO tbl (nullableField) VALUES(NULL)')
dbExec('INSERT INTO tbl (nullableField) VALUES(??)', "NULL")

String parameters are automatically quoted and escaped as required. (If you do not want a string quoted, use ??)


2014-04-14 16:45

viewer   ~~0020669

I can do it this way but if I UPDATE many fields in one query and they are variables it would be better if some special value translates to NULL. Right now I have to make some conditional expressions or use my own parsing of query.
MTA should be more consistent. If it reads NULLs as false, it should allow to write NULLs as false in my opinion.


2014-04-14 16:47

manager   ~~0020670

Last edited: 2014-04-14 16:53

Yeah I understand, it's a completely reasonable request.

The solution would be turning nil into NULL but false would still turn to false.


2014-04-18 16:34

viewer   ~~0020709

I sign under this. This is so terrible to add useless checks.


2014-04-24 02:05

administrator   ~~0020750

Fixed in

Issue History

Date Modified Username Field Change