When using db_select's condition member function I was receiving errors when passing an empty array with the NOT IN operator. The MySQL was properly generating NOT IN (), but this is not legal syntax. I personally think it would be a good idea to take advantage of the database abstraction layer and simply not include the condition if the array passed in is empty and the operator is NOT IN (this likely has the same results with just the IN operator). At the very least a descriptive error message could be displayed.
<?php
$query = db_select('node', 'n')->fields('n');
$query->join('field_data_field_other_related_programs', 'fs', 'n.nid = fs.entity_id');
$query->join('field_data_field_scad_degree_types_vocref_1', 'dt', 'n.nid = dt.entity_id');
$query->join('taxonomy_term_data', 't', 'fs.field_other_related_programs_tid = t.tid');
$query->addField('t', 'tid');
$query
->condition('fs.field_other_related_programs_tid', $tid, '=')
->condition('n.type', 'scad_degree', '=')
->condition('dt.field_scad_degree_types_vocref_1_tid', $minor_tid, '=')
->condition('n.nid', $nodes_in_use, 'NOT IN');
->range(0, 4 - $count);
?>
The solution being to wrap the NOT IN condition in an IF-THEN statement:
<?php
if (isset($nodes_in_use) && !empty($nodes_in_use)) {
$query->condition('n.nid', $nodes_in_use, 'NOT IN');
}
?>