symphonists / uniondatasource

A union datasources allows you to combine multiple datasources to output a single datasource for the primary purpose of a unified pagination.
13 stars 11 forks source link

Fatal error in uniondatasource "The used SELECT statements have a different number of columns" #31

Open rhelms opened 11 years ago

rhelms commented 11 years ago

Hi. I'm supporting an older release of Symphony CMS (2.2.5), using the uniondatasource (0.6).

I'm getting a Symphony Fatal Error, due to a different number of columns.

SELECT SQL_CACHE `e`.id as id, `e`.section_id, e.`author_id`, UNIX_TIMESTAMP(e.`creation_date`) AS `creation_date` 
FROM `sym_entries` AS `e` 
LEFT JOIN `sym_entries_data_3` AS t3_1 ON (e.id = t3_1.entry_id) 
WHERE `e`.`section_id` = 1 AND ( t3_1.value IN ('yes') OR t3_1.value IS NULL ) 
UNION ALL 
SELECT `e`.id as id, `e`.section_id, e.`author_id`, UNIX_TIMESTAMP(e.`creation_date`) AS `creation_date` 
FROM `sym_entries` AS `e` 
WHERE `e`.`section_id` = 7 
UNION ALL 
SELECT `e`.id as id, `e`.section_id, e.`author_id`, UNIX_TIMESTAMP(e.`creation_date`) AS `creation_date`, `ed`.value 
FROM `sym_entries` AS `e` 
LEFT JOIN `sym_entries_data_25` AS t25_1 ON (e.id = t25_1.entry_id) 
LEFT OUTER JOIN `sym_entries_data_50` AS `ed` ON (`e`.`id` = `ed`.`entry_id`) 
WHERE `e`.`section_id` = 6 AND ( t25_1.value IN ('yes') OR t25_1.value IS NULL ) 
ORDER BY id desc LIMIT 0, 20

The usage for three data sources, where two of them order by 'system:id', and the third by a field called 'order'.

I think the error occurs because the third datasource results in $sort_field being populated, and the extra field appended.

It would seem that $sort_field should always be calculated, regardless of the sort field, or a nonce use for that extra field, in the case where $sort_field is not populated.

This might impact the latest release of the extension, as well.

brendo commented 11 years ago

Thanks for the report, I'll take a look this evening and see if it still affects the current release and what we can do for your legacy needs too.