From 1a892c78c3758b350c6c1b7f581a65b4c2bafb68 Mon Sep 17 00:00:00 2001 From: Angel Date: Mon, 22 Jan 2024 09:16:30 +0800 Subject: [PATCH] [fix] incorrect LIKE clause with double-digit indexes #1109 --- src/Medoo.php | 4 ++-- tests/WhereTest.php | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/Medoo.php b/src/Medoo.php index 6ebff1f3..c3ee6813 100644 --- a/src/Medoo.php +++ b/src/Medoo.php @@ -943,8 +943,8 @@ protected function dataImplode(array $data, array &$map, string $conjunctor): st $item = '%' . $item . '%'; } - $likeClauses[] = $column . ($operator === '!~' ? ' NOT' : '') . " LIKE {$mapKey}L{$index}"; - $map["{$mapKey}L{$index}"] = [$item, PDO::PARAM_STR]; + $likeClauses[] = $column . ($operator === '!~' ? ' NOT' : '') . " LIKE {$mapKey}L{$index}$"; + $map["{$mapKey}L{$index}$"] = [$item, PDO::PARAM_STR]; } $stack[] = '(' . implode($connector, $likeClauses) . ')'; diff --git a/tests/WhereTest.php b/tests/WhereTest.php index 051d0465..32610bc5 100644 --- a/tests/WhereTest.php +++ b/tests/WhereTest.php @@ -642,6 +642,44 @@ public function testWildcardLikeWhere($type) ); } + /** + * @covers ::select() + * @covers ::dataImplode() + * @covers ::whereClause() + * @dataProvider typesProvider + */ + public function testMultipleLikeWhere($type) + { + $this->setType($type); + + $words = [ + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine", + "ten", + "eleven", + "twelve" + ]; + + $this->database->select("account", ["title"], ["title[~]" => $words]); + + $this->assertQuery( + <<database->queryString + ); + } + /** * @covers ::select() * @covers ::dataImplode()