2010年6月28日星期一

Re: [fw-db] raw SQL to Zend_Db_Select ?

SQL is a context-free grammar.  To transform SQL statements into another representation you would need a non-deterministic parser of some kind.  Think of yacc or bison for C, or ANTLR for Java.

Lime (http://sourceforge.net/projects/lime-php/) is a parser generator written in PHP, and which generates parser code that is also PHP code.  But Lime appears to be abandonware, not having been updated since May 2008.  The docs are pretty much non-existent.

By the way, I would think if you have a fully-formed SELECT query, there's little reason to convert it to a Zend_Db_Select object.  I suppose this gives you the ability to add more joins or conditions or whatever, but that seems like a pretty rare use.

There are no practical limits on how complicated an expression you can represent in a Zend_Db_Expr object.  

Regards,
Bill Karwin

On Jun 28, 2010, at 9:21 AM, David Mintz wrote:

Before I even start trying, I am wondering how difficult it is to re-fashion an elaborate SELECT query (MySQL) into a Zend_Db_Select object. There are things like IF() containing nested CASE statements. Are there  limits, for example, on how complicated a Zend_Db_Expr() can get?

I guess the other option is to create a view. The point is to have all the basic heavy lifting cleanly encapsulated and add more WHERE clauses programmatically.



--
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/



没有评论: