public function SqlServerSchemaTest::testAddChangeWithBinary in Drupal driver for SQL Server and SQL Azure 7.2
Same name and namespace in other branches
- 7.3 tests/sqlsrv.schema.test \SqlServerSchemaTest::testAddChangeWithBinary()
Test db_add_field() and db_change_field() with binary spec.
File
- tests/
sqlsrv.schema.test, line 238 - Support tests for SQL Server.
Class
- SqlServerSchemaTest
- @file Support tests for SQL Server.
Code
public function testAddChangeWithBinary() {
$table_spec = array(
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
),
'name' => array(
'type' => 'varchar',
'length' => 255,
'binary' => false,
),
),
'primary key' => array(
'id',
),
);
db_create_table('test_table_binary', $table_spec);
// Insert a value in name
db_insert('test_table_binary')
->fields(array(
'name' => 'Sandra',
))
->execute();
// Insert a value in name
db_insert('test_table_binary')
->fields(array(
'name' => 'sandra',
))
->execute();
// By default, datase collation
// should be case insensitive, returning both rows.
$result = db_query('SELECT COUNT(*) FROM {test_table_binary} WHERE name = :name', array(
':name' => 'SANDRA',
))
->fetchField();
$this
->assertEqual($result, 2, 'Returned the correct number of total rows.');
// Now let's change the field
// to case sensistive
db_change_field('test_table_binary', 'name', 'name', array(
'type' => 'varchar',
'length' => 255,
'binary' => true,
));
// With case sensitivity, no results.
$result = db_query('SELECT COUNT(*) FROM {test_table_binary} WHERE name = :name', array(
':name' => 'SANDRA',
))
->fetchField();
$this
->assertEqual($result, 0, 'Returned the correct number of total rows.');
// Now one result.
$result = db_query('SELECT COUNT(*) FROM {test_table_binary} WHERE name = :name', array(
':name' => 'sandra',
))
->fetchField();
$this
->assertEqual($result, 1, 'Returned the correct number of total rows.');
}