catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

FATAL OR BUG #229

Closed tallevi12 closed 9 years ago

tallevi12 commented 9 years ago

When I tried to run this query : $orders = $db->select('orders','order_id',[ 'AND' => [ "order_id" => [1,2,3], "done" => false ] ]);

The query does not return what I'm expected, I started to debug it and i figure out that it happens only when the key start with "or.." (i.e. order_id), when I changed it to another string (that doesn't starts with or..) that works.

catfan commented 9 years ago

Thanks for the report :)

This bug fixed.

4t0m1k commented 9 years ago

There is a problem with the fix https://github.com/catfan/Medoo/commit/76574afc684ea95a7e8c101aef4d1e126e73e76c

The regexp won't match single 'OR' or single 'AND' (without ' #...' after), so a query like this won't work :

if ($database->has("account", [ "AND" => [ "OR" => [ "user_name" => "foo", "email" => "foo" ], "password" => "12345" ] ]))

because of imbricated AND/OR.

Here's a better fix :

/^(AND|OR)(\s+#.*)?$/i

catfan commented 9 years ago

@4t0m1k Good point :)