Menu

#120 NULL turns to 0

open
nobody
None
9
2003-02-24
2002-10-22
Stephan
No

Problem:
--------
if you have a number field in a record with a NULL value
and you edit this record (change-operation) the NULL
value
is changed to 0 even if you dont edit the number field.

Reason:
-------
The generated update statement in the
do_change_record function
looks like UPDATE qFields SET `NUMBER_FIELD`='', ...
including all displayed fields!

Good solution:
--------------
1. Only fields which changed by user input should be
included
in the update statement AND
2. change ='' to =NULL for all non-string field types
(to handle the case that a user changed a non-null
value to NULL)

Dirty workaround:
-----------------
I added a line like
$qry = ereg_replace ( "\=\'\'", "\=NULL", $qry );
after the update statement is generated

This can be dragged down on the sql prompt, too:
------------------------------------------------

mysql> create table d (n varchar(2), i int);
mysql> insert into d (n) values ('AA');

phpMyEdit acts like this, if then i-field was not changed
by the user:

mysql> update d set n='BB',i='' where n='AA';
+------+------+
| n | i |
+------+------+
| BB | 0 | FALSE !!!!
+------+------+

phpMyEdit should do like:
mysql> update d set n='BB',I=NULL where n='AA';
+------+------+
| n | i |
+------+------+
| BB | NULL | OK !!!
+------+------+

or (because the i-field was not changed):
mysql> update d set n='BB' where n='AA';
+------+------+
| n | i |
+------+------+
| BB | NULL | OK !!!
+------+------+

Discussion

  • Ondrej Jombik

    Ondrej Jombik - 2003-02-24

    Logged In: YES
    user_id=226329

    This is not fixable. How will I know if value changed? Empty
    string ('') should be unchanged value, but also new value of
    old 'something' string.

     
  • Ondrej Jombik

    Ondrej Jombik - 2003-02-24
    • priority: 5 --> 9
     

Log in to post a comment.