diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-12-26 14:23:38 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-12-26 14:23:38 +0000 |
commit | 0d100b57dcffe54ec7f46d8f577a4c26fcf34202 (patch) | |
tree | ffcfb6c4cb5e1f9481479620c87b37a2c7b6ebec /modules | |
parent | fc063806de3ded56d1c3d78a49e8a60de7a7fe1c (diff) | |
download | brdo-0d100b57dcffe54ec7f46d8f577a4c26fcf34202.tar.gz brdo-0d100b57dcffe54ec7f46d8f577a4c26fcf34202.tar.bz2 |
- Patch #332002 by Crell et al: MergeQuery should refuse to execute if there are no key fields. With tests.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/simpletest/tests/database_test.test | 20 | ||||
-rw-r--r-- | modules/statistics/statistics.module | 13 |
2 files changed, 26 insertions, 7 deletions
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test index a725b2eee..d6a3b305f 100644 --- a/modules/simpletest/tests/database_test.test +++ b/modules/simpletest/tests/database_test.test @@ -957,6 +957,26 @@ class DatabaseMergeTestCase extends DatabaseTestCase { $this->assertEqual($person->age, $age_before + 4, t('Age updated correctly.')); $this->assertEqual($person->job, 'Speaker', t('Job set correctly.')); } + + /** + * Test that an invalid merge query throws an exception like it is supposed to. + */ + function testInvalidMerge() { + try { + // This query should die because there is no key field specified. + db_merge('test_people') + ->fields(array( + 'age' => 31, + 'name' => 'Tiffany', + )) + ->execute(); + } + catch (InvalidMergeQueryException $e) { + $this->pass(t('InvalidMergeQueryException thrown for invalid query.')); + return; + } + $this->fail(t('No InvalidMergeQueryException thrown')); + } } /** diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index d90c257d2..8cb1cc6e2 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -51,14 +51,13 @@ function statistics_exit() { // We are counting content views. if ((arg(0) == 'node') && is_numeric(arg(1)) && arg(2) == '') { // A node has been viewed, so update the node's counters. - $fields = array( - 'daycount' => 1, - 'totalcount' => 1, - 'nid' => arg(1), - 'timestamp' => REQUEST_TIME, - ); db_merge('node_counter') - ->fields($fields) + ->key(array('nid' => arg(1))) + ->fields(array( + 'daycount' => 1, + 'totalcount' => 1, + 'timestamp' => REQUEST_TIME, + )) ->expression('daycount', 'daycount + 1') ->expression('totalcount', 'totalcount + 1') ->execute(); |