Ticket #425 (reopened defect)

Opened 3 years ago

Last modified 9 months ago

Bug in BasePeer::createSelectSql

Reported by: serg@… Owned by: hans
Priority: normal Milestone: To be scheduled
Component: Runtime (PHP5) Version: 1.2.1
Severity: critical Keywords:
Cc:

Description

Invalid sql query generated if in select column used more then one function. For example:

$c = new Criteria(); $c->setDistinct();
$c->addSelectColumn( sprintf( "SUBSTRING_INDEX(SUBSTRING_INDEX((%s),'-',$pos),'-',-1) AS col", self::PREFIX ) );
$rs = self::doSelectRS( $c );

produced wrong statement and throw exception:

SELECT DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX((fe_dip_project_type.PREFIX),'-',1),'-',-1) AS col 
FROM SUBSTRING_INDEX((fe_dip_project_type, fe_dip_project_type 
WHERE fe_dip_project_type.IS_DELETED=0 

to fix this replace strpos function with strrpos function in /pear/symfony/vendor/propel/util/BasePeer.php on line 579

...
577 $selectClause[] = $columnName; // the full column name: e.g. MAX(books.price)
578
579 $parenPos = strrpos($columnName, '(');
580 $dotPos = strpos($columnName, '.', ($parenPos !== false) ? $parenPos : 0);
...

after this fix all work fine:

SELECT DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX((fe_dip_project_type.PREFIX),'-',1),'-',-1) AS col 
FROM fe_dip_project_type 
WHERE fe_dip_project_type.IS_DELETED=0

Change History

comment:1 Changed 3 years ago by hans

  • Status changed from new to assigned
  • Milestone set to 1.3

comment:2 Changed 3 years ago by hans

(In [818]) Refs #425 - Added unit test for nested functions.

comment:3 Changed 3 years ago by hans

(In [818]) Refs #425 - Added unit test for nested functions.

comment:4 Changed 3 years ago by hans

  • Status changed from assigned to closed
  • Resolution set to wontfix

In r818 I added a unit test that does pass (on postgres) with current BasePeer code, so this fix will actually not work for the various situations in which there can be nested functions. Unfortunately, there's not a good solution for this; there's no way to know exactly what the column is vs. other text within the clause. This would be a case for using custom SQL instead of Criteria.

So, resolving "wontfix", though "cantfix" is more accurate.

comment:5 Changed 10 months ago by francois

  • Status changed from closed to reopened
  • Resolution wontfix deleted
  • Milestone 1.3 deleted

r916 actually applies the strrpos modification. But the BasePeerTest::testMultipleFunctionInCriteria() test does not pass with Postgre as of Propel 1.5. Somehow a regression occurred, that should be looked for.

comment:6 Changed 9 months ago by matthew

  • Milestone set to To be scheduled

Per François, tickets should be in 'To be scheduled'.

Note: See TracTickets for help on using tickets.