function InsertTest::testInsertSelectAll
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/InsertTest.php \Drupal\KernelTests\Core\Database\InsertTest::testInsertSelectAll()
- 10 core/tests/Drupal/KernelTests/Core/Database/InsertTest.php \Drupal\KernelTests\Core\Database\InsertTest::testInsertSelectAll()
- 11.x core/tests/Drupal/KernelTests/Core/Database/InsertTest.php \Drupal\KernelTests\Core\Database\InsertTest::testInsertSelectAll()
Tests that the INSERT INTO ... SELECT * ... syntax works.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ InsertTest.php, line 179
Class
- InsertTest
- Tests the insert builder.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testInsertSelectAll() {
$query = $this->connection
->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'
$this->connection
->insert('test_people_copy')
->from($query)
->execute();
$saved_age = $this->connection
->query('SELECT age FROM {test_people_copy} WHERE name = :name', [
':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.