function DatabaseInsertLOBTestCase::testInsertOneBlob

Test that we can insert a single blob field successfully.

File

modules/simpletest/tests/database_test.test, line 740

Class

DatabaseInsertLOBTestCase
Insert tests using LOB fields, which are weird on some databases.

Code

function testInsertOneBlob() {
  $data = "This is\x00a test.";
  $this->assertTrue(strlen($data) === 15, 'Test data contains a NULL.');
  $id = db_insert('test_one_blob')->fields(array(
    'blob1' => $data,
  ))
    ->execute();
  $r = db_query('SELECT * FROM {test_one_blob} WHERE id = :id', array(
    ':id' => $id,
  ))->fetchAssoc();
  $this->assertTrue($r['blob1'] === $data, format_string('Can insert a blob: id @id, @data.', array(
    '@id' => $id,
    '@data' => serialize($r),
  )));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.