diff --git a/src/Medoo.php b/src/Medoo.php index b8cb0302..c44447cf 100644 --- a/src/Medoo.php +++ b/src/Medoo.php @@ -894,15 +894,20 @@ protected function dataImplode(array $data, array &$map, string $conjunctor): st break; case 'array': - $placeholders = []; + $values = []; foreach ($value as $index => $item) { - $stackKey = $mapKey . $index . '_i'; - $placeholders[] = $stackKey; - $map[$stackKey] = $this->typeMap($item, gettype($item)); + if ($raw = $this->buildRaw($item, $map)) { + $values[] = $raw; + } else { + $stackKey = $mapKey . $index . '_i'; + + $values[] = $stackKey; + $map[$stackKey] = $this->typeMap($item, gettype($item)); + } } - $stack[] = $column . ' NOT IN (' . implode(', ', $placeholders) . ')'; + $stack[] = $column . ' NOT IN (' . implode(', ', $values) . ')'; break; case 'object': @@ -981,16 +986,20 @@ protected function dataImplode(array $data, array &$map, string $conjunctor): st break; case 'array': - $placeholders = []; + $values = []; foreach ($value as $index => $item) { - $stackKey = $mapKey . $index . '_i'; + if ($raw = $this->buildRaw($item, $map)) { + $values[] = $raw; + } else { + $stackKey = $mapKey . $index . '_i'; - $placeholders[] = $stackKey; - $map[$stackKey] = $this->typeMap($item, gettype($item)); + $values[] = $stackKey; + $map[$stackKey] = $this->typeMap($item, gettype($item)); + } } - $stack[] = $column . ' IN (' . implode(', ', $placeholders) . ')'; + $stack[] = $column . ' IN (' . implode(', ', $values) . ')'; break; case 'object': diff --git a/tests/WhereTest.php b/tests/WhereTest.php index 32610bc5..35b2ff64 100644 --- a/tests/WhereTest.php +++ b/tests/WhereTest.php @@ -232,6 +232,62 @@ public function testArrayStringValuesWhere($type) ); } + /** + * @covers ::select() + * @covers ::dataImplode() + * @covers ::whereClause() + * @dataProvider typesProvider + */ + public function testRawArrayValuesWhere($type) + { + $this->setType($type); + + $this->database->select("account", "user_name", [ + 'id' => [ + Medoo::raw('LOWER("FOO")'), + Medoo::raw('LOWER("BAR")') + ] + ]); + + $this->assertQuery( + <<database->queryString + ); + } + + /** + * @covers ::select() + * @covers ::dataImplode() + * @covers ::whereClause() + * @dataProvider typesProvider + */ + public function testRawNotInArrayValuesWhere($type) + { + $this->setType($type); + + $this->database->select("account", "user_name", [ + 'id[!]' => [ + Medoo::raw('LOWER("FOO")'), + Medoo::raw('LOWER("BAR")') + ] + ]); + + $this->assertQuery( + <<database->queryString + ); + } + /** * @covers ::select() * @covers ::dataImplode()