You are here

public function SqlServerSchemaTest::testUnsignedField in Drupal driver for SQL Server and SQL Azure 7

Same name and namespace in other branches
  1. 7.3 tests/sqlsrv.schema.test \SqlServerSchemaTest::testUnsignedField()
  2. 7.2 tests/sqlsrv.schema.test \SqlServerSchemaTest::testUnsignedField()

Test adding / modifying an unsigned column.

File

tests/sqlsrv.schema.test, line 87
Support tests for SQL Server.

Class

SqlServerSchemaTest
@file Support tests for SQL Server.

Code

public function testUnsignedField() {
  $table_spec = array(
    'fields' => array(
      'id' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
    ),
  );
  db_create_table('test_table', $table_spec);
  try {
    db_insert('test_table')
      ->fields(array(
      'id' => -1,
    ))
      ->execute();
    $failed = FALSE;
  } catch (Exception $e) {
    $failed = TRUE;
  }
  $this
    ->assertTrue($failed, t('Inserting a negative value in an unsigned field failed.'));
  $this
    ->assertUnsignedField('test_table', 'id');
  try {
    db_insert('test_table')
      ->fields(array(
      'id' => 1,
    ))
      ->execute();
    $failed = FALSE;
  } catch (Exception $e) {
    $failed = TRUE;
  }
  $this
    ->assertFalse($failed, t('Inserting a positive value in an unsigned field succeeded.'));

  // Change the field to signed.
  db_change_field('test_table', 'id', 'id', array(
    'type' => 'int',
    'not null' => TRUE,
  ));
  $this
    ->assertSignedField('test_table', 'id');

  // Change the field back to unsigned.
  db_change_field('test_table', 'id', 'id', array(
    'type' => 'int',
    'not null' => TRUE,
    'unsigned' => TRUE,
  ));
  $this
    ->assertUnsignedField('test_table', 'id');
}