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/Database/SchemaTest.php
Tests database interactions.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Database/SchemaTest.php, line 155
Contains Drupal\system\Tests\Database\SchemaTest.

Class

SchemaTest
Tests the Schema API.

Namespace

Drupal\system\Tests\Database

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;
  }
}