function DriverSpecificSchemaTestBase::tryUnsignedInsert

Same name in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Database/DriverSpecificSchemaTestBase.php \Drupal\KernelTests\Core\Database\DriverSpecificSchemaTestBase::tryUnsignedInsert()

Tries to insert a negative value into columns defined as unsigned.

Parameters

string $table_name: The table to insert.

string $column_name: The column to insert.

Return value

bool TRUE if the insert succeeded, FALSE otherwise.

1 call to DriverSpecificSchemaTestBase::tryUnsignedInsert()
DriverSpecificSchemaTestBase::testUnsignedColumns in core/tests/Drupal/KernelTests/Core/Database/DriverSpecificSchemaTestBase.php
Tests creating unsigned columns and data integrity thereof.

File

core/tests/Drupal/KernelTests/Core/Database/DriverSpecificSchemaTestBase.php, line 91

Class

DriverSpecificSchemaTestBase
Tests table creation and modification via the schema API.

Namespace

Drupal\KernelTests\Core\Database

Code

public function tryUnsignedInsert(string $table_name, string $column_name) : bool {
    try {
        $this->connection
            ->insert($table_name)
            ->fields([
            $column_name => -1,
        ])
            ->execute();
        return TRUE;
    } catch (\Exception $e) {
        return FALSE;
    }
}

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