merrymonk has asked for the wisdom of the Perl Monks concerning the following question:

I am using Perl to extract data from a database using COM functions.
The documentation for the functions is aimed at VBA users.
The documentation states that one of the functions returns data
from the table as an ADORecordset.
I have searched the net and found various references to an ADORecordset and Perl
but I have not been able to successfully use information from any of these references.
Therefore I would be grateful if any Monk can let me know:
1. how the function should be called;
2. how to use the data that is returned.

Replies are listed 'Best First'.
Re: Perl & ADORecordsets
by jdtoronto (Prior) on Sep 13, 2006 at 17:30 UTC
    I am using Perl to extract data from a database using COM functions.
    Why?

    COM functions are all very good, in their place. But unless there is no alternative, there place is not in Perl code. Perl has a very extensive set of database access moethods which have been well and truly tested under fire, which handle an amazing range of databases and offer a consistent interface as you do it. Right from the lowly DBI, through to some pretty impressive ORM tools like Class::DBI, DBIx::Class and Rose::DB. As you are talking about ADO, then it is probable that you are using Microsoft Access and for that I would suggest DBD::ODBC would be a far more Perlish way of attacking the beast. Of course, you should look at the Tutorials section of the monastery to get a significant injection of wise counsel and good knowledge.

    jdtoronto

      The basic reason is that these are functions provided by
      the software supplier. Therefore they provide a
      robust and seucre way of doing what I want
      The database is from Symantics and therefore not
      Access.
Re: Perl & ADORecordsets
by Solo (Deacon) on Sep 13, 2006 at 20:52 UTC
    In general, you want to thoroughly read the Win32::OLE documentation. The Roth books also have useful info for this type of Perl on Win32 work.

    Here is code I've used in the past to get you started, YMMV with newer versions of ADO.

    use Win32 qw( in ); my $ConnStr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Se +curity Info=False;Data Source=server;Initial Catalog=database;"; my $AdoConn = new Win32::OLE("ADODB.Connection"); $AdoConn->Open($ConnStr); my $AdoRs = new Win32::OLE("ADODB.Recordset"); my $sql = "select * from table"; $AdoRs->Open($sql, $AdoConn); ROW: while (!$AdoRs->{EOF}) { my @col; for my $field ( in $AdoRs->Fields ) { push @col, $field->{Value}; } # ... } continue { $AdoRs->MoveNext(); } $AdoRs->Close();

    --Solo

    --
    You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.
      Many thanks for the information sources and the
      'starter' code.
Re: Perl & ADORecordsets
by dorko (Prior) on Sep 13, 2006 at 16:57 UTC
    Are you tied to using COM functions? If not, you might want to take a look at DBI and either DBD::ODBC or DBD::ADO.

    Cheers,

    Brent

    -- Yeah, I'm a Delt.
      Yes I have to since these are the only functions that are provided
      by the software supplier and therefore have
      some gaurantees of doing the work without any errors.