Is drupal_write_record() something that's being deprecated or is it still useful now that we have db_insert? Perhaps this question shows my current lack of understanding of the new Query objects.

I see that drupal_write_record calls db_insert but that drupal_write_record also seems to do some of the more advanced query building that is already done in the db_insert object instantiation. Is this the case? Thanks for any info that can be shared.

Comments

arbee’s picture

It's my understanding that drupal_write_record is on the endangered species list in favor of db_insert, even though it doesn't specifically say so on api.drupal.org like it does for db_query.

charlie-s’s picture

That's the impression I'm getting too. I was thrown because it's on the D8 API page too, but I assume that's just because the current D8 code contains 99% of the same code as D7.

henryblyth’s picture

It seems that without drupal_write_record(), one would have to place all database transactions inside a db_transaction() to have similar functionality in regards to checking the success/failure of the insert/update.

Although I am planning to include a particular insert/update inside a db_transaction() to capture the exact fault when one occurs and write it to the watchdog, it is nice to have a straight-up return value of FALSE, SAVED_NEW or SAVED_UPDATED to work on from drupal_write_record(). Although, SAVED_NEW and SAVED_UPDATED can be assumed on a successful db_insert() and db_update(), respectively.

Keen to hear some facts about drupal_write_record's longevity, though :)

Regards,
Henry