Skip to content

Commit

Permalink
Bug fix for numeric field searching.
Browse files Browse the repository at this point in the history
  • Loading branch information
msyk committed Sep 9, 2023
1 parent 87ac2e1 commit 07e9427
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The demo with the latest version of INTER-Mediator is here:
- https://demo.inter-mediator.com/INTER-Mediator/samples/

This demo page works on INTER-Mediator Ver.5.x (Milestone version).
INTER-Mediator Ver.6 was quite different from previous versions. So we have called the Stable version for the final release of Ver.5.
INTER-Mediator Ver.6 was quite different from previous versions. So we have called the Milestone version for the final release of Ver.5.
- https://demo.inter-mediator.com/INTER-Mediator_milestone/Samples/

## Documentation
Expand Down
2 changes: 2 additions & 0 deletions dist-docs/change_log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Ver.12 (In Development)
- (Ver.9) The setUpdatedRecord method in database classes renamed to setDataToUpdatedRecord. For the compatibility,
calling the setUpdateRecord method more than one parameter redirect to setDataToUpdatedRecord method.
The setUpdatedRecord with one parameter works as the setter of updatedRecord property.
- [BUG FIX] The data-im="_@condition:..." way with numeric field and the "match" operator didn't expand the condition
clause with '%term%' value. As far as PostgreSQL goes, the casting to text is automatically applied it.

Ver.11 (July 27, 2023)
- Generic exporting class prepared as DB\Export.php.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,18 @@ public function testAddingLCCondtions11()
'((("num0" = \'100\' OR "num0" < \'300\') AND ("num1" = 100 OR "num1" < 300))'
. ' AND ((("f1" = \'valueA\' OR "f2" = \'valueA\') OR ("f1" = \'extra\' OR "f2" = \'extra\')) OR ("f1" < \'valueB\' OR "f2" < \'valueB\') OR ("f3" = \'valueC\')))');
}
public function testAddingLCCondtions12()
{
$this->checkConditions(null,
[
['field' => 'num0', 'operator' => '=', 'value' => 100],
['field' => 'num0', 'operator' => '<', 'value' => 300],
['field' => '__operation__', 'operator' => 'ex',],
['field' => 'num1', 'operator' => '=', 'value' => 100],
['field' => 'num1', 'operator' => '<', 'value' => 300],
['field' => '__operation__', 'operator' => 'block/false/false/false'],
['field' => 'num1', 'operator' => '*match*', 'value' => '999'],
],
$this->lcConditionLike);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,6 @@ function dbProxySetupForCondition(?array $queryArray): void
protected string $sqlSETClause3 = "(`num1`,`num2`,`date1`,`date2`,`time1`,`time2`,`dt1`,`dt2`,`vc1`,`vc2`,`text1`,`text2`) "
. "VALUES(0,0,'','','','','','','','','','')";

protected string $lcConditionLike = '((("num0" = \'100\' OR "num0" < \'300\') AND ("num1" = 100 OR "num1" < 300))'
. ' AND (("num1" LIKE \'%999%\')))';
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,7 @@ function dbProxySetupForCondition(?array $queryArray):void
protected string $sqlSETClause3 = "(\"num1\",\"num2\",\"date1\",\"date2\",\"time1\",\"time2\",\"dt1\",\"dt2\",\"vc1\",\"vc2\",\"text1\",\"text2\") "
. "VALUES(0,0,'','','','','','','','','','')";

protected string $lcConditionLike = '((("num0" = \'100\' OR "num0" < \'300\') AND ("num1" = 100 OR "num1" < 300))'
. ' AND ((CAST("num1" AS TEXT) LIKE \'%999%\')))';

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,4 @@ function dbProxySetupForAuthAccess(string $contextName, int $maxRecord, $subCont
$resultInit = $this->db_proxy->initialize($this->dataSource, $this->options, $this->dbSpec, 2, $contextName);
$this->assertNotFalse($resultInit, 'Proxy::initialize must return true.');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,7 @@ public function testCreateRecord2()
protected string $sqlSETClause3 = "(\"num1\",\"num2\",\"date1\",\"date2\",\"time1\",\"time2\",\"dt1\",\"dt2\",\"vc1\",\"vc2\",\"text1\",\"text2\") "
. "VALUES(0,0,'','','','','','','','','','')";

protected string $lcConditionLike = '((("num0" = \'100\' OR "num0" < \'300\') AND ("num1" = 100 OR "num1" < 300))'
. ' AND (("num1" LIKE \'%999%\')))';

}
2 changes: 1 addition & 1 deletion src/js/Adapter_DBServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ const INTERMediator_DBAdapter = {
params += '&condition' + extCount + 'field=__operation__'
params += '&condition' + extCount + 'operator=block/' + (INTERMediator.lcConditionsOP1AND ? 'T' : 'F')
+ '/' + (INTERMediator.lcConditionsOP2AND ? 'T' : 'F')
+ '/' + ((INTERMediator.lcConditionsOP3AND && INTERMediator.lcConditionsOP3AND.toUpperCase() === 'AND')
+ '/' + ((INTERMediator.lcConditionsOP3AND && INTERMediator.lcConditionsOP3AND === 'AND')
? 'AND' : (INTERMediator.lcConditionsOP3AND ? 'T' : 'F'))
extCount++
isFirstItem = false
Expand Down
10 changes: 10 additions & 0 deletions src/php/DB/Support/DB_PDO_Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,4 +545,14 @@ public function lastInsertIdAlt(string $seqObject, string $tableName): ?string
}
return null;
}

/**
* @param $field
* @param $value
* @return string
*/
public function getSQLNumericToLikeOpe($field, $value): string
{
return "{$field} LIKE {$value}";
}
}
10 changes: 10 additions & 0 deletions src/php/DB/Support/DB_PDO_PostgreSQL_Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,14 @@ public function authSupportCanMigrateSHA256Hash(string $userTable, string $hashT
}
return $returnValue;
}

/**
* @param $field
* @param $value
* @return string
*/
public function getSQLNumericToLikeOpe($field, $value): string
{
return "CAST({$field} AS TEXT) LIKE {$value}";
}
}
26 changes: 20 additions & 6 deletions src/php/DB/Support/DB_PDO_SQLSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,24 @@ private function generateWhereClause(array $conditions, string $primaryKey, arra
if ($isINOperator) {
$escapedValue = $this->arrayToItemizedString($condition['value'], $isNumeric);
}
$queryClauseArray[$chunkCount][]
= (!$isNumeric || $isINOperator)
? "{$escapedField} {$condition['operator']} {$escapedValue}"
: ("{$escapedField} {$condition['operator']} " . floatval($condition['value']));
if ($isNumeric) {
if ($isINOperator) {
$queryClauseArray[$chunkCount][]
= "{$escapedField} {$condition['operator']} {$escapedValue}";
} else if (strtolower(trim($condition['operator'])) == "like") {
$queryClauseArray[$chunkCount][]
= $this->handler->getSQLNumericToLikeOpe($escapedField, $escapedValue);
} else {
$queryClauseArray[$chunkCount][]
= ("{$escapedField} {$condition['operator']} " . floatval($condition['value']));
}
} else {
$queryClauseArray[$chunkCount][] = "{$escapedField} {$condition['operator']} {$escapedValue}";
}
// $queryClauseArray[$chunkCount][]
// = (!$isNumeric || $isINOperator || $isLIKEOperator)
// ? "{$escapedField} {$condition['operator']} {$escapedValue}"
// : ("{$escapedField} {$condition['operator']} " . floatval($condition['value']));
} else {
$queryClauseArray[$chunkCount][] = "{$escapedField} {$condition['operator']}";
}
Expand All @@ -178,7 +192,7 @@ private function generateWhereClause(array $conditions, string $primaryKey, arra
* @param string $signedUser
* @return string
*/
private function getWhereClause(string $currentOperation, bool $includeContext = true, bool $includeExtra = true,
private function getWhereClause(string $currentOperation, bool $includeContext = true, bool $includeExtra = true,
?string $signedUser = '', bool $bypassAuth = false): string
{
$tableInfo = $this->dbSettings->getDataSourceTargetArray();
Expand Down Expand Up @@ -276,7 +290,7 @@ private function getWhereClause(string $currentOperation, bool $includeContext =
/**
* @return string
*/
private function getSortClause():string
private function getSortClause(): string
{
$tableInfo = $this->dbSettings->getDataSourceTargetArray();
$sortClause = array();
Expand Down

0 comments on commit 07e9427

Please sign in to comment.