Re: can $dbh-do take a prepared statement handle?

2011-06-17 Thread Martin J. Evans

On 16/06/11 17:34, Jeff Macdonald wrote:

On Fri, Jun 3, 2011 at 3:36 PM, David Nicoldavidni...@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


Re: can $dbh-do take a prepared statement handle?

2011-06-17 Thread David Nicol

 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.


Furthermore, my super_do would not work with an object that
stringifies into SQL code. Better might be

eval {$unknown-execute();1) or $dbh-do($unknown)

which would need to be adjusted to capture the returned values, if
needed, and would not work with an object other than a $sth that has
an execute method.


Re: can $dbh-do take a prepared statement handle?

2011-06-17 Thread Jeff Macdonald
Thanks everyone for the clarification.

On Fri, Jun 17, 2011 at 7:05 AM, David Nicol davidni...@gmail.com wrote:

 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.


 Furthermore, my super_do would not work with an object that
 stringifies into SQL code. Better might be

    eval {$unknown-execute();1) or $dbh-do($unknown)

 which would need to be adjusted to capture the returned values, if
 needed, and would not work with an object other than a $sth that has
 an execute method.




-- 
Jeff Macdonald
Ayer, MA


Re: can $dbh-do take a prepared statement handle?

2011-06-16 Thread Jeff Macdonald
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.


-- 
Jeff Macdonald
Ayer, MA


Re: can $dbh-do take a prepared statement handle?

2011-06-03 Thread Jonathan Leffler
On Fri, Jun 3, 2011 at 12:06, Jeff Macdonald macfisher...@gmail.com wrote:

 can $dbh-do take a prepared statement handle?


No.  See 'perldoc DBI'.

-- 
Jonathan Leffler jonathan.leff...@gmail.com  #include disclaimer.h
Guardian of DBD::Informix - v2008.0513 - http://dbi.perl.org
Blessed are we who can laugh at ourselves, for we shall never cease to be
amused.


Re: can $dbh-do take a prepared statement handle?

2011-06-03 Thread David Nicol
=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]);
   }
};