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() { ...@@ -37,7 +37,7 @@ public function testConcatLiterals() {
*/ */
public function testConcatFields() { public function testConcatFields() {
$result = $this->connection->query( $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 ', ':a1' => 'The age of ',
':a2' => ' is ', ':a2' => ' is ',
':a3' => '.', ':a3' => '.',
...@@ -64,7 +64,7 @@ public function testConcatWsLiterals() { ...@@ -64,7 +64,7 @@ public function testConcatWsLiterals() {
* Tests string concatenation with separator, with field values. * Tests string concatenation with separator, with field values.
*/ */
public function testConcatWsFields() { 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', ':a1' => 'name',
':a2' => 'age', ':a2' => 'age',
':age' => 25, ':age' => 25,
...@@ -160,7 +160,7 @@ public function testAllowSquareBrackets() { ...@@ -160,7 +160,7 @@ public function testAllowSquareBrackets() {
$this->assertIdentical('[square]', $result->fetchField()); $this->assertIdentical('[square]', $result->fetchField());
// Test that allow_square_brackets has no effect on arguments. // 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()); $this->assertIdentical('[square]', $result->fetchField());
$result = $this->connection->query("select name from {test} where name = :value", [':value' => '[square]'], ['allow_square_brackets' => TRUE]); $result = $this->connection->query("select name from {test} where name = :value", [':value' => '[square]'], ['allow_square_brackets' => TRUE]);
$this->assertIdentical('[square]', $result->fetchField()); $this->assertIdentical('[square]', $result->fetchField());
......
...@@ -26,7 +26,7 @@ public function testCaseSensitiveInsert() { ...@@ -26,7 +26,7 @@ public function testCaseSensitiveInsert() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField(); $num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField();
$this->assertSame($num_records_before + 1, (int) $num_records_after, 'Record inserts correctly.'); $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.'); $this->assertIdentical($saved_age, '2', 'Can retrieve after inserting.');
} }
......
...@@ -22,7 +22,7 @@ class DeleteTruncateTest extends DatabaseTestBase { ...@@ -22,7 +22,7 @@ class DeleteTruncateTest extends DatabaseTestBase {
*/ */
public function testSubselectDelete() { public function testSubselectDelete() {
$num_records_before = $this->connection->query('SELECT COUNT(*) FROM {test_task}')->fetchField(); $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') $subquery = $this->connection->select('test', 't')
->fields('t', ['id']) ->fields('t', ['id'])
......
...@@ -20,7 +20,7 @@ class FetchTest extends DatabaseTestBase { ...@@ -20,7 +20,7 @@ class FetchTest extends DatabaseTestBase {
*/ */
public function testQueryFetchDefault() { public function testQueryFetchDefault() {
$records = []; $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); $this->assertInstanceOf(StatementInterface::class, $result);
foreach ($result as $record) { foreach ($result as $record) {
$records[] = $record; $records[] = $record;
...@@ -36,7 +36,7 @@ public function testQueryFetchDefault() { ...@@ -36,7 +36,7 @@ public function testQueryFetchDefault() {
*/ */
public function testQueryFetchObject() { public function testQueryFetchObject() {
$records = []; $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) { foreach ($result as $record) {
$records[] = $record; $records[] = $record;
$this->assertIsObject($record); $this->assertIsObject($record);
...@@ -51,7 +51,7 @@ public function testQueryFetchObject() { ...@@ -51,7 +51,7 @@ public function testQueryFetchObject() {
*/ */
public function testQueryFetchArray() { public function testQueryFetchArray() {
$records = []; $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) { foreach ($result as $record) {
$records[] = $record; $records[] = $record;
$this->assertIsArray($record); $this->assertIsArray($record);
...@@ -69,7 +69,7 @@ public function testQueryFetchArray() { ...@@ -69,7 +69,7 @@ public function testQueryFetchArray() {
*/ */
public function testQueryFetchClass() { public function testQueryFetchClass() {
$records = []; $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) { foreach ($result as $record) {
$records[] = $record; $records[] = $record;
$this->assertInstanceOf(FakeRecord::class, $record); $this->assertInstanceOf(FakeRecord::class, $record);
...@@ -87,7 +87,7 @@ public function testQueryFetchClass() { ...@@ -87,7 +87,7 @@ public function testQueryFetchClass() {
*/ */
public function testQueryFetchObjectClass() { public function testQueryFetchObjectClass() {
$records = 0; $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)) { while ($result = $query->fetchObject(FakeRecord::class)) {
$records += 1; $records += 1;
$this->assertInstanceOf(FakeRecord::class, $result); $this->assertInstanceOf(FakeRecord::class, $result);
...@@ -104,7 +104,7 @@ public function testQueryFetchObjectClass() { ...@@ -104,7 +104,7 @@ public function testQueryFetchObjectClass() {
*/ */
public function testQueryFetchClasstype() { public function testQueryFetchClasstype() {
$records = []; $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) { foreach ($result as $record) {
$records[] = $record; $records[] = $record;
$this->assertInstanceOf(FakeRecord::class, $record); $this->assertInstanceOf(FakeRecord::class, $record);
...@@ -121,7 +121,7 @@ public function testQueryFetchClasstype() { ...@@ -121,7 +121,7 @@ public function testQueryFetchClasstype() {
*/ */
public function testQueryFetchNum() { public function testQueryFetchNum() {
$records = []; $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) { foreach ($result as $record) {
$records[] = $record; $records[] = $record;
$this->assertIsArray($record); $this->assertIsArray($record);
...@@ -137,7 +137,7 @@ public function testQueryFetchNum() { ...@@ -137,7 +137,7 @@ public function testQueryFetchNum() {
*/ */
public function testQueryFetchBoth() { public function testQueryFetchBoth() {
$records = []; $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) { foreach ($result as $record) {
$records[] = $record; $records[] = $record;
$this->assertIsArray($record); $this->assertIsArray($record);
...@@ -167,11 +167,11 @@ public function testQueryFetchAllColumn() { ...@@ -167,11 +167,11 @@ public function testQueryFetchAllColumn() {
* Confirms that we can fetch an entire column of a result set at once. * Confirms that we can fetch an entire column of a result set at once.
*/ */
public function testQueryFetchCol() { 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(); $column = $result->fetchCol();
$this->assertCount(3, $column, 'fetchCol() returns the right number of records.'); $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; $i = 0;
foreach ($result as $record) { foreach ($result as $record) {
$this->assertIdentical($record->name, $column[$i++], 'Column matches direct access.'); $this->assertIdentical($record->name, $column[$i++], 'Column matches direct access.');
...@@ -182,7 +182,7 @@ public function testQueryFetchCol() { ...@@ -182,7 +182,7 @@ public function testQueryFetchCol() {
* Tests that rowCount() throws exception on SELECT query. * Tests that rowCount() throws exception on SELECT query.
*/ */
public function testRowCount() { public function testRowCount() {
$result = $this->connection->query('SELECT name FROM {test}'); $result = $this->connection->query('SELECT [name] FROM {test}');
try { try {
$result->rowCount(); $result->rowCount();
$exception = FALSE; $exception = FALSE;
......
...@@ -20,7 +20,7 @@ public function testDefaultInsert() { ...@@ -20,7 +20,7 @@ public function testDefaultInsert() {
$schema = drupal_get_module_schema('database_test', 'test'); $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.'); $this->assertEqual($job, $schema['fields']['job']['default'], 'Default field value is set.');
} }
...@@ -54,7 +54,7 @@ public function testDefaultInsertWithFields() { ...@@ -54,7 +54,7 @@ public function testDefaultInsertWithFields() {
$schema = drupal_get_module_schema('database_test', 'test'); $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.'); $this->assertEqual($job, $schema['fields']['job']['default'], 'Default field value is set.');
} }
......
...@@ -20,7 +20,7 @@ public function testInsertOneBlob() { ...@@ -20,7 +20,7 @@ public function testInsertOneBlob() {
$id = $this->connection->insert('test_one_blob') $id = $this->connection->insert('test_one_blob')
->fields(['blob1' => $data]) ->fields(['blob1' => $data])
->execute(); ->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)])); $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() { ...@@ -34,7 +34,7 @@ public function testInsertMultipleBlob() {
'blob2' => 'a test', 'blob2' => 'a test',
]) ])
->execute(); ->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.'); $this->assertTrue($r['blob1'] === 'This is' && $r['blob2'] === 'a test', 'Can insert multiple blobs per row.');
} }
......
...@@ -27,7 +27,7 @@ public function testSimpleInsert() { ...@@ -27,7 +27,7 @@ public function testSimpleInsert() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField(); $num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField();
$this->assertSame($num_records_before + 1, (int) $num_records_after, 'Record inserts correctly.'); $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.'); $this->assertIdentical($saved_age, '29', 'Can retrieve after inserting.');
} }
...@@ -62,11 +62,11 @@ public function testMultiInsert() { ...@@ -62,11 +62,11 @@ public function testMultiInsert() {
$num_records_after = (int) $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField(); $num_records_after = (int) $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField();
$this->assertSame($num_records_before + 3, $num_records_after, 'Record inserts correctly.'); $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.'); $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.'); $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.'); $this->assertIdentical($saved_age, '32', 'Can retrieve after inserting.');
} }
...@@ -105,11 +105,11 @@ public function testRepeatedInsert() { ...@@ -105,11 +105,11 @@ public function testRepeatedInsert() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField(); $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.'); $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.'); $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.'); $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.'); $this->assertIdentical($saved_age, '32', 'Can retrieve after inserting.');
} }
...@@ -125,11 +125,11 @@ public function testInsertFieldOnlyDefinition() { ...@@ -125,11 +125,11 @@ public function testInsertFieldOnlyDefinition() {
->values(['Curly', '31']) ->values(['Curly', '31'])
->values(['Moe', '32']) ->values(['Moe', '32'])
->execute(); ->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.'); $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.'); $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.'); $this->assertIdentical($saved_age, '32', 'Can retrieve after inserting.');
} }
...@@ -169,7 +169,7 @@ public function testInsertSelectFields() { ...@@ -169,7 +169,7 @@ public function testInsertSelectFields() {
->from($query) ->from($query)
->execute(); ->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.'); $this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
} }
...@@ -190,7 +190,7 @@ public function testInsertSelectAll() { ...@@ -190,7 +190,7 @@ public function testInsertSelectAll() {
->from($query) ->from($query)
->execute(); ->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.'); $this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
} }
...@@ -204,7 +204,7 @@ public function testSpecialColumnInsert() { ...@@ -204,7 +204,7 @@ public function testSpecialColumnInsert() {
'update' => 'Update value 2', 'update' => 'Update value 2',
]) ])
->execute(); ->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); $this->assertEquals('Update value 2', $saved_value);
} }
......
...@@ -33,7 +33,7 @@ public function testMaxAllowedPacketQueryTruncating() { ...@@ -33,7 +33,7 @@ public function testMaxAllowedPacketQueryTruncating() {
$long_name = str_repeat('a', $max_allowed_packet + 1); $long_name = str_repeat('a', $max_allowed_packet + 1);
try { 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'"); $this->fail("An exception should be thrown for queries larger than 'max_allowed_packet'");
} }
catch (DatabaseException $e) { catch (DatabaseException $e) {
......
...@@ -20,8 +20,8 @@ class LoggingTest extends DatabaseTestBase { ...@@ -20,8 +20,8 @@ class LoggingTest extends DatabaseTestBase {
public function testEnableLogging() { public function testEnableLogging() {
Database::startLog('testing'); Database::startLog('testing');
$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();
$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();
// Trigger a call that does not have file in the backtrace. // 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(); call_user_func_array([Database::getConnection(), 'query'], ['SELECT age FROM {test} WHERE name = :name', [':name' => 'Ringo']])->fetchCol();
...@@ -41,11 +41,11 @@ public function testEnableLogging() { ...@@ -41,11 +41,11 @@ public function testEnableLogging() {
public function testEnableMultiLogging() { public function testEnableMultiLogging() {
Database::startLog('testing1'); 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'); 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'); $queries1 = Database::getLog('testing1');
$queries2 = Database::getLog('testing2'); $queries2 = Database::getLog('testing2');
...@@ -65,9 +65,9 @@ public function testEnableTargetLogging() { ...@@ -65,9 +65,9 @@ public function testEnableTargetLogging() {
Database::startLog('testing1'); 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'); $queries1 = Database::getLog('testing1');
...@@ -86,14 +86,14 @@ public function testEnableTargetLogging() { ...@@ -86,14 +86,14 @@ public function testEnableTargetLogging() {
public function testEnableTargetLoggingNoTarget() { public function testEnableTargetLoggingNoTarget() {
Database::startLog('testing1'); 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. // 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 // 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 // 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 // unit tests, so we use a target here that we know with absolute certainty
// does not exist. // 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'); $queries1 = Database::getLog('testing1');
...@@ -114,11 +114,11 @@ public function testEnableMultiConnectionLogging() { ...@@ -114,11 +114,11 @@ public function testEnableMultiConnectionLogging() {
Database::startLog('testing1'); Database::startLog('testing1');
Database::startLog('testing1', 'test2'); 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'); $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); Database::setActiveConnection($old_key);
......
...@@ -31,7 +31,7 @@ public function testMergeInsert() { ...@@ -31,7 +31,7 @@ public function testMergeInsert() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField(); $num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$this->assertEqual($num_records_before + 1, $num_records_after, 'Merge inserted properly.'); $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->name, 'Tiffany', 'Name set correctly.');
$this->assertEqual($person->age, 31, 'Age set correctly.'); $this->assertEqual($person->age, 31, 'Age set correctly.');
$this->assertEqual($person->job, 'Presenter', 'Job set correctly.'); $this->assertEqual($person->job, 'Presenter', 'Job set correctly.');
...@@ -56,7 +56,7 @@ public function testMergeUpdate() { ...@@ -56,7 +56,7 @@ public function testMergeUpdate() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField(); $num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$this->assertEqual($num_records_before, $num_records_after, 'Merge updated properly.'); $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->name, 'Tiffany', 'Name set correctly.');
$this->assertEqual($person->age, 31, 'Age set correctly.'); $this->assertEqual($person->age, 31, 'Age set correctly.');
$this->assertEqual($person->job, 'Speaker', 'Job set correctly.'); $this->assertEqual($person->job, 'Speaker', 'Job set correctly.');
...@@ -80,7 +80,7 @@ public function testMergeUpdateExcept() { ...@@ -80,7 +80,7 @@ public function testMergeUpdateExcept() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField(); $num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$this->assertEqual($num_records_before, $num_records_after, 'Merge updated properly.'); $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->name, 'Tiffany', 'Name set correctly.');
$this->assertEqual($person->age, 30, 'Age skipped correctly.'); $this->assertEqual($person->age, 30, 'Age skipped correctly.');
$this->assertEqual($person->job, 'Speaker', 'Job set correctly.'); $this->assertEqual($person->job, 'Speaker', 'Job set correctly.');
...@@ -106,7 +106,7 @@ public function testMergeUpdateExplicit() { ...@@ -106,7 +106,7 @@ public function testMergeUpdateExplicit() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField(); $num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$this->assertEqual($num_records_before, $num_records_after, 'Merge updated properly.'); $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->name, 'Joe', 'Name set correctly.');
$this->assertEqual($person->age, 30, 'Age skipped correctly.'); $this->assertEqual($person->age, 30, 'Age skipped correctly.');
$this->assertEqual($person->job, 'Speaker', 'Job set correctly.'); $this->assertEqual($person->job, 'Speaker', 'Job set correctly.');
...@@ -118,7 +118,7 @@ public function testMergeUpdateExplicit() { ...@@ -118,7 +118,7 @@ public function testMergeUpdateExplicit() {
public function testMergeUpdateExpression() { public function testMergeUpdateExpression() {
$num_records_before = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField(); $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 // 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. // change age this way, but that's beside the point.
...@@ -135,7 +135,7 @@ public function testMergeUpdateExpression() { ...@@ -135,7 +135,7 @@ public function testMergeUpdateExpression() {
$num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField(); $num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$this->assertEqual($num_records_before, $num_records_after, 'Merge updated properly.'); $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->name, 'Tiffany', 'Name set correctly.');