Hello everyone!

I have just written the hook_insert function in a new module for Drupal 6 I am working on (using the Schema API), and I have used the drupal_write_record function to do it:

function roster_insert($node) {
	drupal_write_record('roster', $node);
}

I have also written the hook_update function using the same drupal_write_record function. Now I was writing the hook_delete function but I cannot find any equivalent of drupal_write_record to delete records. Only thing I can find is the classic:

db_query('DELETE FROM {roster} WHERE nid = %d', $node->nid);

Am I missing something?

Thanks in advance.

Comments

nevets’s picture

Why not use drupal_write_record and pass the key(s) as the 3rd argument (as an array). For example if the key to the 'roster' table is nid you could write roster_insert as

function roster_insert($node) {
drupal_write_record('roster', $node, array('nid'));
}
jsabater’s picture

Erm... I believe I did not explain my doubt clearly enough. It was about which function, similar to drupal_write_record, should be used to delete records, not to insert or update them.

nevets’s picture

I know but it is generally better to update records (compared to deleting and re-inserting).

jsabater’s picture

You mean doing a logical delete, don't you? (e.g. setting a boolean variable, "deleted", to true)

y01101414’s picture

You can see the book "Pro Drupal Development SECOND EDITION"
In the book you can find a tab about "Inserts and Updates with drupal_write_record()"(in page 142 you can find it.)
The book tell the drupal_write_record()'s function are insert and update but not delete.

voj’s picture

wow, you inserted a reference to a book. But the question is not yet answered.
Next time you put a reference you should make an explanation about the reference(specially if it's a book) or atleast lighten us up.
Your not helping. :)