diff --git a/README.md b/README.md index fc613386a..57dabd887 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/dist-docs/change_log.txt b/dist-docs/change_log.txt index 53ac823f8..d89d87622 100644 --- a/dist-docs/change_log.txt +++ b/dist-docs/change_log.txt @@ -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. diff --git a/spec/INTER-Mediator-UnitTest/DB-PDO/DB_PDO_Test_LocalContextConditions.php b/spec/INTER-Mediator-UnitTest/DB-PDO/DB_PDO_Test_LocalContextConditions.php index 911510a0b..899ce6c58 100644 --- a/spec/INTER-Mediator-UnitTest/DB-PDO/DB_PDO_Test_LocalContextConditions.php +++ b/spec/INTER-Mediator-UnitTest/DB-PDO/DB_PDO_Test_LocalContextConditions.php @@ -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); + } } diff --git a/spec/INTER-Mediator-UnitTest/DB-PDO/MySQL/DB_PDO_MySQL_Test.php b/spec/INTER-Mediator-UnitTest/DB-PDO/MySQL/DB_PDO_MySQL_Test.php index 48bd236d7..d72439301 100644 --- a/spec/INTER-Mediator-UnitTest/DB-PDO/MySQL/DB_PDO_MySQL_Test.php +++ b/spec/INTER-Mediator-UnitTest/DB-PDO/MySQL/DB_PDO_MySQL_Test.php @@ -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%\')))'; } \ No newline at end of file diff --git a/spec/INTER-Mediator-UnitTest/DB-PDO/PostgreSQL/DB_PDO_PostgreSQL_Test.php b/spec/INTER-Mediator-UnitTest/DB-PDO/PostgreSQL/DB_PDO_PostgreSQL_Test.php index 2e65d8f16..87a0f3314 100755 --- a/spec/INTER-Mediator-UnitTest/DB-PDO/PostgreSQL/DB_PDO_PostgreSQL_Test.php +++ b/spec/INTER-Mediator-UnitTest/DB-PDO/PostgreSQL/DB_PDO_PostgreSQL_Test.php @@ -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%\')))'; + } diff --git a/spec/INTER-Mediator-UnitTest/DB-PDO/PostgreSQL/DB_Proxy_PostgreSQL_Test.php b/spec/INTER-Mediator-UnitTest/DB-PDO/PostgreSQL/DB_Proxy_PostgreSQL_Test.php index d3e8330e0..a46c4aa94 100755 --- a/spec/INTER-Mediator-UnitTest/DB-PDO/PostgreSQL/DB_Proxy_PostgreSQL_Test.php +++ b/spec/INTER-Mediator-UnitTest/DB-PDO/PostgreSQL/DB_Proxy_PostgreSQL_Test.php @@ -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.'); } - } diff --git a/spec/INTER-Mediator-UnitTest/DB-PDO/SQLite/DB_PDO_SQLite_Test.php b/spec/INTER-Mediator-UnitTest/DB-PDO/SQLite/DB_PDO_SQLite_Test.php index 5f6861098..fe8824226 100755 --- a/spec/INTER-Mediator-UnitTest/DB-PDO/SQLite/DB_PDO_SQLite_Test.php +++ b/spec/INTER-Mediator-UnitTest/DB-PDO/SQLite/DB_PDO_SQLite_Test.php @@ -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%\')))'; + } diff --git a/src/js/Adapter_DBServer.js b/src/js/Adapter_DBServer.js index e8056b960..92712f118 100644 --- a/src/js/Adapter_DBServer.js +++ b/src/js/Adapter_DBServer.js @@ -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 diff --git a/src/php/DB/Support/DB_PDO_Handler.php b/src/php/DB/Support/DB_PDO_Handler.php index 1089d1b73..d5a90d20a 100644 --- a/src/php/DB/Support/DB_PDO_Handler.php +++ b/src/php/DB/Support/DB_PDO_Handler.php @@ -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}"; + } } diff --git a/src/php/DB/Support/DB_PDO_PostgreSQL_Handler.php b/src/php/DB/Support/DB_PDO_PostgreSQL_Handler.php index bd9d4748a..8bdd5d0e6 100644 --- a/src/php/DB/Support/DB_PDO_PostgreSQL_Handler.php +++ b/src/php/DB/Support/DB_PDO_PostgreSQL_Handler.php @@ -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}"; + } } diff --git a/src/php/DB/Support/DB_PDO_SQLSupport.php b/src/php/DB/Support/DB_PDO_SQLSupport.php index e4307640b..6e2944e19 100644 --- a/src/php/DB/Support/DB_PDO_SQLSupport.php +++ b/src/php/DB/Support/DB_PDO_SQLSupport.php @@ -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']}"; } @@ -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(); @@ -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();