dart-drivers / mysql

MySQL Connector for Dart
Other
99 stars 38 forks source link

Bound parameters with a value of (Dart) null don't get inserted as mysql NULLs. #50

Closed sonoranDesert closed 10 years ago

sonoranDesert commented 10 years ago

I'm seeing Dart nulls getting inserted as the string "null" in mysql.

Is the expected behavior that sqljocky would translate Dart nulls into mysql NULLs, or do you have to do something special to get NULL in mysql?

For example:

String sql = 'UPDATE users SET name = ?'; List params = [null];

would yield a query of "UPDATE users SET name = 'null'", which is not the behavior I want.

sonoranDesert commented 10 years ago

Update: It seems that the problem is not turning Dart nulls into mysql NULLs, but rather the reverse.

I was pulling data OUT of mysql then stuffing it back in somewhere else, and it seems that sqljocky converts mysql NULLs into a Dart string "null".

sonoranDesert commented 10 years ago

Apologies for all the messages. I tracked this down to a bug of my own (eventually).

I wanted DB results from SELECT statements to be Maps, with key values corresponding to column names, so I wrote this code:

        return resultsObj.forEach((List row)
        {
            Map indexedRow = new Map();
            for(int i=0; i<resultsObj.fields.length; i++) {
                indexedRow[resultsObj.fields[i].name] = row[i].toString();
            }
            results.add(indexedRow);
        });

The "row[i].toString()" part is fine EXCEPT when the value is null. So, my mistake!