Tim,

On Thu, 10 Jan 2002, Tim Bunce wrote:

> > 
> > Seems non-trivial to me...
> 
> No. The SQL should have been constructed by the application calling
> quote_identifier() on any identifiers it contains.
> 
> The issue is how your DBD's quote_identifier implementation knows
> whether it should quote or not.
> 

Sure make the DBD implementers do all the work ;-)

> And, as I said in my previous email:
> > (A middle-road approach might be to have an option to quote_identifier
> > that says only quote the identifier if it needs it. If a database
> > don't support quoting identifiers then either quoting or not-quoting
> > an identifier that needs it will generate an error anyway.)
> 
> I've now implemented that.
> 

If a database do not support quoting, wouldn't be up to the DBD driver to
complain loudly when someone tries to quote something, and otherwise just
be a no-op?


Is this the implementation you are refering to?

> sub quote_identifier {
>        my $dbh = shift;
>        my $id  = shift;
>        my $opt = shift;                # optional, quote only if needed
>        # ignore null elements (ie catalog, schema)
>        my @id  = (ref $id) ? grep { defined } @$id : ($id);
>        s/"/""/g foreach @id;           # escape embedded quotes
>        foreach (@id) {                 # quote the elements
>            next if $opt && /^[a-z_]\w*$/i;
>            $_ = qq{"$_"};
>        }
>        return join '.', @id;           # ... and join the dots
>    }

If so; I have a few questions:

1) Why do you have the character class as a-z and not A-Z?  I am under the
impression that regular identifiers are case folded to upper case, so if I
were to call quote_identifier on q{this}, I would probably want q{"this"}
because quoting is now required to preserve case, but q{THIS} would end up
being q{THIS} because it is the same as q{"THIS"}, so there is no need to
quote it.

2) quote_identifier(["this    ", "is a ",test],1) would return
q{this    ."is a ".test} So are you saying that the white space at the end
of the first identifier is not significant but the whitespace at the end
of the second is?

3) What about reserved sql words they also need to be quoted?  If you are
not going to look at reserved words, why bother making the distinction
between 'needs quotes' and 'no quotes' since  
quote_identifier("\Uselect",1) will always be broken unless the DBD
override the function.


Rudy

Reply via email to