function DatabaseInsertTestCase::testInsertSelectAll
Tests that the INSERT INTO ... SELECT * ... syntax works.
File
-
modules/
simpletest/ tests/ database_test.test, line 705
Class
- DatabaseInsertTestCase
- Test the insert builder.
Code
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.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.