On Wed, Jan 09, 2002 at 09:54:07PM -0500, Rudy Lippan wrote:
>
> 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?
No need to complain. quote_identifier would just return the unquoted word(s).
And quote_identifier is also responsible for joining words with
dots (catalog.schema.table, or perhaps table.fieldname).
I don't expect quote_identifier to ever have cause to warn or croak
about anything. It should just do what's most reasonable.
> 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?
Note the 'i' in /.../i.
> 2) quote_identifier(["this ", "is a ",test],1) would return q{this ."is a
>".test}
I think you haven't tried it :)
> 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.
Ah, now, that's a more tricky issue :)
One way round it would be to change the 'next if' condition to be
next if $opt && /^[a-z_]\w*$/i && !(ref $opt && $opt->{uc($_)});
So $opt could be a ref to a hash of words that need quoting.
Applications could pass in a hash if they want. Or pass in a plain
1 and the driver could call $dbh->SUPER::quote_identifier with a
hash of reserved words for that database.
But remember that $opt is a fudge itself. It doesn't have to be
perfect, just useful. It expect most apps not to use it and just
let quote_identifier quote everything.
Tim.