function _messaging_query_conditions in Messaging 6.2
Same name and namespace in other branches
- 6.4 messaging.module \_messaging_query_conditions()
- 6 messaging.module \_messaging_query_conditions()
- 6.3 messaging.module \_messaging_query_conditions()
Helper function for query builders.
Using schema data get 'field = [placeholder]' and args arrays
Parameters
$table: Table name (to be prefixed)
$params: Array of field => value conditions
$table_alias: Optional table alias to prefix fields in conditions
File
- ./
messaging.module, line 1249
Code
function _messaging_query_conditions($table, $params, $table_alias = NULL) {
$schema = drupal_get_schema($table);
$conditions = $args = array();
foreach ($params as $field => $value) {
$type = $schema['fields'][$field]['type'];
$field_name = $table_alias ? "{$table_alias}.{$field}" : $field;
// For array values, build IN conditions
if (is_array($value)) {
$conditions[] = $field_name . ' IN (' . db_placeholders($value, $type) . ')';
$args = array_merge($args, $value);
}
elseif (is_null($value)) {
$condtions[] = $field_name . ' IS NULL';
}
else {
$conditions[] = $field_name . ' = ' . db_type_placeholder($type);
$args[] = $value;
}
}
// Return arrwy with conditions and arguments. Also full where clause.
return array(
'conditions' => $conditions,
'args' => $args,
'where' => implode(' AND ', $conditions),
);
}