You are here

function database_test_query_alter in Drupal 7

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/database_test/database_test.module \database_test_query_alter()
  2. 9 core/modules/system/tests/modules/database_test/database_test.module \database_test_query_alter()

Implements hook_query_alter().

File

modules/simpletest/tests/database_test.module, line 6

Code

function database_test_query_alter(QueryAlterableInterface $query) {
  if ($query
    ->hasTag('database_test_alter_add_range')) {
    $query
      ->range(0, 2);
  }
  if ($query
    ->hasTag('database_test_alter_add_join')) {
    $people_alias = $query
      ->join('test', 'people', "test_task.pid = %alias.id");
    $name_field = $query
      ->addField($people_alias, 'name', 'name');
    $query
      ->condition($people_alias . '.id', 2);
  }
  if ($query
    ->hasTag('database_test_alter_change_conditional')) {
    $conditions =& $query
      ->conditions();
    $conditions[0]['value'] = 2;
  }
  if ($query
    ->hasTag('database_test_alter_change_fields')) {
    $fields =& $query
      ->getFields();
    unset($fields['age']);
  }
  if ($query
    ->hasTag('database_test_alter_change_expressions')) {
    $expressions =& $query
      ->getExpressions();
    $expressions['double_age']['expression'] = 'age*3';
  }
}