Unverified Commit 749984b9 authored by alexpott's avatar alexpott

Issue #3152390 by munish.kumar, Deepak Goyal, daffie: Bracket-encapsulated...

Issue #3152390 by munish.kumar, Deepak Goyal, daffie: Bracket-encapsulated field names for static queries in core/tests/Drupal/KernelTests/Core/Database

(cherry picked from commit dbd93506)
parent 25e59e2f
......@@ -37,7 +37,7 @@ public function testConcatLiterals() {
*/
public function testConcatFields() {
$result = $this->connection->query(
'SELECT CONCAT(:a1, CONCAT(job, CONCAT(:a2, CONCAT(age, :a3)))) FROM {test} WHERE age = :age', [
'SELECT CONCAT(:a1, CONCAT([job], CONCAT(:a2, CONCAT([age], :a3)))) FROM {test} WHERE [age] = :age', [
':a1' => 'The age of ',
':a2' => ' is ',
':a3' => '.',
......@@ -64,7 +64,7 @@ public function testConcatWsLiterals() {
* Tests string concatenation with separator, with field values.
*/
public function testConcatWsFields() {
$result = $this->connection->query("SELECT CONCAT_WS('-', :a1, name, :a2, age) FROM {test} WHERE age = :age", [
$result = $this->connection->query("SELECT CONCAT_WS('-', :a1, [name], :a2, [age]) FROM {test} WHERE [age] = :age", [
':a1' => 'name',
':a2' => 'age',
':age' => 25,
......@@ -160,7 +160,7 @@ public function testAllowSquareBrackets() {
$this->assertIdentical('[square]', $result->fetchField());
// Test that allow_square_brackets has no effect on arguments.
$result = $this->connection->query("select name from {test} where name = :value", [':value' => '[square]']);
$result = $this->connection->query("select [name] from {test} where [name] = :value", [':value' => '[square]']);
$this->assertIdentical('[square]', $result->fetchField());
$result = $this->connection->query("select name from {test} where name = :value", [':value' => '[square]'], ['allow_square_brackets' => TRUE]);
$this->assertIdentical('[square]', $result->fetchField());
......
......@@ -26,7 +26,7 @@ public function testCaseSensitiveInsert() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField();
$this->assertSame($num_records_before + 1, (int) $num_records_after, 'Record inserts correctly.');
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'john'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'john'])->fetchField();
$this->assertIdentical($saved_age, '2', 'Can retrieve after inserting.');
}
......
......@@ -22,7 +22,7 @@ class DeleteTruncateTest extends DatabaseTestBase {
*/
public function testSubselectDelete() {
$num_records_before = $this->connection->query('SELECT COUNT(*) FROM {test_task}')->fetchField();
$pid_to_delete = $this->connection->query("SELECT * FROM {test_task} WHERE task = 'sleep' ORDER BY tid")->fetchField();
$pid_to_delete = $this->connection->query("SELECT * FROM {test_task} WHERE [task] = 'sleep' ORDER BY [tid]")->fetchField();
$subquery = $this->connection->select('test', 't')
->fields('t', ['id'])
......
......@@ -20,7 +20,7 @@ class FetchTest extends DatabaseTestBase {
*/
public function testQueryFetchDefault() {
$records = [];
$result = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25]);
$result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25]);
$this->assertInstanceOf(StatementInterface::class, $result);
foreach ($result as $record) {
$records[] = $record;
......@@ -36,7 +36,7 @@ public function testQueryFetchDefault() {
*/
public function testQueryFetchObject() {
$records = [];
$result = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25], ['fetch' => \PDO::FETCH_OBJ]);
$result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25], ['fetch' => \PDO::FETCH_OBJ]);
foreach ($result as $record) {
$records[] = $record;
$this->assertIsObject($record);
......@@ -51,7 +51,7 @@ public function testQueryFetchObject() {
*/
public function testQueryFetchArray() {
$records = [];
$result = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25], ['fetch' => \PDO::FETCH_ASSOC]);
$result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25], ['fetch' => \PDO::FETCH_ASSOC]);
foreach ($result as $record) {
$records[] = $record;
$this->assertIsArray($record);
......@@ -69,7 +69,7 @@ public function testQueryFetchArray() {
*/
public function testQueryFetchClass() {
$records = [];
$result = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25], ['fetch' => FakeRecord::class]);
$result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25], ['fetch' => FakeRecord::class]);
foreach ($result as $record) {
$records[] = $record;
$this->assertInstanceOf(FakeRecord::class, $record);
......@@ -87,7 +87,7 @@ public function testQueryFetchClass() {
*/
public function testQueryFetchObjectClass() {
$records = 0;
$query = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25]);
$query = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25]);
while ($result = $query->fetchObject(FakeRecord::class)) {
$records += 1;
$this->assertInstanceOf(FakeRecord::class, $result);
......@@ -104,7 +104,7 @@ public function testQueryFetchObjectClass() {
*/
public function testQueryFetchClasstype() {
$records = [];
$result = $this->connection->query('SELECT classname, name, job FROM {test_classtype} WHERE age = :age', [':age' => 26], ['fetch' => \PDO::FETCH_CLASS | \PDO::FETCH_CLASSTYPE]);
$result = $this->connection->query('SELECT [classname], [name], [job] FROM {test_classtype} WHERE [age] = :age', [':age' => 26], ['fetch' => \PDO::FETCH_CLASS | \PDO::FETCH_CLASSTYPE]);
foreach ($result as $record) {
$records[] = $record;
$this->assertInstanceOf(FakeRecord::class, $record);
......@@ -121,7 +121,7 @@ public function testQueryFetchClasstype() {
*/
public function testQueryFetchNum() {
$records = [];
$result = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25], ['fetch' => \PDO::FETCH_NUM]);
$result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25], ['fetch' => \PDO::FETCH_NUM]);
foreach ($result as $record) {
$records[] = $record;
$this->assertIsArray($record);
......@@ -137,7 +137,7 @@ public function testQueryFetchNum() {
*/
public function testQueryFetchBoth() {
$records = [];
$result = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25], ['fetch' => \PDO::FETCH_BOTH]);
$result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25], ['fetch' => \PDO::FETCH_BOTH]);
foreach ($result as $record) {
$records[] = $record;
$this->assertIsArray($record);
......@@ -167,11 +167,11 @@ public function testQueryFetchAllColumn() {
* Confirms that we can fetch an entire column of a result set at once.
*/
public function testQueryFetchCol() {
$result = $this->connection->query('SELECT name FROM {test} WHERE age > :age', [':age' => 25]);
$result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] > :age', [':age' => 25]);
$column = $result->fetchCol();
$this->assertCount(3, $column, 'fetchCol() returns the right number of records.');
$result = $this->connection->query('SELECT name FROM {test} WHERE age > :age', [':age' => 25]);
$result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] > :age', [':age' => 25]);
$i = 0;
foreach ($result as $record) {
$this->assertIdentical($record->name, $column[$i++], 'Column matches direct access.');
......@@ -182,7 +182,7 @@ public function testQueryFetchCol() {
* Tests that rowCount() throws exception on SELECT query.
*/
public function testRowCount() {
$result = $this->connection->query('SELECT name FROM {test}');
$result = $this->connection->query('SELECT [name] FROM {test}');
try {
$result->rowCount();
$exception = FALSE;
......
......@@ -20,7 +20,7 @@ public function testDefaultInsert() {
$schema = drupal_get_module_schema('database_test', 'test');
$job = $this->connection->query('SELECT job FROM {test} WHERE id = :id', [':id' => $id])->fetchField();
$job = $this->connection->query('SELECT [job] FROM {test} WHERE [id] = :id', [':id' => $id])->fetchField();
$this->assertEqual($job, $schema['fields']['job']['default'], 'Default field value is set.');
}
......@@ -54,7 +54,7 @@ public function testDefaultInsertWithFields() {
$schema = drupal_get_module_schema('database_test', 'test');
$job = $this->connection->query('SELECT job FROM {test} WHERE id = :id', [':id' => $id])->fetchField();
$job = $this->connection->query('SELECT [job] FROM {test} WHERE [id] = :id', [':id' => $id])->fetchField();
$this->assertEqual($job, $schema['fields']['job']['default'], 'Default field value is set.');
}
......
......@@ -20,7 +20,7 @@ public function testInsertOneBlob() {
$id = $this->connection->insert('test_one_blob')
->fields(['blob1' => $data])
->execute();
$r = $this->connection->query('SELECT * FROM {test_one_blob} WHERE id = :id', [':id' => $id])->fetchAssoc();
$r = $this->connection->query('SELECT * FROM {test_one_blob} WHERE [id] = :id', [':id' => $id])->fetchAssoc();
$this->assertTrue($r['blob1'] === $data, new FormattableMarkup('Can insert a blob: id @id, @data.', ['@id' => $id, '@data' => serialize($r)]));
}
......@@ -34,7 +34,7 @@ public function testInsertMultipleBlob() {
'blob2' => 'a test',
])
->execute();
$r = $this->connection->query('SELECT * FROM {test_two_blobs} WHERE id = :id', [':id' => $id])->fetchAssoc();
$r = $this->connection->query('SELECT * FROM {test_two_blobs} WHERE [id] = :id', [':id' => $id])->fetchAssoc();
$this->assertTrue($r['blob1'] === 'This is' && $r['blob2'] === 'a test', 'Can insert multiple blobs per row.');
}
......
......@@ -27,7 +27,7 @@ public function testSimpleInsert() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField();
$this->assertSame($num_records_before + 1, (int) $num_records_after, 'Record inserts correctly.');
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Yoko'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Yoko'])->fetchField();
$this->assertIdentical($saved_age, '29', 'Can retrieve after inserting.');
}
......@@ -62,11 +62,11 @@ public function testMultiInsert() {
$num_records_after = (int) $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField();
$this->assertSame($num_records_before + 3, $num_records_after, 'Record inserts correctly.');
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Larry'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Larry'])->fetchField();
$this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Curly'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Curly'])->fetchField();
$this->assertIdentical($saved_age, '31', 'Can retrieve after inserting.');
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Moe'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Moe'])->fetchField();
$this->assertIdentical($saved_age, '32', 'Can retrieve after inserting.');
}
......@@ -105,11 +105,11 @@ public function testRepeatedInsert() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField();
$this->assertSame((int) $num_records_before + 3, (int) $num_records_after, 'Record inserts correctly.');
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Larry'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Larry'])->fetchField();
$this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Curly'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Curly'])->fetchField();
$this->assertIdentical($saved_age, '31', 'Can retrieve after inserting.');
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Moe'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Moe'])->fetchField();
$this->assertIdentical($saved_age, '32', 'Can retrieve after inserting.');
}
......@@ -125,11 +125,11 @@ public function testInsertFieldOnlyDefinition() {
->values(['Curly', '31'])
->values(['Moe', '32'])
->execute();
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Larry'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Larry'])->fetchField();
$this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Curly'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Curly'])->fetchField();
$this->assertIdentical($saved_age, '31', 'Can retrieve after inserting.');
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Moe'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Moe'])->fetchField();
$this->assertIdentical($saved_age, '32', 'Can retrieve after inserting.');
}
......@@ -169,7 +169,7 @@ public function testInsertSelectFields() {
->from($query)
->execute();
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Meredith'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Meredith'])->fetchField();
$this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
}
......@@ -190,7 +190,7 @@ public function testInsertSelectAll() {
->from($query)
->execute();
$saved_age = $this->connection->query('SELECT age FROM {test_people_copy} WHERE name = :name', [':name' => 'Meredith'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test_people_copy} WHERE [name] = :name', [':name' => 'Meredith'])->fetchField();
$this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
}
......@@ -204,7 +204,7 @@ public function testSpecialColumnInsert() {
'update' => 'Update value 2',
])
->execute();
$saved_value = $this->connection->query('SELECT [update] FROM {select} WHERE id = :id', [':id' => 2])->fetchField();
$saved_value = $this->connection->query('SELECT [update] FROM {select} WHERE [id] = :id', [':id' => 2])->fetchField();
$this->assertEquals('Update value 2', $saved_value);
}
......
......@@ -33,7 +33,7 @@ public function testMaxAllowedPacketQueryTruncating() {
$long_name = str_repeat('a', $max_allowed_packet + 1);
try {
$this->connection->query('SELECT name FROM {test} WHERE name = :name', [':name' => $long_name]);
$this->connection->query('SELECT [name] FROM {test} WHERE [name] = :name', [':name' => $long_name]);
$this->fail("An exception should be thrown for queries larger than 'max_allowed_packet'");
}
catch (DatabaseException $e) {
......
......@@ -20,8 +20,8 @@ class LoggingTest extends DatabaseTestBase {
public function testEnableLogging() {
Database::startLog('testing');
$this->connection->query('SELECT name FROM {test} WHERE age > :age', [':age' => 25])->fetchCol();
$this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Ringo'])->fetchCol();
$this->connection->query('SELECT [name] FROM {test} WHERE [age] > :age', [':age' => 25])->fetchCol();
$this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Ringo'])->fetchCol();
// Trigger a call that does not have file in the backtrace.
call_user_func_array([Database::getConnection(), 'query'], ['SELECT age FROM {test} WHERE name = :name', [':name' => 'Ringo']])->fetchCol();
......@@ -41,11 +41,11 @@ public function testEnableLogging() {
public function testEnableMultiLogging() {
Database::startLog('testing1');
$this->connection->query('SELECT name FROM {test} WHERE age > :age', [':age' => 25])->fetchCol();
$this->connection->query('SELECT [name] FROM {test} WHERE [age] > :age', [':age' => 25])->fetchCol();
Database::startLog('testing2');
$this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Ringo'])->fetchCol();
$this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Ringo'])->fetchCol();
$queries1 = Database::getLog('testing1');
$queries2 = Database::getLog('testing2');
......@@ -65,9 +65,9 @@ public function testEnableTargetLogging() {
Database::startLog('testing1');
$this->connection->query('SELECT name FROM {test} WHERE age > :age', [':age' => 25])->fetchCol();
$this->connection->query('SELECT [name] FROM {test} WHERE [age] > :age', [':age' => 25])->fetchCol();
Database::getConnection('replica')->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Ringo'])->fetchCol();
Database::getConnection('replica')->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Ringo'])->fetchCol();
$queries1 = Database::getLog('testing1');
......@@ -86,14 +86,14 @@ public function testEnableTargetLogging() {
public function testEnableTargetLoggingNoTarget() {
Database::startLog('testing1');
$this->connection->query('SELECT name FROM {test} WHERE age > :age', [':age' => 25])->fetchCol();
$this->connection->query('SELECT [name] FROM {test} WHERE [age] > :age', [':age' => 25])->fetchCol();
// We use "fake" here as a target because any non-existent target will do.
// However, because all of the tests in this class share a single page
// request there is likely to be a target of "replica" from one of the other
// unit tests, so we use a target here that we know with absolute certainty
// does not exist.
Database::getConnection('fake')->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Ringo'])->fetchCol();
Database::getConnection('fake')->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Ringo'])->fetchCol();
$queries1 = Database::getLog('testing1');
......@@ -114,11 +114,11 @@ public function testEnableMultiConnectionLogging() {
Database::startLog('testing1');
Database::startLog('testing1', 'test2');
$this->connection->query('SELECT name FROM {test} WHERE age > :age', [':age' => 25])->fetchCol();
$this->connection->query('SELECT [name] FROM {test} WHERE [age] > :age', [':age' => 25])->fetchCol();
$old_key = Database::setActiveConnection('test2');
Database::getConnection('replica')->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Ringo'])->fetchCol();
Database::getConnection('replica')->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Ringo'])->fetchCol();
Database::setActiveConnection($old_key);
......
......@@ -31,7 +31,7 @@ public function testMergeInsert() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$this->assertEqual($num_records_before + 1, $num_records_after, 'Merge inserted properly.');
$person = $this->connection->query('SELECT * FROM {test_people} WHERE job = :job', [':job' => 'Presenter'])->fetch();
$person = $this->connection->query('SELECT * FROM {test_people} WHERE [job] = :job', [':job' => 'Presenter'])->fetch();
$this->assertEqual($person->name, 'Tiffany', 'Name set correctly.');
$this->assertEqual($person->age, 31, 'Age set correctly.');
$this->assertEqual($person->job, 'Presenter', 'Job set correctly.');
......@@ -56,7 +56,7 @@ public function testMergeUpdate() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$this->assertEqual($num_records_before, $num_records_after, 'Merge updated properly.');
$person = $this->connection->query('SELECT * FROM {test_people} WHERE job = :job', [':job' => 'Speaker'])->fetch();
$person = $this->connection->query('SELECT * FROM {test_people} WHERE [job] = :job', [':job' => 'Speaker'])->fetch();
$this->assertEqual($person->name, 'Tiffany', 'Name set correctly.');
$this->assertEqual($person->age, 31, 'Age set correctly.');
$this->assertEqual($person->job, 'Speaker', 'Job set correctly.');
......@@ -80,7 +80,7 @@ public function testMergeUpdateExcept() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$this->assertEqual($num_records_before, $num_records_after, 'Merge updated properly.');
$person = $this->connection->query('SELECT * FROM {test_people} WHERE job = :job', [':job' => 'Speaker'])->fetch();
$person = $this->connection->query('SELECT * FROM {test_people} WHERE [job] = :job', [':job' => 'Speaker'])->fetch();
$this->assertEqual($person->name, 'Tiffany', 'Name set correctly.');
$this->assertEqual($person->age, 30, 'Age skipped correctly.');
$this->assertEqual($person->job, 'Speaker', 'Job set correctly.');
......@@ -106,7 +106,7 @@ public function testMergeUpdateExplicit() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$this->assertEqual($num_records_before, $num_records_after, 'Merge updated properly.');
$person = $this->connection->query('SELECT * FROM {test_people} WHERE job = :job', [':job' => 'Speaker'])->fetch();
$person = $this->connection->query('SELECT * FROM {test_people} WHERE [job] = :job', [':job' => 'Speaker'])->fetch();
$this->assertEqual($person->name, 'Joe', 'Name set correctly.');
$this->assertEqual($person->age, 30, 'Age skipped correctly.');
$this->assertEqual($person->job, 'Speaker', 'Job set correctly.');
......@@ -118,7 +118,7 @@ public function testMergeUpdateExplicit() {
public function testMergeUpdateExpression() {
$num_records_before = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$age_before = $this->connection->query('SELECT age FROM {test_people} WHERE job = :job', [':job' => 'Speaker'])->fetchField();
$age_before = $this->connection->query('SELECT [age] FROM {test_people} WHERE [job] = :job', [':job' => 'Speaker'])->fetchField();
// This is a very contrived example, as I have no idea why you'd want to
// change age this way, but that's beside the point.
......@@ -135,7 +135,7 @@ public function testMergeUpdateExpression() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$this->assertEqual($num_records_before, $num_records_after, 'Merge updated properly.');
$person = $this->connection->query('SELECT * FROM {test_people} WHERE job = :job', [':job' => 'Speaker'])->fetch();
$person = $this->connection->query('SELECT * FROM {test_people} WHERE [job] = :job', [':job' => 'Speaker'])->fetch();
$this->assertEqual($person->name, 'Tiffany', 'Name set correctly.');
$this->assertEqual($person->age, $age_before + 4, 'Age updated correctly.');
$this->assertEqual($person->job, 'Speaker', 'Job set correctly.');
......@@ -154,7 +154,7 @@ public function testMergeInsertWithoutUpdate() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$this->assertEqual($num_records_before + 1, $num_records_after, 'Merge inserted properly.');
$person = $this->connection->query('SELECT * FROM {test_people} WHERE job = :job', [':job' => 'Presenter'])->fetch();
$person = $this->connection->query('SELECT * FROM {test_people} WHERE [job] = :job', [':job' => 'Presenter'])->fetch();
$this->assertEqual($person->name, '', 'Name set correctly.');
$this->assertEqual($person->age, 0, 'Age set correctly.');
$this->assertEqual($person->job, 'Presenter', 'Job set correctly.');
......@@ -173,7 +173,7 @@ public function testMergeUpdateWithoutUpdate() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$this->assertEqual($num_records_before, $num_records_after, 'Merge skipped properly.');
$person = $this->connection->query('SELECT * FROM {test_people} WHERE job = :job', [':job' => 'Speaker'])->fetch();
$person = $this->connection->query('SELECT * FROM {test_people} WHERE [job] = :job', [':job' => 'Speaker'])->fetch();
$this->assertEqual($person->name, 'Meredith', 'Name skipped correctly.');
$this->assertEqual($person->age, 30, 'Age skipped correctly.');
$this->assertEqual($person->job, 'Speaker', 'Job skipped correctly.');
......@@ -186,7 +186,7 @@ public function testMergeUpdateWithoutUpdate() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$this->assertEqual($num_records_before, $num_records_after, 'Merge skipped properly.');
$person = $this->connection->query('SELECT * FROM {test_people} WHERE job = :job', [':job' => 'Speaker'])->fetch();
$person = $this->connection->query('SELECT * FROM {test_people} WHERE [job] = :job', [':job' => 'Speaker'])->fetch();
$this->assertEqual($person->name, 'Meredith', 'Name skipped correctly.');
$this->assertEqual($person->age, 30, 'Age skipped correctly.');
$this->assertEqual($person->job, 'Speaker', 'Job skipped correctly.');
......@@ -243,7 +243,7 @@ public function testMergeWithReservedWords() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {select}')->fetchField();
$this->assertEquals($num_records_before + 1, $num_records_after, 'Merge inserted properly.');
$person = $this->connection->query('SELECT * FROM {select} WHERE id = :id', [':id' => 2])->fetch();
$person = $this->connection->query('SELECT * FROM {select} WHERE [id] = :id', [':id' => 2])->fetch();
$this->assertEquals('', $person->update);
$this->assertEquals('2', $person->id);
}
......
......@@ -13,10 +13,10 @@ class QueryTest extends DatabaseTestBase {
* Tests that we can pass an array of values directly in the query.
*/
public function testArraySubstitution() {
$names = $this->connection->query('SELECT name FROM {test} WHERE age IN ( :ages[] ) ORDER BY age', [':ages[]' => [25, 26, 27]])->fetchAll();
$names = $this->connection->query('SELECT [name] FROM {test} WHERE [age] IN ( :ages[] ) ORDER BY [age]', [':ages[]' => [25, 26, 27]])->fetchAll();
$this->assertCount(3, $names, 'Correct number of names returned');
$names = $this->connection->query('SELECT name FROM {test} WHERE age IN ( :ages[] ) ORDER BY age', [':ages[]' => [25]])->fetchAll();
$names = $this->connection->query('SELECT [name] FROM {test} WHERE [age] IN ( :ages[] ) ORDER BY [age]', [':ages[]' => [25]])->fetchAll();
$this->assertCount(1, $names, 'Correct number of names returned');
}
......@@ -25,7 +25,7 @@ public function testArraySubstitution() {
*/
public function testScalarSubstitution() {
try {
$names = $this->connection->query('SELECT name FROM {test} WHERE age IN ( :ages[] ) ORDER BY age', [':ages[]' => 25])->fetchAll();
$names = $this->connection->query('SELECT [name] FROM {test} WHERE [age] IN ( :ages[] ) ORDER BY [age]', [':ages[]' => 25])->fetchAll();
$this->fail('Array placeholder with scalar argument should result in an exception.');
}
catch (\InvalidArgumentException $e) {
......@@ -44,7 +44,7 @@ public function testArrayArgumentsSQLInjection() {
'1' => '',
];
try {
$this->connection->query("SELECT * FROM {test} WHERE name = :name", [':name' => $condition])->fetchObject();
$this->connection->query("SELECT * FROM {test} WHERE [name] = :name", [':name' => $condition])->fetchObject();
$this->fail('SQL injection attempt via array arguments should result in a database exception.');
}
catch (\InvalidArgumentException $e) {
......
......@@ -14,11 +14,11 @@ class RangeQueryTest extends DatabaseTestBase {
*/
public function testRangeQuery() {
// Test if return correct number of rows.
$range_rows = $this->connection->queryRange("SELECT name FROM {test} ORDER BY name", 1, 3)->fetchAll();
$range_rows = $this->connection->queryRange("SELECT [name] FROM {test} ORDER BY [name]", 1, 3)->fetchAll();
$this->assertCount(3, $range_rows, 'Range query work and return correct number of rows.');
// Test if return target data.
$raw_rows = $this->connection->query('SELECT name FROM {test} ORDER BY name')->fetchAll();
$raw_rows = $this->connection->query('SELECT [name] FROM {test} ORDER BY [name]')->fetchAll();
$raw_rows = array_slice($raw_rows, 1, 3);
$this->assertEqual($range_rows, $raw_rows);
}
......
......@@ -30,7 +30,7 @@ public function testRegression_310447() {
'job' => $job,
])->execute();
$from_database = $this->connection->query('SELECT job FROM {test} WHERE job = :job', [':job' => $job])->fetchField();
$from_database = $this->connection->query('SELECT [job] FROM {test} WHERE [job] = :job', [':job' => $job])->fetchField();
$this->assertSame($job, $from_database, 'The database handles UTF-8 characters cleanly.');
}
......
......@@ -166,9 +166,9 @@ public function testSchema() {
$this->checkSchemaComment('Changed column description.', 'test_table', 'test_serial');
$this->assertTrue($this->tryInsert(), 'Insert with a serial succeeded.');
$max1 = $this->connection->query('SELECT MAX(test_serial) FROM {test_table}')->fetchField();
$max1 = $this->connection->query('SELECT MAX([test_serial]) FROM {test_table}')->fetchField();
$this->assertTrue($this->tryInsert(), 'Insert with a serial succeeded.');
$max2 = $this->connection->query('SELECT MAX(test_serial) FROM {test_table}')->fetchField();
$max2 = $this->connection->query('SELECT MAX([test_serial]) FROM {test_table}')->fetchField();
$this->assertTrue($max2 > $max1, 'The serial is monotone.');
$count = $this->connection->query('SELECT COUNT(*) FROM {test_table}')->fetchField();
......@@ -186,9 +186,9 @@ public function testSchema() {
$this->assertSame(['test_serial'], $method->invoke($this->schema, 'test_table'));
$this->assertTrue($this->tryInsert(), 'Insert with a serial succeeded.');
$max1 = $this->connection->query('SELECT MAX(test_serial) FROM {test_table}')->fetchField();
$max1 = $this->connection->query('SELECT MAX([test_serial]) FROM {test_table}')->fetchField();
$this->assertTrue($this->tryInsert(), 'Insert with a serial succeeded.');
$max2 = $this->connection->query('SELECT MAX(test_serial) FROM {test_table}')->fetchField();
$max2 = $this->connection->query('SELECT MAX([test_serial]) FROM {test_table}')->fetchField();
$this->assertTrue($max2 > $max1, 'The serial is monotone.');
$count = $this->connection->query('SELECT COUNT(*) FROM {test_table}')->fetchField();
......
......@@ -446,7 +446,7 @@ public function testRandomOrder() {
// same as the chance that a deck of cards will come out in the same order
// after shuffling it (in other words, nearly impossible).
$number_of_items = 52;
while ($this->connection->query("SELECT MAX(id) FROM {test}")->fetchField() < $number_of_items) {
while ($this->connection->query("SELECT MAX([id]) FROM {test}")->fetchField() < $number_of_items) {
$this->connection->insert('test')->fields(['name' => $this->randomMachineName()])->execute();
}
......
......@@ -155,9 +155,9 @@ public function testTransactionRollBackSupported() {
// Neither of the rows we inserted in the two transaction layers
// should be present in the tables post-rollback.
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'DavidB'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'DavidB'])->fetchField();
$this->assertNotIdentical($saved_age, '24', 'Cannot retrieve DavidB row after commit.');
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'DanielB'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'DanielB'])->fetchField();
$this->assertNotIdentical($saved_age, '19', 'Cannot retrieve DanielB row after commit.');
}
catch (\Exception $e) {
......@@ -204,9 +204,9 @@ public function testCommittedTransaction() {
$this->transactionOuterLayer('A');
// Because we committed, both of the inserted rows should be present.
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'DavidA'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'DavidA'])->fetchField();
$this->assertIdentical($saved_age, '24', 'Can retrieve DavidA row after commit.');
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'DanielA'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'DanielA'])->fetchField();
$this->assertIdentical($saved_age, '19', 'Can retrieve DanielA row after commit.');
}
catch (\Exception $e) {
......@@ -355,7 +355,7 @@ public function assertRowPresent($name, $message = NULL) {
if (!isset($message)) {
$message = new FormattableMarkup('Row %name is present.', ['%name' => $name]);
}
$present = (boolean) $this->connection->query('SELECT 1 FROM {test} WHERE name = :name', [':name' => $name])->fetchField();
$present = (boolean) $this->connection->query('SELECT 1 FROM {test} WHERE [name] = :name', [':name' => $name])->fetchField();
return $this->assertTrue($present, $message);
}
......@@ -371,7 +371,7 @@ public function assertRowAbsent($name, $message = NULL) {
if (!isset($message)) {
$message = new FormattableMarkup('Row %name is absent.', ['%name' => $name]);
}
$present = (boolean) $this->connection->query('SELECT 1 FROM {test} WHERE name = :name', [':name' => $name])->fetchField();
$present = (boolean) $this->connection->query('SELECT 1 FROM {test} WHERE [name] = :name', [':name' => $name])->fetchField();
return $this->assertFalse($present, $message);
}
......@@ -495,7 +495,7 @@ public function testQueryFailureInTransaction() {
// Test a failed query using the query() method.
try {
$this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'David'])->fetchField();
$this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'David'])->fetchField();
$this->fail('Using the query method failed.');
}
catch (\Exception $e) {
......@@ -600,7 +600,7 @@ public function testQueryFailureInTransaction() {
// Commit the transaction.
unset($transaction);
$saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'David'])->fetchField();
$saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'David'])->fetchField();
$this->assertEqual('24', $saved_age);
}
......
......@@ -24,7 +24,7 @@ public function testOrConditionUpdate() {
$num_updated = $update->execute();
$this->assertIdentical($num_updated, 2, 'Updated 2 records.');
$num_matches = $this->connection->query('SELECT COUNT(*) FROM {test} WHERE job = :job', [':job' => 'Musician'])->fetchField();
$num_matches = $this->connection->query('SELECT COUNT(*) FROM {test} WHERE [job] = :job', [':job' => 'Musician'])->fetchField();
$this->assertIdentical($num_matches, '2', 'Updated fields successfully.');
}
......@@ -38,7 +38,7 @@ public function testInConditionUpdate() {
->execute();
$this->assertIdentical($num_updated, 2, 'Updated 2 records.');
$num_matches = $this->connection->query('SELECT COUNT(*) FROM {test} WHERE job = :job', [':job' => 'Musician'])->fetchField();