glushkovds / phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel
MIT License
147 stars 26 forks source link

Wrong parameter index on multiple wheres #18

Closed rick20 closed 1 year ago

rick20 commented 2 years ago

Hi,

I encountered an issue when trying to use multiple wheres. The following query

Sales::query()
  ->select([
      "lines",
      "month",
      "SUM(qty) AS amount",
  ])
  ->whereIn('product_id', [2])
  ->whereBetween('month', [$month['start'], $month['end']])
  ->toSql()

will produce:

select lines, month, SUM(qty) AS amount from "sales" where "product_id" in (:0) and "month" between :0 and :1

Each where will have parameter index begin from 0. This will cause a product id is used as a first argument for month. Is there any workaround for this particular issue? Thanks.

glushkovds commented 2 years ago

Hi! Please, check out the test: https://github.com/glushkovds/phpclickhouse-laravel/blob/b9c2d19540da7d5278294ce82da58ac50b7797c9/tests/BaseTest.php#L34-L43

I guess your Sales model isn't PhpClickHouseLaravel\BaseModel, because it didn't have a query method.

aachekalov commented 1 year ago

I guess the problem may occurs using (internally) Illuminate\Database\Query\Builder instead of PhpClickHouseLaravel\Builder

That's because in the QueryGrammar.php in case Where In :number calculates in place, but in case Basic Where does later over #@? stub.

@glushkovds Why don't you use parameterize from the parent class?