Click to See Complete Forum and Search --> : Perl Database trouble


Kram
05-19-2004, 12:25 AM
I have the following code which connects to a database (tested and works)...

But it does not seem to INSERT data the way i want it to. I think the INSERT statement is correct but when I open up the database, the records not there.


use strict;
use PDF;
use Win32::OLE;

#connect to database
my $conn = Win32::OLE->new("ADODB.Connection");
$conn->open("DSN=Properties");

#pdf to look at
my $pdf = PDF->new()
|| die "Can\'t create PDF parser";
$pdf->TargetFile("e:\\mark\\web\\dev\\database\\document 1.pdf");

#extract properties from pdf
my $title = $pdf->GetInfo('Title');
my $author = $pdf->GetInfo('Author');
my $keywords = $pdf->GetInfo('Keywords');

#insert values into database
$conn->Execute("INSERT INTO Properties(Title) values (?)",undef,($title));

$conn->Close();

silent11
05-19-2004, 06:58 AM
$conn->Execute("INSERT INTO Properties(Title) values (?)",undef,($title));



Shouldn't you put some kind of test at the end of this to see it it's actually working?

I've never used Win32::OLE for Databse access, I've only used DBI. Notice below how dbi gives you an errstr() method to test weather or not the execute commnad was successful...



$UPDATE_sth->execute($theme,$name,$branch,$craft,$other,$notes,$status,$id) || die $UPDATE_sth->errstr();



Perhaps there is some similar functionality in Win32::OLE. Even if there isn't , I'd add a || die $!; at the end of the statement to see if $conn->Execute() is returning 0.

Good luck