Page MenuHomePhabricator

Cargo query using HOLDS and a function isn't parsed correctly
Open, Needs TriagePublic

Description

I'm currently using Mediawiki 1.33, and just upgraded to Cargo 2.7

I have the following cargo query in a template:

{{#cargo_query: tables=TradeSummary
    |fields=CONCAT(description, IF(LENGTH(category)>0, CONCAT('[[',category,']]'),''))
    |where=code HOLDS CONCAT('{{{1}}}')
  |default=Missing code ''{{{1}}}''|format=list|delimiter= |columns=1}}

And I get the following error on the page:

A database query error has occurred. Did you forget to run your application's database schema updater after upgrading?

Query: SELECT CONCAT(description, IF(LENGTH(category)>0, CONCAT('',category,''),)) FROM `mw_cargo__TradeSummary` WHERE `mw_cargo__TradeSummary`.`_ID` IN (SELECT _rowID FROM `mw_cargo__TradeSummary__code` WHERE _value = CONCAT() '{{{1}}}') ORDER BY CONCAT(description, IF(LENGTH(category)>0, CONCAT('',category,''),)) LIMIT 100 Function: CargoSQLQuery::run Error: 1582 Incorrect parameter count in the call to native function 'CONCAT' (localhost)

The thing I would highlight is the sub-select

SELECT _rowID FROM `mw_cargo__TradeSummary__code` WHERE _value = CONCAT() '{{{1}}}')

What I expect is the query runs without problems, like it did on previous version. This is a regression.

WORKAROUND: The use of CONCAT({{{1}}}) is a workaround from an earlier version of Cargo which couldn't handle the wiki parameters if they were blank or unset.

The workaround for this is to remove the CONCAT() and make sure the parameter has a default value.

{{#cargo_query: tables=TradeSummary
    |fields=CONCAT(description, IF(LENGTH(category)>0, CONCAT('[[',category,']]'),' '))
    |where=code HOLDS '{{{1|A}}}'
  |default=Missing code ''{{{1}}}''|format=list|delimiter= |columns=1}}

I can workaround my problem, but the error in the parser to create the sub-select when using a function still remains.