NULL vs Empty when dealing with user input

前端 未结 8 2024
一整个雨季
一整个雨季 2021-02-06 11:57

Yes, another NULL vs empty string question.

I agree with the idea that NULL means not set, while empty string means \"a value that is empty\". Here\'s my problem: If the

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-06 12:34

    What you need to do is figure out what behavior you want. There is no one fixed algebra of how name strings are interpreted.

    Think about the state machine here: you have fields which have several states: it slounds like you're thinking about a state of "unitialized", another of "purposefully empty" and a third with some set value. ANYTHING you do that makes that assignment and is consistent with the rest of your program will be find; it sounds like the easy mapping is

    NULL → uninitialized
    "" → purposefully unset
    a name → initialized.

提交回复
热议问题