if (is_null($value)) {
$where[] = "$key IS NULL";
} else {
- $isstring = (is_string($value) && !is_number($value));
if ($allowed_types & SQL_PARAMS_NAMED) {
// Need to verify key names because they can contain, originally,
// spaces and other forbidden chars when using sql_xxx() functions and friends.
if ($normkey !== $key) {
debugging('Invalid key found in the conditions array.');
}
- if ($isstring) {
- $where[] = $this->sql_binary_equal($key, ':'.$normkey);
- } else {
- $where[] = "$key = :$normkey";
- }
+ $where[] = "$key = :$normkey";
$params[$normkey] = $value;
} else {
- if ($isstring) {
- $where[] = $this->sql_binary_equal($key, '?');
- } else {
- $where[] = "$key = ?";
- }
+ $where[] = "$key = ?";
$params[] = $value;
}
}
return $this->sql_order_by_text($fieldname, $numchars);
}
- /**
- * Case and collation sensitive string 'string = string'
- * @param string $string1
- * @param string $string2
- * @return string SQL fragment
- */
- public function sql_binary_equal($string1, $string2) {
- return "$string1 = $string2";
- }
-
/**
* Returns 'LIKE' part of a query.
*
return $this->collation;
}
- /**
- * Case and collation sensitive string 'string = string'
- * @param string $string1
- * @param string $string2
- * @return string SQL fragment
- */
- public function sql_binary_equal($string1, $string2) {
- //TODO: we need to make sure this does not break unique indexes
- //return "$string1 COLLATE Latin1_General_CS_AS = $string2";
- return "$string1 = $string2";
- }
-
/**
* Returns 'LIKE' part of a query.
*
return ' CAST(' . $fieldname . ' AS SIGNED) ';
}
-
- /**
- * Case and collation sensitive string 'string = string'
- * @param string $string1
- * @param string $string2
- * @return string SQL fragment
- */
- public function sql_binary_equal($string1, $string2) {
- //TODO: we need to make sure this does not break unique indexes
- //return "BINARY $string1 = $string2";
- return "$string1 = $string2";
- }
-
/**
* Returns 'LIKE' part of a query.
*
$DB->insert_record($tablename, array('name'=>'aaa'));
$DB->insert_record($tablename, array('name'=>'aäa'));
$DB->insert_record($tablename, array('name'=>'aáa'));
+ $DB->insert_record($tablename, array('name'=>'AAA'));
+ $DB->insert_record($tablename, array('name'=>'aÄa'));
$this->assertTrue(true);
} catch (Exception $e) {
- $this->fail("Database collation is not supposed to make unique index accent insensitive!");
+ $this->fail("Collation uniqueness problem detected - default collation is expected to be case sensitive and accent sensitive.");
throw($e);
}
}
$DB->insert_record($tablename, array('name'=>'aäa', 'descr'=>'aäa'));
$DB->insert_record($tablename, array('name'=>'AAA', 'descr'=>'AAA'));
- $sql = "SELECT * FROM {".$tablename."} WHERE ".$DB->sql_binary_equal('name', '?');
- $records = $DB->get_records_sql($sql, array("aaa"));
- $this->assertEqual(count($records), 1);
-
- $sql = "SELECT * FROM {".$tablename."} WHERE ".$DB->sql_binary_equal('name', '?');
- $records = $DB->get_records_sql($sql, array("aáa"));
- $this->assertEqual(count($records), 1);
-
- $sql = "SELECT * FROM {".$tablename."} WHERE ".$DB->sql_binary_equal('name', 'descr');
- $records = $DB->get_records_sql($sql, array());
- $this->assertEqual(count($records), 2);
-
- // get_records() is supposed to use binary comparison too
+ // get_records() is supposed to use binary comparison
$records = $DB->get_records($tablename, array('name'=>"aaa"));
- $this->assertEqual(count($records), 1);
+ $this->assertEqual(count($records), 1, 'SQL operator = is expected to be case and accent sensitive');
$records = $DB->get_records($tablename, array('name'=>"aäa"));
- $this->assertEqual(count($records), 1);
+ $this->assertEqual(count($records), 1, 'SQL operator = is expected to be case and accent sensitive');
$bool = $DB->record_exists($tablename, array('name'=>"aaa"));
- $this->assertTrue($bool);
+ $this->assertTrue($bool, 'SQL operator = is expected to be case and accent sensitive');
$bool = $DB->record_exists($tablename, array('name'=>"AaA"));
- $this->assertFalse($bool);
+ $this->assertFalse($bool, 'SQL operator = is expected to be case and accent sensitive');
}
function test_sql_like() {