function SchemaTest::tryInsert

Tests inserting data into an existing table.

Parameters

$table: The database table to insert data into.

Return value

TRUE if the insert succeeded, FALSE otherwise.

1 call to SchemaTest::tryInsert()
SchemaTest::testSchema in drupal/core/modules/system/lib/Drupal/system/Tests/Common/SchemaTest.php
Tests database interactions.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Common/SchemaTest.php, line 157
Definition of Drupal\system\Tests\Common\SchemaTest.

Class

SchemaTest
Tests the Schema API.

Namespace

Drupal\system\Tests\Common

Code

function tryInsert($table = 'test_table') {
  try {
    db_insert($table)
      ->fields(array(
      'id' => mt_rand(10, 20),
    ))
      ->execute();
    return TRUE;
  } catch (Exception $e) {
    return FALSE;
  }
}