This query do not return a 'selected table result' like, they output DBCC print message like bellow, and because this I cant not get values by fetch* DBI method.
DBCC SHOWCONTIG scanning 'Orders' table...
Table: 'Orders' (21575115); index ID: 1, database ID: 6
TABLE level scan performed.
- Pages Scanned................................: 20
- Extents Scanned..............................: 5
- Extent Switches..............................: 4
- Avg. Pages per Extent........................: 4.0
- Scan Density [Best Count:Actual Count].......: 60.00% [3:5]
- Logical Scan Fragmentation ..................: 0.00%
- Extent Scan Fragmentation ...................: 40.00%
- Avg. Bytes Free per Page.....................: 146.5
- Avg. Page Density (full).....................: 98.19%
DBCC execution completed. If DBCC printed error messages, contact your
+ system administrator.
Talking about Win32::OLE, I can do this with a code like bellow.
use Win32::OLE qw(in);
use Win32::OLE::Const;
my $DBConn = Win32::OLE->new('ADODB.Connection');
$DBConn->Open( "Provider=sqloledb;Data Source=127.0.0.1;Initial Cat
+alog=master;User ID=sa; Password=****;" );
if ( Win32::OLE->LastError() ) {
print "Error : " . Win32::OLE->LastError() . "\n";
exit 1;
}
my $RS = $DBConn->Execute(q{
use [Northwind]
DECLARE @id int, @indid int, @counter dec (15)
CREATE TABLE #Temp ( id int, indid int )
INSERT INTO #Temp
SELECT o.id, i.indid
FROM sysobjects AS o
FULL JOIN sysindexes AS i
ON o.id = i.id
WHERE o.xtype = 'U'
SELECT @counter = COUNT(*) FROM #Temp
SET rowcount 1
WHILE ( @counter ) > 0
BEGIN
SELECT @id = id, @indid = indid FROM #Temp
SET @counter = @counter -1
DBCC SHOWCONTIG (@id, @indid)
DELETE FROM #Temp WHERE id = @id and indid = @indid
END
SET rowcount 0
DROP TABLE #Temp} );
if ( Win32::OLE->LastError() ) {
print "Error : " . Win32::OLE->LastError() . "\n";
exit 2;
}
my @ErrosReturn;
while (1){
# Get all message returned by ADO connection
foreach my $Error ( in ( $DBConn->Errors() ) ) {
my $Description = $Error->{Description};
$Description =~ s/\s*$//;
push @ErrosReturn, $Description;
}
eval { $RS = $RS->NextRecordSet(); };
last if ( $@ );
}
print join "\n", @ErrosReturn;
I need to translate the Win32::OLE code to DBI, but I can't see a way to get theses messages.
Solli Moreira Honorio
Sao Paulo - Brazil
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|