Solved

Newsletter supplementary material

Posted on 2004-10-04
3
483 Views
Last Modified: 2011-09-20
-The Perl code explination
 -The code
0
Comment
Question by:turn123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 11

Author Comment

by:turn123
ID: 14256360
Not much to explain this time.  Create a new text document in the same directory as the separate .pl file give in http://www.experts-exchange.com/Q_21188390.html#14117768 -> name it something.pl -> copy and paste the code into it.
0
 
LVL 11

Author Comment

by:turn123
ID: 14256363
use strict;
use DBI;
use XML::Simple;

my $filename = "shipping_stuff.mdb";
my $dsn = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=$filename";
my $dbh = DBI->connect("dbi:ODBC:$dsn", "", "")
     or die "Can't open source DB: $!\n";

my $data = XMLin("output.xml",KeyAttr => ["DataExtName"], ForceArray => [ "DataExtRet","InvoiceLineRet","InvoiceRet" ]);
my $control = 0;
while ($data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{RefNumber} =~ /(.+)/) {
      my $sqlstatement = "INSERT into inv VALUES ('";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{RefNumber}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{TimeCreated}','";
      if ($data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr3} =~ /.+/) {
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr1}','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr2}','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr3}','";
      } elsif ($data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr2} =~ /.+/) {
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr1}','";
            $sqlstatement .= "','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr2}','";
      } else {
            $sqlstatement .= "','";
            $sqlstatement .= "','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr1}','";
      }
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr4}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{City}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{State}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{PostalCode}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Country}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{PONumber}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{TermsRef}->{FullName}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipMethodRef}->{FullName}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{SalesRepRef}->{FullName}','";
      if ($data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr3} =~ /.+/) {
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Addr1}','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Addr2}','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Addr3}','";
      } elsif ($data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr2} =~ /.+/) {
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Addr1}','";
            $sqlstatement .= "','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Addr2}','";
      } else {
            $sqlstatement .= "','";
            $sqlstatement .= "','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Addr1}','";
      }
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Addr4}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{City}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{State}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{PostalCode}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Country}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{EditSequence}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{TxnID}')";
      open SQL, ">> sql.txt";
      print SQL $sqlstatement . "\n";
      close SQL;
      my $statementhandle = $dbh->prepare("DELETE from inv where ID = '$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{RefNumber}'");
      $statementhandle->execute();
      my $statementhandle = $dbh->prepare($sqlstatement) || die "Cannot prepare statement";
      $statementhandle->execute() || die "Could not execute SQL statement, maybe invalid?";
      ++$control;
}
0
 
LVL 11

Accepted Solution

by:
turn123 earned 0 total points
ID: 14333423
Question moved to Productivity Applications and closed.

turn123,
Page Editor -- Productivity Applications
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Online collaboration is quickly becoming embedded in the workplace, and its benefits are tangible. See what the current landscape looks like and what the future holds for collaboration tools and the future of work.
The advancement in technology has been a great source of betterment and empowerment for the human race, Nevertheless, this is not to say that technology doesn’t have any problems. We are bombarded with constant distractions, whether as an overload o…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question