You are here

function SchemaTest::tryInsert in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/SchemaTest.php \Drupal\system\Tests\Database\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 core/modules/system/src/Tests/Database/SchemaTest.php
Tests database interactions.

File

core/modules/system/src/Tests/Database/SchemaTest.php, line 386
Contains \Drupal\system\Tests\Database\SchemaTest.

Class

SchemaTest
Tests table creation and modification via 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;
  }
}