in reply to Re: Re: Re: DBI and Win32::OLE Conflict?
in thread DBI and Win32::OLE Conflict?

/me smacks herself in the head

And this is why we shouldn't re-invent the wheel :)

That doesn't seem to be the problem, because the first program is the one that's working (despite the \n). Interesting though that the \n gets lost when the XML is generated.

Good catch!

  • Comment on Re: Re: Re: Re: DBI and Win32::OLE Conflict?

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: DBI and Win32::OLE Conflict?
by poj (Abbot) on Jan 02, 2003 at 23:54 UTC
    Just another wild guess really, are you sure this is correct and the same in both cases ?
    <!DOCTYPE QBXML PUBLIC '-//INTUIT//DTD QBXML QBD 1.1//EN'>
    poj

      When the error first popped up, that was the first thing I looked at. The second thing was to make sure the XML was how QB likes it (using the XML Validator that comes with QB). The third was to actually feed QB the XML separate from the program to see if it was the program causing the problem.

      All three tests passed. That line is correct, it Validated fine, and it was fed into QB without error.

      But to address your question directly: According to this both files are completely identical. And I've been using that in all of my QB 2002 programs without a problem. And it is exactly the same as the one Inuit uses in its examples.

Re: Re: Re: Re: Re: DBI and Win32::OLE Conflict?
by poj (Abbot) on Jan 03, 2003 at 14:42 UTC
    Let's assume there is some conflict caused by having the DBI connection open. Try reading the data from the CSV into a hash, close the connection and then feed it into Qb
    poj

      Good suggestion, I just tried it. Here is the modified program:

      #!perl -Tw use strict; use DBI; use Win32::OLE; use XML::Generator; my $list_id = '40000-1022206382'; my $request_id = 1; # Be paranoid about error messages Win32::OLE->Option(Warn => 3); # Start the Processor my $connection = Win32::OLE->new('QBXMLRP.RequestProcessor'); # Name your program $connection->OpenConnection("qbtmr", "Timer Import"); # Open the currently open QuickBooks file, in "DoNotCare" mode. my $ticket = $connection->BeginSession('', 2); my $dbh = DBI->connect("DBI:CSV:") or die "Cannot connect: " . $DBI::errstr; my $sth = $dbh->prepare("SELECT Customer, Service, Duration, Date FROM + data") or die "Cannot prepare: " . $dbh->errstr(); $sth->execute() or die "Cannot execute: " . $sth->errstr(); $sth->bind_columns(\my($customer, $service, $duration, $date)); my @items; while ($sth->fetch) { push (@items, { date => $date, customer=> $customer, service => $service, duration=> $duration }); } $sth->finish(); $dbh->disconnect(); foreach my $item (@items) { my $gen = XML::Generator->new( escape => 'always', conformance => 'strict', pretty => 2, dtd => [ 'QBXML', 'PUBLIC', "'-//INTUIT//DTD", " +QBXML QBD 1.1//EN'"], version => '1.0' ); my $xml = $gen->xmldecl; $xml = $gen->QBXML( $gen->QBXMLMsgsRq( {'onError' => 'stopOnError'}, $gen->TimeTrackingAddRq({requestID => 1}, $gen->TimeTrackingAdd( $gen->TxnDate($item->{date}), $gen->EntityRef( $gen->ListID($list_id) ), $gen->CustomerRef( $gen->FullName($item->{customer}) ), $gen->ItemServiceRef( $gen->FullName($item->{service}) ), $gen->Duration($item->{duration}), ), ), ), ); my $xml_req = $gen->xml($xml); $request_id++; open (CHANGE, ">change.xml") or die "Can't open change.xml for wri +ting - $!"; print CHANGE $xml_req; close CHANGE; my $xml_res= $connection->ProcessRequest($ticket, $xml_req); } # Gracefully end everything $connection->EndSession($ticket); $connection->CloseConnection;

      Contents of change.xml. It is precisely the same as actual.xml and reinvent.xml. I've verified this using "Beyond Compare" and then again after using diotalevi's regex.:

      <?xml version="1.0" standalone="no"?> <!DOCTYPE QBXML PUBLIC '-//INTUIT//DTD QBXML QBD 1.1//EN'> <QBXML> <QBXMLMsgsRq onError="stopOnError"> <TimeTrackingAddRq requestID="1"> <TimeTrackingAdd> <TxnDate>2003-01-01</TxnDate> <EntityRef> <ListID>40000-1022206382</ListID> </EntityRef> <CustomerRef> <FullName>Cahoots Sports Bar &amp; Grill</FullName> </CustomerRef> <ItemServiceRef> <FullName>AP</FullName> </ItemServiceRef> <Duration>PT00H01M</Duration> </TimeTrackingAdd> </TimeTrackingAddRq> </QBXMLMsgsRq> </QBXML>

      Same exact error message. But your suggestion got me thinking. So I modified the program in this post by moving all the Win32 connection crap (between the request_id and the start of the dbi stuff) to right before the foreach loop ( my goal to make all the dbi stuff happen first and the QB stuff happen second) and ran it again. XML came out exact, again. And the error message still happened.

        Tough one this - Just to confirm, when you comment out the db stuff and use
        push (@items, { date => "2003-01-01", customer=> "Cahoots Sports Bar & Grill", service => "AP", duration=> "PT00H01M" });
        it all works OK ?
        poj