in reply to DBI-quote doesn't like tied hashes?

I prefer to use placeholders:
my $sth = $dbh->prepare("SELECT * FROM ?"); $sth->execute($p->{test});
Quoting is taken care of automatically. Not only is there one less thing to worry about, it allows for more generic code.

Replies are listed 'Best First'.
RE: Re: DBI-quote doesn't like tied hashes?
by btrott (Parson) on May 17, 2000 at 01:03 UTC
    chromatic wrote:
    > I prefer to use placeholders: > > my $sth = $dbh->prepare("SELECT * FROM ?");
    I also prefer to use placeholders, but only when I can actually use them. :) In the databases I've used, you can't use a placeholder for the table name, because the database driver doesn't have enough information to create an execution plan if it doesn't know the table name.

    In general, though, I heartily endorse the use of placeholders. :)

      Yeah, and in those cases (ie; with table names) I do it both ways...
      $sth = $dbh->prepare(qq{ select $ouch,$this from $hurts where $another = ? }) or DoSomethingElse();
      I know this looks stupid has hell, and it has bothered me in the past too! But, I don't use it that often so I never really bothered looking for a solution. At least keeping the values within the placeholders I get DBI to quote them for me. I haven't had the need to quote a table name yet...