Query alters
Lots of things in Drupal are alterable using various hooks; queries are no different. This means that if a module writes a query such as we've seen before, other modules can alter it by implementing hook_query_alter()
. So let's consider an example of how this may work.
Assume the following query, which simply returns all player records:
$result = $database->select('players', 'p') Â Â Â ->fields('p') Â Â Â ->execute();
Imagine that another module wants to alter this query and limit the results to find only the players in a specific team. There is one problem. Our query has no markers that can indicate to another module that this is the one that needs to be altered. As you can imagine, there are a bunch of queries that are run in any given request, so identifying queries becomes impossible. Enter query tags.
The previous query would not be alterable because it's not recognizable, and...