Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

ODBC and OLE DB

by b0dh1 (Initiate)
on May 25, 2000 at 19:31 UTC ( #14774=perlquestion: print w/ replies, xml ) Need Help??
b0dh1 has asked for the wisdom of the Perl Monks concerning the following question:

I'm a perl newbie, so this could be really easy, but I just can't get it.

I've got two scripts: one that reads the data from a text file into a recordset and writes it to an Access database using an ODBC connection, and one that reads through the same db and writes out the contents of the recordset using an OLE DB connection.

What I'm trying to do is write these as one script that reads through the db, and if a field match is not found it writes the data from the textfile to the db... but it won't work.

With OLE DB I get a "not enough storage is available to complete this operation" error when trying to write to the db, and with ODBC I can't open a recordset to iterate through, "Can't locate auto/Win32/ODBC/execute.al in @INC"

I'm running the latest build of ActivePerl on a WinNT machine. Any help would be greatly appreciated. Thanks.

Comment on ODBC and OLE DB
Re: ODBC and OLE DB
by KM (Priest) on May 25, 2000 at 20:01 UTC
    Win32::ODBC doesn't have an execute() method (which is really what that error is telling you). Instead use the Sql() method.
    I don't know what module you are using for the 'OLE DB' (Win32::OLE?). Why aren't you just using Win32::ODBC (or DBD::ODBC) for both operations? I'm confused as to why you have textfile-&qt;DB->textfile. Why not just go textfile->textfile, or textfile->textfile->DB?

    Cheers,
    KM

Re: ODBC and OLE DB
by b0dh1 (Initiate) on May 25, 2000 at 20:20 UTC

    Yes, I'm using the Win32::OLE mod. Using the Win32::ODBC mod I've been unable to open a recordset that I can iterate through. I can open a connection for executing SQL statements, but I can't open a recordset (guess I just don't know the commands for creating the recordset object)

    With the data transfer, I'm just going textfile-to-DB, but I'm looping through the recordset before each SQL INSERT statement to make sure I'm not inserting duplicate data.

      Well, as I mentioned you are trying to execute the SQL with a method that doesn't exist in Win32::ODBC. Refer to my last response (or the docs for Win32::ODBC) for the correct method. Below is a quick example of using Win32::ODBC:

      use Win32::ODBC; my $DSN = qq(DSN Name); my $db; if (!($db = new Win32::ODBC($DSN))){ print "Connection Error: " . Win32::ODBC::Error . "\n"; exit; } my $qry = qq(select * from table); if ($db->Sql($qry)){ print "SQL Error: " . $db->Error . "\n"; $db->Close; exit; } while($db->FetchRow){ my %record = $db->DataHash; print $record{FIELD}; ... etc ... } $db->Close;

      Again, read the docs that come with Win32::ODBC, and visit roth.net for more documentation.

      Cheers,
      KM

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://14774]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-09-19 22:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (151 votes), past polls