62 lines
1.7 KiB
Plaintext
62 lines
1.7 KiB
Plaintext
<?php
|
|
// $Id$
|
|
|
|
/**
|
|
* Implementation of hook_query_alter().
|
|
*/
|
|
function database_test_query_alter(SelectQuery $query) {
|
|
|
|
if ($query->hasTag('database_test_alter_add_range')) {
|
|
$query->range(0, 2);
|
|
}
|
|
|
|
if ($query->hasTag('database_test_alter_remove_range')) {
|
|
$query->range();
|
|
}
|
|
|
|
if ($query->hasTag('database_test_alter_add_join')) {
|
|
$people_alias = $query->join('test', 'people', "test_task.pid=people.id");
|
|
$name_field = $query->addField('people', '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';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implementation of hook_menu().
|
|
*/
|
|
function database_test_menu() {
|
|
$items['database_test_db_query_temporary'] = array(
|
|
'access callback' => TRUE,
|
|
'page callback' => 'database_test_db_query_temporary',
|
|
);
|
|
return $items;
|
|
}
|
|
|
|
/**
|
|
* Run a db_query_temporary and print the number of rows in the resulting table.
|
|
*
|
|
* We need to test that the table created is temporary, so we run it here, in a
|
|
* separate menu callback request; After this request is done, the temporary
|
|
* table should automatically dropped.
|
|
*/
|
|
function database_test_db_query_temporary() {
|
|
db_query_temporary('SELECT status FROM {system}', array(), 'temporary');
|
|
print db_query('SELECT COUNT(*) FROM temporary')->fetchField();
|
|
exit;
|
|
}
|