$this->assertTrue($insert_result==SAVED_NEW,'Correct value returned when a record is inserted with drupal_write_record() for a table with a single-field primary key.');
$this->assertTrue(isset($person->id),'Primary key is set on record created with drupal_write_record().');
$this->assertIdentical($person->age,0,'Age field set to default value.');
$this->assertIdentical($person->job,'Undefined','Job field set to default value.');
// Verify that the record was inserted.
$result=db_query("SELECT * FROM {test} WHERE id = :id",array(':id'=>$person->id))->fetchObject();
$this->assertIdentical($result->name,'John','Name field set.');
$this->assertIdentical($result->age,'0','Age field set to default value.');
$this->assertIdentical($result->job,'Undefined','Job field set to default value.');
$this->assertFalse(isset($result->unknown_column),'Unknown column was ignored.');
$this->assertTrue($update_result==SAVED_UPDATED,'Correct value returned when a record updated with drupal_write_record() for table with single-field primary key.');
// Verify that the record was updated.
$result=db_query("SELECT * FROM {test} WHERE id = :id",array(':id'=>$person->id))->fetchObject();
$this->assertIdentical($result->name,'Peter','Name field set.');
$this->assertIdentical($result->age,'27','Age field set.');
$this->assertIdentical($result->job,'','Job field set and cast to string.');
// Try to insert NULL in columns that does not allow this.
$person=new\stdClass();
$person->name='Ringo';
$person->age=NULL;
$person->job=NULL;
drupal_write_record('test',$person);
$this->assertTrue(isset($person->id),'Primary key is set on record created with drupal_write_record().');
$result=db_query("SELECT * FROM {test} WHERE id = :id",array(':id'=>$person->id))->fetchObject();
$this->assertIdentical($result->name,'Ringo','Name field set.');
$this->assertIdentical($result->age,'0','Age field set.');
$this->assertIdentical($result->job,'','Job field set.');
// Insert a record - the "age" column allows NULL.
$person=new\stdClass();
$person->name='Paul';
$person->age=NULL;
drupal_write_record('test_null',$person);
$this->assertTrue(isset($person->id),'Primary key is set on record created with drupal_write_record().');
$result=db_query("SELECT * FROM {test_null} WHERE id = :id",array(':id'=>$person->id))->fetchObject();
$this->assertIdentical($result->name,'Paul','Name field set.');
$this->assertIdentical($result->age,NULL,'Age field set.');
// Insert a record - do not specify the value of a column that allows NULL.
$person=new\stdClass();
$person->name='Meredith';
drupal_write_record('test_null',$person);
$this->assertTrue(isset($person->id),'Primary key is set on record created with drupal_write_record().');
$this->assertIdentical($person->age,0,'Age field set to default value.');
$result=db_query("SELECT * FROM {test_null} WHERE id = :id",array(':id'=>$person->id))->fetchObject();
$this->assertIdentical($result->name,'Meredith','Name field set.');
$this->assertIdentical($result->age,'0','Age field set to default value.');
$this->assertTrue($insert_result==SAVED_NEW,'Correct value returned when a record is inserted with drupal_write_record() for a table with a multi-field primary key.');
$this->assertTrue($update_result==SAVED_UPDATED,'Correct value returned when a record is updated with drupal_write_record() for a table with a multi-field primary key.');