Re: pdo_pgsql
| From: | Wez Furlong | Date: | Wed, 23 Mar 2005 03:47:50 +0000 |
| Subject: | Re: pdo_pgsql | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals php.internals |
| Request: | Send a blank email to internals+get-15552@lists.php.net to get a copy of this message | ||
The problem with using $ in the query is that you'd need to \ escape
them; remember that PHP uses $ to interpolate its own variables.
IMO, adding $ as another way to name parameters is overkill, as we
already have :named style.
--Wez.
On Wed, 23 Mar 2005 11:33:34 +0800, Christopher Kings-Lynne
<chriskl@familyhealth.com.au> wrote:
> > Depends on how you define "correctly" ;-)
> > Chances are that it will raise an error.
> >
> > I'm not sure if this should really be considered a problem; that's a
> > really obtuse SQL statement. As a non-pgsqler, I have a hard time
> > figuring out where the variables are.
>
> Well, anything that's not perfect is a problem :)
>
> Dollar quoting is new in pgsql 8, it's sort of like 'heredocs'.
> Basically it's to avoid having to escape ' in your function bodies, or
> other strings, eg:
>
> CREATE FUNCTION test(int) RETURNS int AS
> $tagname$
> SELECT 23 FROM table WHERE a > $1 AND b = 'hello'
> $tagname$ LANGUAGE SQL;
>
> The 'tagname' is the dollar quote identifier, and everything from that
> dollar quote opener to the end one will be considered a string literal.
> Notice I do not have to escape the '' in the function body.
>
> It a perfectly reasonable thing, even encouraged thing to do. We'll
> just have to upgrade the SQL parser to cope :P
>
> Prepared query parameters are indicated with $n syntax in PostgreSQL,
> just to make things tricky :D
>
> ie:
>
> SELECT * FROM blah WHERE a = $1 AND b = $2;
>
> The $1 will get replaced with first param, $2 with second, etc.
>
> Maybe support should be added for this style of notation? It'd be
> pretty easy I guess.
>
> > I welcome native postgres prepare/bind/execute support, and don't mind
> > adjusting the pdo_sql_parser.re code to cater for rewriting ? or
> > :named style substitutions into postgres style; it already includes
> > some logic for rewriting ? to :named and vice-versa, so the
> > modifications should be reasonably simple.
>
> Might be necessary.
>
> Chris
>