On 2016/04/09 5:20 PM, Richard Williams wrote: > I have a PHP program where I have the equivalent of the following code. The > code was not deleting the expected rows ('abc' & 'def') because of the bad > syntax. However the error did not throw an exception. Is this what I should > expect? > > $p = new PDO('sqlite::memory:'); > $p->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); > $p->exec("create table a (a text)"); > $sql = "delete from a where a in (a in ('abc','def'))"; > $stat = $p->exec($sql);
Yes, you should expect it. The expression "a in ('abc','def')" returns a boolean value, true or false based on what is in "a" at the current record (which is what you need for the filtering). So the larger expression "a in (a in ('abc','def'))" checks whether "a" falls inside a set of values that contain a single boolean value (as returned by the above expression) - whether that boolean value ends up being TRUE or FALSE does not matter, since the "a" won't likely be a boolean in itself, but there is absolutely nothing wrong with the expression's validity and so no reason to error out or throw an exception or even simply complain about the grammar. It simply might not find any matches and so not delete any rows.