Skip to content

Commit

Permalink
[fix] incorrect LIKE clause with double-digit indexes #1109
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelaon committed Jan 22, 2024
1 parent eb1ad19 commit 1a892c7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Medoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) . ')';
Expand Down
38 changes: 38 additions & 0 deletions tests/WhereTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<<<EOD
SELECT "title"
FROM "account"
WHERE
("title" LIKE '%one%' OR "title" LIKE '%two%' OR "title" LIKE '%three%' OR "title" LIKE '%four%' OR "title" LIKE '%five%' OR "title" LIKE '%six%' OR "title" LIKE '%seven%' OR "title" LIKE '%eight%' OR "title" LIKE '%nine%' OR "title" LIKE '%ten%' OR "title" LIKE '%eleven%' OR "title" LIKE '%twelve%')
EOD,
$this->database->queryString
);
}

/**
* @covers ::select()
* @covers ::dataImplode()
Expand Down

0 comments on commit 1a892c7

Please sign in to comment.