function DatabaseInsertTestCase::testInsertFieldOnlyDefinintion in SimpleTest 7
Test that we can specify fields without values and specify values later.
File
- tests/
database_test.test, line 499
Class
- DatabaseInsertTestCase
- Test the insert builder.
Code
function testInsertFieldOnlyDefinintion() {
// This is useful for importers, when we want to create a query and define
// its fields once, then loop over a multi-insert execution.
db_insert('test')
->fields(array(
'name',
'age',
))
->values(array(
'Larry',
'30',
))
->values(array(
'Curly',
'31',
))
->values(array(
'Moe',
'32',
))
->execute();
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(
':name' => 'Larry',
))
->fetchField();
$this
->assertIdentical($saved_age, '30', t('Can retrieve after inserting.'));
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(
':name' => 'Curly',
))
->fetchField();
$this
->assertIdentical($saved_age, '31', t('Can retrieve after inserting.'));
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(
':name' => 'Moe',
))
->fetchField();
$this
->assertIdentical($saved_age, '32', t('Can retrieve after inserting.'));
}