1 database_test.test DatabaseInsertTestCase::testInsertSelectAll()

Tests that the INSERT INTO ... SELECT * ... syntax works.

File

core/modules/simpletest/tests/database_test.test, line 595
Database tests.

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.');
}