I am curious what is considered best practice for referencing boolean types in DBI prepare statements.

Normally I use the SQL syntax "SELECT * FROM tbl WHERE boolcol" or "SELECT * FROM tbl WHERE NOT boolcol" to query a boolean column, however this syntax does not seem "placeholder"-able. Maybe I am wrong about this fact?

So, in order to take advantage of prepare statement placeholders, I've changed my queries to "SELECT * FROM tbl WHERE boolcol=?". Is this the correct way to do this? I know that it works, but I'm curious if this is considered the *Right Way*(tm).

Example: a table has 3 boolean and one integer columns which will be queried in a loop.
CREATE TABLE tbl ( a BOOLEAN, b BOOLEAN, c BOOLEAN, d INT4, e TEXT);


mu $sth = $dbh->prepare('SELECT * FROM tbl WHERE a=?, b=?, c=?, d=?');
myloop {
  my ($a_state, $b_state, $c_state, $d_value) = ...
  $sth->execute($a_state, $b_state, $c_state, $d_value);
  ...
}

Thanks!

PS: I somewhat concerned about using the placeholder method because if my unserstanding is correct, some db servers use unquoted TRUE|FALSE, some use quoted 't'|'f', and some use 0|1. Seems like things could get messy moving from one db server to the other.

-J

--
-**-*-*---*-*---*-*---*-----*-*-----*---*-*---*-----*-----*-*-----*---
 Jon Lapham  <[EMAIL PROTECTED]>                Rio de Janeiro, Brasil
 Personal: http://www.jandr.org/
***-*--*----*-------*------------*--------------------*---------------



Reply via email to