Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
You need to import the SQL type constants from DBI and specify that SQL_LONGVARCHAR as the type of the data to be added to the memo field.

The code below extracts the news from the Google RSS feed and inserts the stories into an Access database via DBI and ODBC. The database connection is made on the fly without needing configuration. The description item is a memo field in the Access database.

#! /usr/bin/perl # use strict; use warnings; use LWP; use XML::RSSLite; use DBI ':sql_types'; use Date::Parse; use Date::Format; use HTML::Entities; use Data::Dumper; my $rssUrl = 'http://news.google.com/news?M=&M=&M=&M=&%20Toubro=&outpu +t=rss'; unless (getRss()) { $ENV{HTTP_PROXY}='myproxy:80'; getRss(); } sub getRss { my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; $ua->agent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.11) + Gecko/20050728'); my $response = $ua->get($rssUrl); my $rssContent; if ($response->is_success) { $rssContent = $response->content; # or whatever } my $mdb = "C:\\perl\\rssnewsdb\\rss.mdb"; my $DSN = "driver=Microsoft Access Driver (*.mdb);dbq=$mdb"; my $dbh = DBI->connect("dbi:ODBC:$DSN", ",") or die "$DBI::errstr\n"; if ($rssContent) { $rssContent =~ s/ isPermaLink="false"//g; my %rssHash; parseRSS(\%rssHash, \$rssContent); foreach my $item (@{$rssHash{item}}) { my $sql = "INSERT INTO tFeed ( [guid], title, link, category , + publicationdate, description) VALUES(?,?,?,?,?,?)"; my $sth = $dbh->prepare($sql); my $guid = $item->{'guid'}; my $title = $item->{'title'}; my $link = $item->{'link'}; my $description = $item->{'description'}; my $category = $item->{'category'}; my $publicationdate = time2str ('%c', str2time($item->{'pubDat +e'})); $description =~ s/<.*?>/ /g; $description =~ s/&/&/g; decode_entities $description; $description =~ s/\s+/ /g; $description =~ s/^\s+//g; print "$description\n\n"; $sth->bind_param(1, $guid); $sth->bind_param(2, $title); $sth->bind_param(3, $link); $sth->bind_param(4, $category); $sth->bind_param(5, $publicationdate); $sth->bind_param(6, $description, SQL_LONGVARCHAR); eval { $sth->execute() or die $dbh->errstr; }; if ($@) { print "Failed to add - $title\n"; } } return 1; } else { print "error!\n"; } return undef; }

In reply to Re: Accessing MS-Access memofield via DBI by inman
in thread Accessing MS-Access memofield via DBI by reneeb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (12)
    As of 2014-10-30 16:41 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (208 votes), past polls