As Philip also says, this is done sometimes by SQL generators to make it
easier on the person who developed the code for the SQL generator. It
makes it easier because then they don't have to write code for the case
of adding the first term to a WHERE clause. That is, if the SQL
statement is assumed to contain the syntax "WHERE 1 = 1" by default,
then any real conditions you specify can simply be appended to the WHERE
clause with an AND operation.
It shouldn't be a problem to have the extra 1=1 term, even though it
seems inelegant and messy. SQL optimizers should be smart enough to
factor out any operand of an AND expression that evaluates to TRUE for
every row. "WHERE TRUE AND <expr>" is equivalent to "WHERE <expr>".
Similarly, a SQL optimizer should be able to factor out any operand of
an OR expression that evaluates to FALSE for every row. "WHERE FALSE OR
<expr>" is equivalent to "WHERE <expr>".
FWIW, Zend_Db_Select does not need to add the artificial 1=1 term! :-)
If you specify no conditions in the WHERE clause, Zend_Db_Select simply
omits that clause.
Regards,
Bill Karwin
________________________________
From: Adam Balgach [mailto:[EMAIL PROTECTED]
Sent: Tuesday, May 01, 2007 1:59 PM
To: Zend Mailing List
Subject: [fw-general] quick question...
has the group ever heard of using 1=1 in the where clause of a
SQL statement? Some other auto generating sql apps put this in, and I
had just never seen it before. I don't think its a. good coding or b.
good convention. But I wanted to check before I made a feature request.
Thanks,
A.