Hi all,

Attached/included is my hackish attempt to add support for the
adExecuteStream option to ADO.pm. I needed this for retrieving data
from several stored procedures that return XML and it works for my
purposes but I'm not sure if I've integrated it well into ADO.pm
(especially in the execute() subroutine.)

Enjoy and comments welcome, thanks.
Luke

Apologies if Gmail screws up formatting....

--- ADO.pm.orig Fri Mar 17 15:27:10 2006
+++ ADO.pm      Fri Mar 17 15:25:01 2006
@@ -327,19 +327,20 @@

                my ( $outer, $sth ) = DBI::_new_sth( $dbh, { Statement => 
$statement } );

-               $sth->{ado_cachesize}  = $dbh->{ado_cachesize};
-               $sth->{ado_comm}       = $comm;
-               $sth->{ado_conn}       = $conn;
-               $sth->{ado_cursortype} = $dbh->{ado_cursortype} || 
$attr->{CursorType};
-               $sth->{ado_fields}     = undef;
-               $sth->{ado_max_errors} = $dbh->{ado_max_errors};
-               $sth->{ado_refresh}    = 1;
-               $sth->{ado_rownum}     = -1;
-               $sth->{ado_rows}       = -1;
-               $sth->{ado_rowset}     = undef;
-               $sth->{ado_type}       = undef;
-               $sth->{ado_usecmd}     = undef;
-               $sth->{ado_users}      = undef;
+               $sth->{ado_cachesize}     = $dbh->{ado_cachesize};
+               $sth->{ado_comm}          = $comm;
+               $sth->{ado_conn}          = $conn;
+               $sth->{ado_cursortype}    = $dbh->{ado_cursortype} || 
$attr->{CursorType};
+               $sth->{ado_fields}        = undef;
+               $sth->{ado_max_errors}    = $dbh->{ado_max_errors};
+               $sth->{ado_refresh}       = 1;
+               $sth->{ado_rownum}        = -1;
+               $sth->{ado_rows}          = -1;
+               $sth->{ado_rowset}        = undef;
+               $sth->{ado_type}          = undef;
+               $sth->{ado_usecmd}        = undef;
+               $sth->{ado_users}         = undef;
+               $sth->{ado_executeoption} = 0;

                # Set overrides for and attributes.
                for my $key ( grep { /^ado_/ } keys %$attr ) {
@@ -375,6 +376,17 @@
     if ( $sth->{ado_refresh} == 2 ) {
       $Cnt = DBD::ADO::st::_refresh( $sth );
     }
+       # LRB
+       if ( $sth->{ado_executeoption} ==
$Enums->{ExecuteOptionEnum}{adExecuteStream}) {
+               my $sResponseStream = Win32::OLE->new('ADODB.Stream');
+               return if DBD::ADO::Failed($dbh, "Can't create 'ADODB.Stream'");
+               $sResponseStream->Open();
+               return if DBD::ADO::Failed($dbh, "Can't open 'ADODB.Stream'");
+               my $vObj = 
Win32::OLE::Variant->new(Win32::OLE::Variant::VT_VARIANT()|Win32::OLE::Variant::VT_BYREF(),
$sResponseStream);
+               return if DBD::ADO::Failed($dbh, "Can't create Variant for 
'ADODB.Stream'");
+               $comm->{Properties}{'Output Stream'}{Value} = $vObj;
+               $sth->{ado_responsestream} = $sResponseStream;
+       }
     if ( $Cnt ) {
       # Describe the Parameters:
       for my $p ( Win32::OLE::in( $comm->Parameters ) ) {
@@ -1052,7 +1064,16 @@
                        || defined $sth->{ado_users}
                        );

-               if ( $UseRecordSet ) {
+               my $UseResponseStream = defined $sth->{ado_executeoption} &&
+                       ( $sth->{ado_executeoption} ==
$Enums->{ExecuteOptionEnum}{adExecuteStream} );
+
+               if ( $UseResponseStream ) {
+                       $sth->trace_msg("    -- Execute: Using Response 
Stream\n", 5 );
+                       $comm->Execute( { 'Options' => 
$sth->{ado_executeoption} } );
+                       return if DBD::ADO::Failed( $sth,"Can't Execute Command 
'$sql'");
+                       return $sth->{ado_responsestream}->ReadText();
+               }
+               elsif ( $UseRecordSet ) {
                        $rs = Win32::OLE->new('ADODB.RecordSet');
                        return if DBD::ADO::Failed( $sth,"Can't create 
'ADODB.RecordSet'");
--- ADO.pm.orig Fri Mar 17 15:27:10 2006
+++ ADO.pm      Fri Mar 17 15:25:01 2006
@@ -327,19 +327,20 @@
 
                my ( $outer, $sth ) = DBI::_new_sth( $dbh, { Statement => 
$statement } );
 
-               $sth->{ado_cachesize}  = $dbh->{ado_cachesize};
-               $sth->{ado_comm}       = $comm;
-               $sth->{ado_conn}       = $conn;
-               $sth->{ado_cursortype} = $dbh->{ado_cursortype} || 
$attr->{CursorType};
-               $sth->{ado_fields}     = undef;
-               $sth->{ado_max_errors} = $dbh->{ado_max_errors};
-               $sth->{ado_refresh}    = 1;
-               $sth->{ado_rownum}     = -1;
-               $sth->{ado_rows}       = -1;
-               $sth->{ado_rowset}     = undef;
-               $sth->{ado_type}       = undef;
-               $sth->{ado_usecmd}     = undef;
-               $sth->{ado_users}      = undef;
+               $sth->{ado_cachesize}     = $dbh->{ado_cachesize};
+               $sth->{ado_comm}          = $comm;
+               $sth->{ado_conn}          = $conn;
+               $sth->{ado_cursortype}    = $dbh->{ado_cursortype} || 
$attr->{CursorType};
+               $sth->{ado_fields}        = undef;
+               $sth->{ado_max_errors}    = $dbh->{ado_max_errors};
+               $sth->{ado_refresh}       = 1;
+               $sth->{ado_rownum}        = -1;
+               $sth->{ado_rows}          = -1;
+               $sth->{ado_rowset}        = undef;
+               $sth->{ado_type}          = undef;
+               $sth->{ado_usecmd}        = undef;
+               $sth->{ado_users}         = undef;
+               $sth->{ado_executeoption} = 0;
 
                # Set overrides for and attributes.
                for my $key ( grep { /^ado_/ } keys %$attr ) {
@@ -375,6 +376,17 @@
     if ( $sth->{ado_refresh} == 2 ) {
       $Cnt = DBD::ADO::st::_refresh( $sth );
     }
+       # LRB
+       if ( $sth->{ado_executeoption} == 
$Enums->{ExecuteOptionEnum}{adExecuteStream}) {
+               my $sResponseStream = Win32::OLE->new('ADODB.Stream');
+               return if DBD::ADO::Failed($dbh, "Can't create 'ADODB.Stream'");
+               $sResponseStream->Open();
+               return if DBD::ADO::Failed($dbh, "Can't open 'ADODB.Stream'");
+               my $vObj = 
Win32::OLE::Variant->new(Win32::OLE::Variant::VT_VARIANT()|Win32::OLE::Variant::VT_BYREF(),
 $sResponseStream);
+               return if DBD::ADO::Failed($dbh, "Can't create Variant for 
'ADODB.Stream'");
+               $comm->{Properties}{'Output Stream'}{Value} = $vObj;
+               $sth->{ado_responsestream} = $sResponseStream;
+       }
     if ( $Cnt ) {
       # Describe the Parameters:
       for my $p ( Win32::OLE::in( $comm->Parameters ) ) {
@@ -1052,7 +1064,16 @@
                        || defined $sth->{ado_users}
                        );
 
-               if ( $UseRecordSet ) {
+               my $UseResponseStream = defined $sth->{ado_executeoption} &&
+                       ( $sth->{ado_executeoption} == 
$Enums->{ExecuteOptionEnum}{adExecuteStream} );
+
+               if ( $UseResponseStream ) {
+                       $sth->trace_msg("    -- Execute: Using Response 
Stream\n", 5 );
+                       $comm->Execute( { 'Options' => 
$sth->{ado_executeoption} } );
+                       return if DBD::ADO::Failed( $sth,"Can't Execute Command 
'$sql'");
+                       return $sth->{ado_responsestream}->ReadText();
+               }
+               elsif ( $UseRecordSet ) {
                        $rs = Win32::OLE->new('ADODB.RecordSet');
                        return if DBD::ADO::Failed( $sth,"Can't create 
'ADODB.RecordSet'");
 

Reply via email to