On 16/06/11 17:34, Jeff Macdonald wrote:
On Fri, Jun 3, 2011 at 3:36 PM, David Nicol<davidni...@gmail.com>  wrote:


=pod

if you've got enough control over the flow of control to have the code below
work safely, you probably don't need it

=cut

sub Super_do($){
    if (ref $_[0]){
         $_[0]->execute();
    }else{
         $dbh->do($_[0]);
    }
};


so it looks like yes! I got sidetracked after I asked that message.
I'm guessing this is in the DBI code? Thanks for the pointer.



I don't think the answer is yes at all and I don't think David was saying yes. 
I don't think you can pass a prepared statement handle to the do method, it 
needs to be some SQL text. The above example from David does not pass a 
statement handle to do. It checks if $_[0] is a ref (which it will be if it is 
a statement handle) but if it is not (i.e., it is sql text) it calls do.

You can see for yourself with:

perl -le 'use DBI; my $h = DBI->connect("dbi:ODBC:xx","xx","xx"); my $s = 
$h->prepare(q/create table mje (a integer)/); $h->do($s);'

which errors with:

DBD::ODBC::db do failed: [unixODBC][Easysoft][SQL Server Driver][SQL 
Server]Incorrect syntax near '::'. (SQL-42000) at -e line 1.

because the $s statement handle was stringified into something like 
"DBI::st=HASH(0x8e7e2c0)"

Martin
--
Martin J. Evans
Easysoft Limited
http://www.easysoft.com

Reply via email to