@@ -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