On Wed 24 Oct 2001 13:23, Simon Oliver <[EMAIL PROTECTED]> wrote:
> >         sub quote_identifier {
> >             shift;
> >             return join '.', map { qq{"$_"} } @_;
> >         }
> > 
> > would be enough to both quote single names and add dots for multiple names.
> 
> >             return join '.', map { qq{"$_"} } @_;
> this looks nice but if one of the identifiers is empty will get a
> warning.
> 
> This assumes that q{"} is the quotation mark and q{.} is used to join
> identifiers, which is true for most systems but might not be.  For
> example Microsoft Access permits the use of [] to quote identifiers.   
> 
> The QuotedIdentifiers(boolean) attribute is required for the situation
> where the database might have quoted identifiers switched off (as in
> JDBC and MS-SQL) and could cause a sytax error.
> 
> For DBD::ODBC we could use print $dbh->func( 29, GetInfo ) to determine
> the correct IdentifierQuoteStart character to use and set it
> automatically on connect.  I'm sure there are simillar functions for
> other DBMS's - otherwise they will use the default of q{"}.
> 
> IdentifierQuoteStart and QuotedIdentifiers could access tied scalars in
> the DBD, which could then get/set directly from the underlying database
> as appropriate.
> 
> The reason for IdentifierColumns is to allow the DBD or user the
> override the default of columns 0,1,2 (catalog,schema,table) when
> building the identifier.
> 
> I realise that there is no reason to make these functions object methods
> (as I had previously defined them.
> 
> This all could be rewitten to a single function as follows:

To minimize the number of attributes:

$dbh->{IdentifierQuote} = "'";
$dbh->{IdentifierQuote} = [ qw( [ ] ) ];

>     sub quote_identifier {
>       my $qs = $dbh->{IdentifierQuoteStart};
>       my $qe = $dbh->{IdentifierQuoteEnd} || $dbh->{IdentifierQuoteStart};

        my ($qs, $qe) = ref $dbh->{IdentifierQuote} ?
            @{$dbh->{IdentifierQuote}} : ($dbh->{IdentifierQuote}) x 2;

>       return join $dbh->{IdentifierSeparator}, map( {
>           my $id = $_ || '';
>           $dbh->{QuotedIdentifiers} ? "$qs$id$qe" : $id;
>           } @_ );     
>     }

-- 
H.Merijn Brand    Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)
using perl-5.6.1, 5.7.1 & 629 on HP-UX 10.20 & 11.00, AIX 4.2, AIX 4.3,
     WinNT 4, Win2K pro & WinCE 2.11 often with Tk800.022 &/| DBD-Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/

Reply via email to