Here's a quick tip for newbie module builders (like myself).
The process of development is likely to involve many installs, as well as many uninstalls, of your new module. If you're doing this right, you'll have a hook_uninstall() function in your .install file that cleans out any DB tables you've added.
I need to first find out if a certain value X exists in a certain column in a certain table. Ideally, I just want a binary value returned, so I can proceed with other stuff, depending on whether or not X exists. I've reduced it to one line of Drupal code:
$value_exists = db_result(db_query("SELECT IF (%d in (SELECT id FROM {some_table}), 1, 0)", $value));It works! But it still seems pretty convoluted. Anyone know if there's a more elegant way to test if a value exists?
As I recently mentioned, the .install file of my pending (and very customized) module creates a new vocabulary, to accomodate the new nodes being imported via web services. Upon creation of the vocabulary, I need to know the vid, so I can then populate the new vocabulary with terms.
The question is: what's the proper way to do this. After some research, I went with this: