It would be far less work to just start with a Zend_Db_Select object.

The tokenizer is the easy part.  The parser is harder.

There are no parser generator tools for PHP, AFAIK. There's Lime, but it's abandonware and virtually undocumented.

So you would have to write PHP code for an LR parser for the SQL grammar. This would take many weeks, assuming you know how to write parsers from scratch (without the aid of a parser generator like yacc, bison, or ANTLR). Have you taken a class in Compiler Design?

Regards,
Bill Karwin

On Aug 12, 2010, at 9:28 AM, Andrei Iarus wrote:

I need it for Zend_Db_Paginator.
But is it possible to create such a tokeinzer that works for all standard SQL [everything that is not standard will fail].
Thanks, Ralph.


--- On Thu, 8/12/10, Ralph Schindler <[email protected]> wrote:

From: Ralph Schindler <[email protected]>
Subject: Re: [fw-general] String to Zend_Db_Select Object
To: "Andrei Iarus" <[email protected]>
Cc: "Zend Framework" <[email protected]>
Date: Thursday, August 12, 2010, 6:47 PM

This is not possible. For that to happen, you'd need an SQL parser/ tokenizer, which there is not one in ZF. Moreover, the SQL you have is probably somewhat specific to a particular vendor implementation of SQL which, again, would make it really hard to build a parser/ tokenizer that knows about these variances in SQL.

There are only a few major parts that need to be really looked at, and for most cases, you can use Zend_Db_Expr to fill in parts where you do not want to parameterize them. (For example $select- >where(new Zend_Db_Expr('a = 500 AND b LIKE "FOO"));)

Why do you want to do this anyway? Do you need to be able to mutate your current query? If that is the case, then creating your query as a Zend_Db_Select might be worth it in the long run.

-ralph

Andrei Iarus wrote:
> Hello to all,
> Any ideas on how to cast/transform a string to an object of type Zend_Db_Select? Ideally, without rewriting it by hand.
>  Thank you very much
>
>


Reply via email to