How can I update or insert a row with NULL fields using query builder?
db_update() does allow NULL to be used for field values. To confirm this, check out the core table, block_custom, which allows both block_custom.body and block_custom.format to be NULL.

First, insert some dummy data either through the block administration screen or via SQL:

INSERT INTO block_custom (body, info, format)
  VALUES ('Lorem Ipsum', 'Test block', 'plain_text');


Now run the following code:

db_update('block_custom')
  -&gt;fields(array('body' =&gt; NULL))
  -&gt;condition('info', 'Test block')
  -&gt;execute();


If you look at the table after executing, block_custom.body will be set to NULL.

db_insert() works too:

$fields = array(
  'body' =&gt; NULL,
  'info' =&gt; 'Test block 2',
  'format' =&gt; 'plain_text',
);

$result = db_insert('block_custom')
  -&gt;fields($fields)
  -&gt;execute();


So there's something else wrong with your statement. Two things to check:


Ensure $record really has NULL values in the db_update() query. var_dump() the array just before the db_update() and ensure nothing's modified the values.
Check the condition statement. If set to a condition that doesn't match any of the rows in the table, the update won't occur and $result will contain a falsy value. Since it's perfectly value to have an UPDATE query that matches no rows, it won't throw an exception or return an error.