Skip to content

Commit

Permalink
N°2589 - Infinite loops when logging with a Contact having a non empt…
Browse files Browse the repository at this point in the history
…y TagSet field

Add ListParameters to DBSearch for nested queries
  • Loading branch information
eespie committed Jun 24, 2020
1 parent 311aeb0 commit 94f9b16
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/dbobjectsearch.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2097,4 +2097,9 @@ static public function GetPolymorphicExpression($sClass, $sAttCode)
}
return $oExpression;
}

public function ListParameters()
{
return $this->GetCriteria()->ListParameters();
}
}
2 changes: 2 additions & 0 deletions core/dbsearch.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,8 @@ public abstract function GetSQLQueryStructure(
*/
public abstract function GetCriteria();

public abstract function ListParameters();

/**
* Shortcut to add efficient IN condition
*
Expand Down
10 changes: 10 additions & 0 deletions core/dbunionsearch.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,4 +728,14 @@ public function AddConditionForInOperatorUsingParam($sFilterCode, $aValues, $bPo
$oSearch->AddConditionExpression($oInCondition);
}
}

public function ListParameters()
{
$aParameters = array();
foreach ($this->aSearches as $oSearch)
{
$aParameters = array_merge($aParameters, $oSearch->ListParameters());
}
return $aParameters;
}
}
2 changes: 1 addition & 1 deletion core/oql/expression.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2624,7 +2624,7 @@ public function ListConstantFields()

public function ListParameters()
{
return array();
return $this->m_oValue->ListParameters();
}

public function RenameParam($sOldName, $sNewName)
Expand Down
47 changes: 47 additions & 0 deletions test/core/ExpressionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Combodo\iTop\Test\UnitTest\Core;

use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use Expression;

class ExpressionTest extends ItopDataTestCase
{
const USE_TRANSACTION = false;

/**
* @dataProvider ListParametersProvider
* @param $sOQL
* @param $aExpected
*
* @throws \OQLException
*/
public function testListParameters($sOQL, $aExpected)
{
$oExpression = Expression::FromOQL($sOQL);
$aParameters = $oExpression->ListParameters();
$aResult = array();
foreach ($aParameters as $oVarExpr)
{
/** var \VariableExpression $oVarExpr */
$aResult[] = $oVarExpr->RenderExpression();
}
$this->debug($aResult);
$this->assertSame(array_diff($aExpected, $aResult), array_diff($aResult, $aExpected));
}

public function ListParametersProvider()
{
return array(
array('1', array()),
array(':id = 2', array(':id')),
array('expiration_date < DATE_SUB(NOW(), INTERVAL :expiration_days DAY)', array(':expiration_days')),
array('id IN (SELECT Organization WHERE :id = 2)', array(':id')),
array('id IN (:id, 2)', array(':id')),
array("B.name LIKE :name", array(':name')),
array("name REGEXP :regexp", array(':regexp')),
array(" t.agent_id = :current_contact_id", array(':current_contact_id')),
array("INET_ATON(dev.managementip) > INET_ATON('10.22.32.224') AND INET_ATON(:ip) < INET_ATON('10.22.32.255')", array(':ip')),
);
}
}
1 change: 1 addition & 0 deletions test/core/OQLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ public function testMakeSelectQuery($sOQL, $sExpectedExceptionClass = '')
}
catch (Exception $e)
{
$this->debug($e->getMessage());
$sExceptionClass = get_class($e);
}

Expand Down

0 comments on commit 94f9b16

Please sign in to comment.