开发者

MySql setting that allows "" to be equal to null or 0?

I've got a MySQL server running on linux and another on Windows, both containing duplicate copies of a database table. The table is defined like:开发者_如何学Python

parent_id - int(10) - nullable - default=null
title - varchar(100)

I can execute this sql on Linux, and it works fine (I know, it's wrong and horrible and shouldn't work, but it does). Inserting a 0 into in the parent ID, but on Windows an error is thrown saying to use the right syntax near "":

insert into some_table (parent_id, title) values ("", "Some string")

Is there a MySQL setting that tells the Linux version to accept a "" as a valid int?

EDIT

I want it to be known that I agree, making the above work just plain sick. It's wrong in every way - but it's something I have to deal with. I'm tasked with maintaining a poorly written PHP product that depends on the above type of SQL statement being able to execute.

EDIT 2

What's interesting is that in the console, MySQL on Linux throws a warning saying "Incorrect integer value ''" - yet it still inserts the record. MySQL on Windows throws the message but doesn't do the insert. So somehow, MySQL on Linux is setup to ignore errors... does anyone know where this setting resides?


How about using the IFNULL or IF function to fix your statement rather than changing a MySQL setting.


Because the column is defined with a default, you can omit specifying it in the insert statement.

Sorry, maybe i misread your problem. Are you trying to insert a zero as the value for parent_id ?


Simply dont set the parent_id value.

insert into some_table (title) values ("Some string")


Ultimately, I never did find the setting in MySQL that allows this. Not that I'm too broken up about it. I talked the client into giving more time to making the app correct and simply removed all the poorly written code that relied on the setting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜