Skip to content

Commit 76314ee

Browse files
authored
Refactor test for ambiguous ORDER BY column resolution
1 parent 3abb2b7 commit 76314ee

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

tests/WP_SQLite_Driver_Translation_Tests.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,21 @@ public function testSelect(): void {
9494
}
9595

9696
/**
97-
* Test MySQL-compatible ORDER BY name resolution with unqualified columns.
98-
* When a column name appears unqualified in ORDER BY and is unique in the SELECT list,
99-
* it should resolve to the SELECT expression (or alias) instead of causing an ambiguity error.
100-
*
101-
* This demonstrates the core issue: In MySQL this works, while SQLite would normally error on ambiguity.
102-
* We rewrite unqualified ORDER BY terms to the SELECT expression recorded for that output name.
97+
* Test for Query Error: ambiguous column name in ORDER BY clause
98+
* @see https://github.com/wordpress/sqlite-database-integration/issues/228
10399
*/
104100
public function testSelectOrderByAmbiguousColumnResolution(): void {
105-
// Test with explicit aliases - should resolve to alias name
101+
// This query works in MySQL, but in SQLite `ORDER BY name` is ambiguous. Let's confirm
102+
// the SQLite driver can handle it.
106103
$this->assertQuery(
107-
'SELECT `t1`.`name` AS `t1_name` FROM `t1` JOIN `t2` ON `t2`.`t1_id` = `t1`.`id` ORDER BY `t1_name`',
108-
'SELECT t1.name AS t1_name FROM t1 JOIN t2 ON t2.t1_id = t1.id ORDER BY `t1_name`'
104+
'SELECT `t1`.`name` FROM `t1` JOIN `t2` ON `t2`.`t1_id` = `t1`.`id` ORDER BY `t1`.`name`',
105+
'SELECT t1.name FROM t1 JOIN t2 ON t2.t1_id = t1.id ORDER BY name'
109106
);
110107

111-
// This demonstrates the core issue: In MySQL this works, in SQLite it errors
112-
// MySQL resolves the unqualified 'name' in ORDER BY to the unique 'name' in SELECT list
108+
// Test with explicit aliases - should resolve to alias name
113109
$this->assertQuery(
114-
'SELECT `t1`.`name` FROM `t1` JOIN `t2` ON `t2`.`t1_id` = `t1`.`id` ORDER BY `t1`.`name`',
115-
'SELECT t1.name FROM t1 JOIN t2 ON t2.t1_id = t1.id ORDER BY name'
110+
'SELECT `t1`.`name` AS `t1_name` FROM `t1` JOIN `t2` ON `t2`.`t1_id` = `t1`.`id` ORDER BY `t1_name`',
111+
'SELECT t1.name AS t1_name FROM t1 JOIN t2 ON t2.t1_id = t1.id ORDER BY `t1_name`'
116112
);
117113

118114
// It should also work with multiple ambiguous columns.

0 commit comments

Comments
 (0)