diff options
author | David Rothstein <drothstein@gmail.com> | 2013-12-25 14:57:44 -0500 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2013-12-25 14:57:44 -0500 |
commit | cbabb1a24bf40e74363efbf0401ba8d37b8c9799 (patch) | |
tree | 6bee867bdb60e2ceacf02ca670026f7dd2bcdd83 /modules/simpletest | |
parent | 6c89f3924e7e375e634b52f539520b9125789431 (diff) | |
download | brdo-cbabb1a24bf40e74363efbf0401ba8d37b8c9799.tar.gz brdo-cbabb1a24bf40e74363efbf0401ba8d37b8c9799.tar.bz2 |
Issue #2056363 by yched, Sweetchuck, chx: INSERT INTO table SELECT * FROM ... not supported.
Diffstat (limited to 'modules/simpletest')
-rw-r--r-- | modules/simpletest/tests/database_test.install | 3 | ||||
-rw-r--r-- | modules/simpletest/tests/database_test.test | 26 |
2 files changed, 27 insertions, 2 deletions
diff --git a/modules/simpletest/tests/database_test.install b/modules/simpletest/tests/database_test.install index 867d81323..11361151f 100644 --- a/modules/simpletest/tests/database_test.install +++ b/modules/simpletest/tests/database_test.install @@ -87,6 +87,9 @@ function database_test_schema() { ), ); + $schema['test_people_copy'] = $schema['test_people']; + $schema['test_people_copy']['description'] = 'A duplicate version of the test_people table, used for additional tests.'; + $schema['test_one_blob'] = array( 'description' => 'A simple table including a BLOB field for testing BLOB behavior.', 'fields' => array( diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test index b58578e99..aa390bd43 100644 --- a/modules/simpletest/tests/database_test.test +++ b/modules/simpletest/tests/database_test.test @@ -23,6 +23,7 @@ class DatabaseTestCase extends DrupalWebTestCase { $schema['test'] = drupal_get_schema('test'); $schema['test_people'] = drupal_get_schema('test_people'); + $schema['test_people_copy'] = drupal_get_schema('test_people_copy'); $schema['test_one_blob'] = drupal_get_schema('test_one_blob'); $schema['test_two_blobs'] = drupal_get_schema('test_two_blobs'); $schema['test_task'] = drupal_get_schema('test_task'); @@ -603,9 +604,9 @@ class DatabaseInsertTestCase extends DatabaseTestCase { } /** - * Test that the INSERT INTO ... SELECT ... syntax works. + * Test that the INSERT INTO ... SELECT (fields) ... syntax works. */ - function testInsertSelect() { + function testInsertSelectFields() { $query = db_select('test_people', 'tp'); // The query builder will always append expressions after fields. // Add the expression first to test that the insert fields are correctly @@ -627,6 +628,27 @@ class DatabaseInsertTestCase extends DatabaseTestCase { $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Meredith'))->fetchField(); $this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.'); } + + /** + * Tests that the INSERT INTO ... SELECT * ... syntax works. + */ + function testInsertSelectAll() { + $query = db_select('test_people', 'tp') + ->fields('tp') + ->condition('tp.name', 'Meredith'); + + // The resulting query should be equivalent to: + // INSERT INTO test_people_copy + // SELECT * + // FROM test_people tp + // WHERE tp.name = 'Meredith' + db_insert('test_people_copy') + ->from($query) + ->execute(); + + $saved_age = db_query('SELECT age FROM {test_people_copy} WHERE name = :name', array(':name' => 'Meredith'))->fetchField(); + $this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.'); + } } /** |