database icon indicating copy to clipboard operation
database copied to clipboard

better support for BETWEEN clause

Open 8ctopus opened this issue 2 years ago • 0 comments

Currently BETWEEN is supported using database::literal, such as in this query:

$sql = <<<SQL
    SELECT
        *
    FROM
        test
    WHERE
SQL;

$rows = $database->query($sql, [
    $database::literal('id BETWEEN ? AND ?', 1, 2),
]);

It would be even nicer if it worked like this:

$sql = <<<SQL
    SELECT
        *
    FROM
        test
    WHERE
SQL;

$rows = $database->query($sql, [
    'id BETWEEN' => [1, 2],
]);

Now when it sees that the value is an array ([1, 2]), it automatically switches to IN.

https://github.com/nette/database/blob/master/src/Database/SqlPreprocessor.php#L285-L293)

8ctopus avatar Apr 03 '23 06:04 8ctopus